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.
62 lines
2.1 KiB
62 lines
2.1 KiB
#include <catch2/catch_test_macros.hpp> |
|
#include "../src/physics.h" |
|
#include "../src/simulation.h" |
|
#include "../src/config_loader.h" |
|
#include <cmath> |
|
|
|
TEST_CASE("Invalid parent: massive bodies never become children of small bodies", |
|
"[init][parent][hierarchy]") { |
|
const double TIME_STEP = 60.0; |
|
const double MASS_THRESHOLD_RATIO = 1000.0; |
|
|
|
SimulationState* sim = create_simulation(10, 0, 0, TIME_STEP); |
|
REQUIRE(load_system_config(sim, "tests/configs/earth_mars_simple.toml")); |
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
if (sim->bodies[i].parent_index >= 0) { |
|
int parent_idx = sim->bodies[i].parent_index; |
|
double parent_mass = sim->bodies[parent_idx].mass; |
|
double child_mass = sim->bodies[i].mass; |
|
double mass_ratio = parent_mass / child_mass; |
|
|
|
INFO("Body " << i << " (" << sim->bodies[i].name |
|
<< ") parent " << parent_idx << " (" << sim->bodies[parent_idx].name |
|
<< "): mass ratio = " << mass_ratio); |
|
|
|
REQUIRE(mass_ratio >= 1.0); |
|
|
|
if (strcmp(sim->bodies[parent_idx].name, "Spacecraft") != 0 && |
|
strcmp(sim->bodies[i].name, "Spacecraft") != 0) { |
|
REQUIRE(mass_ratio >= MASS_THRESHOLD_RATIO); |
|
} |
|
} |
|
} |
|
|
|
for (int step = 0; step < 100; step++) { |
|
update_simulation(sim); |
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
if (sim->bodies[i].parent_index >= 0) { |
|
int parent_idx = sim->bodies[i].parent_index; |
|
double parent_mass = sim->bodies[parent_idx].mass; |
|
double child_mass = sim->bodies[i].mass; |
|
|
|
if (child_mass > 1e20) { |
|
REQUIRE(parent_mass > child_mass); |
|
} |
|
} |
|
} |
|
} |
|
|
|
destroy_simulation(sim); |
|
} |
|
|
|
TEST_CASE("Mutual SOI: similar mass planets within SOI boundary", |
|
"[init][soi][mutual][edge_case]") { |
|
const double TIME_STEP = 60.0; |
|
|
|
SimulationState* sim = create_simulation(10, 0, 0, TIME_STEP); |
|
REQUIRE_FALSE(load_system_config(sim, "tests/configs/mutual_soi_close.toml")); |
|
|
|
destroy_simulation(sim); |
|
}
|
|
|