Browse Source

Use config_loader in all tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
main
cinnaboot 6 months ago
parent
commit
203e88cc05
  1. 11
      tests/configs/earth_circular.txt
  2. 11
      tests/configs/mars_circular.txt
  3. 9
      tests/test_energy.cpp
  4. 17
      tests/test_orbital_period.cpp

11
tests/configs/earth_circular.txt

@ -0,0 +1,11 @@
# Test Configuration: Sun + Earth (circular orbit)
# Earth at 1 AU with circular orbit
# Expected orbital period: ~365 days
#
# Format: name mass(kg) radius(m) x(m) y(m) z(m) parent_index r g b eccentricity semi_major_axis(m)
# Sun at origin (index 0)
Sun 1.989e30 6.96e8 0 0 0 -1 1.0 1.0 0.0 0 0
# Earth at 1 AU - circular orbit (index 1, parent Sun)
Earth 5.972e24 6.371e6 1.496e11 0 0 0 0.0 0.5 1.0 0 1.496e11

11
tests/configs/mars_circular.txt

@ -0,0 +1,11 @@
# Test Configuration: Sun + Mars (circular orbit)
# Mars at 1.5 AU with circular orbit
# Expected orbital period: ~687 days
#
# Format: name mass(kg) radius(m) x(m) y(m) z(m) parent_index r g b eccentricity semi_major_axis(m)
# Sun at origin (index 0)
Sun 1.989e30 6.96e8 0 0 0 -1 1.0 1.0 0.0 0 0
# Mars at 1.5 AU - circular orbit (index 1, parent Sun)
Mars 6.39e23 3.3895e6 2.244e11 0 0 0 0.8 0.3 0.1 0 2.244e11

9
tests/test_energy.cpp

@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "../src/physics.h" #include "../src/physics.h"
#include "../src/bodies.h" #include "../src/bodies.h"
#include "../src/config_loader.h"
#include "../src/test_utilities.h" #include "../src/test_utilities.h"
#include <cmath> #include <cmath>
@ -11,13 +12,7 @@ TEST_CASE("Energy conservation - Earth circular orbit", "[energy][rk4]") {
SimulationState* sim = create_simulation(10, TIME_STEP); SimulationState* sim = create_simulation(10, TIME_STEP);
Vec3 sun_pos = {0, 0, 0}; REQUIRE(load_system_config(sim, "tests/configs/earth_circular.txt"));
Vec3 sun_vel = {0, 0, 0};
add_body(sim, "Sun", 1.989e30, 6.96e8, sun_pos, sun_vel, -1, 1.0, 1.0, 0.0, 0, 0);
Vec3 earth_pos = {1.496e11, 0, 0};
Vec3 earth_vel = {0, 29800, 0};
add_body(sim, "Earth", 5.972e24, 6.371e6, earth_pos, earth_vel, 0, 0.0, 0.5, 1.0, 0, 1.496e11);
double initial_energy = calculate_system_total_energy(sim); double initial_energy = calculate_system_total_energy(sim);

17
tests/test_orbital_period.cpp

@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "../src/physics.h" #include "../src/physics.h"
#include "../src/bodies.h" #include "../src/bodies.h"
#include "../src/config_loader.h"
#include "../src/test_utilities.h" #include "../src/test_utilities.h"
#include <cmath> #include <cmath>
@ -12,13 +13,7 @@ TEST_CASE("Orbital period - Earth (RK4)", "[period][rk4]") {
SimulationState* sim = create_simulation(10, TIME_STEP); SimulationState* sim = create_simulation(10, TIME_STEP);
Vec3 sun_pos = {0, 0, 0}; REQUIRE(load_system_config(sim, "tests/configs/earth_circular.txt"));
Vec3 sun_vel = {0, 0, 0};
add_body(sim, "Sun", 1.989e30, 6.96e8, sun_pos, sun_vel, -1, 1.0, 1.0, 0.0, 0, 0);
Vec3 earth_pos = {1.496e11, 0, 0};
Vec3 earth_vel = {0, 29789, 0};
add_body(sim, "Earth", 5.972e24, 6.371e6, earth_pos, earth_vel, 0, 0.0, 0.5, 1.0, 0, 1.496e11);
OrbitTracker* tracker = create_orbit_tracker(1); OrbitTracker* tracker = create_orbit_tracker(1);
@ -51,13 +46,7 @@ TEST_CASE("Orbital period - Mars (RK4)", "[period][rk4]") {
SimulationState* sim = create_simulation(10, TIME_STEP); SimulationState* sim = create_simulation(10, TIME_STEP);
Vec3 sun_pos = {0, 0, 0}; REQUIRE(load_system_config(sim, "tests/configs/mars_circular.txt"));
Vec3 sun_vel = {0, 0, 0};
add_body(sim, "Sun", 1.989e30, 6.96e8, sun_pos, sun_vel, -1, 1.0, 1.0, 0.0, 0, 0);
Vec3 mars_pos = {2.244e11, 0, 0};
Vec3 mars_vel = {0, 24323, 0};
add_body(sim, "Mars", 6.39e23, 3.3895e6, mars_pos, mars_vel, 0, 0.8, 0.3, 0.1, 0, 2.244e11);
OrbitTracker* tracker = create_orbit_tracker(1); OrbitTracker* tracker = create_orbit_tracker(1);

Loading…
Cancel
Save