vibe coding an orbital mechanics simulation to try out claude code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

34 lines
1.1 KiB

#include <catch2/catch_test_macros.hpp>
#include "../src/physics.h"
#include "../src/simulation.h"
#include "../src/config_loader.h"
#include "../src/test_utilities.h"
#include <cmath>
TEST_CASE("Energy conservation - Earth circular orbit", "[energy][rk4]") {
const double TIME_STEP = 60.0;
const double DAYS_TO_SIMULATE = 10.0;
const double SECONDS_PER_DAY = 86400.0;
SimulationState* sim = create_simulation(10, 0, 0, TIME_STEP);
REQUIRE(load_system_config(sim, "tests/test_energy.toml"));
double initial_energy = calculate_system_total_energy(sim);
double total_time = DAYS_TO_SIMULATE * SECONDS_PER_DAY;
while (sim->time < total_time) {
update_simulation(sim);
}
double final_energy = calculate_system_total_energy(sim);
double energy_drift_percent = fabs((final_energy - initial_energy) / initial_energy) * 100.0;
INFO("Initial energy: " << initial_energy << " J");
INFO("Final energy: " << final_energy << " J");
INFO("Energy drift: " << energy_drift_percent << "%");
REQUIRE(energy_drift_percent < 5.0);
destroy_simulation(sim);
}