@ -10,30 +10,25 @@
TEST_CASE ( " Spacecraft loading from config " , " [spacecraft][config] " ) {
const double TIME_STEP = 60.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( craft_state - > craft_count = = 1 ) ;
REQUIRE ( std : : string ( craft_state - > spacecraft [ 0 ] . name ) = = " LEO_Satellite " ) ;
REQUIRE ( craft_state - > spacecraft [ 0 ] . parent_index = = 1 ) ;
REQUIRE ( sim - > craft_count = = 1 ) ;
REQUIRE ( std : : string ( sim - > spacecraft [ 0 ] . name ) = = " LEO_Satellite " ) ;
REQUIRE ( sim - > spacecraft [ 0 ] . parent_index = = 1 ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}
TEST_CASE ( " Prograde burn increases orbital energy " , " [spacecraft][burn][prograde] " ) {
const double TIME_STEP = 60.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
Spacecraft * craft = & craft_state - > spacecraft [ 0 ] ;
Spacecraft * craft = & sim - > spacecraft [ 0 ] ;
CelestialBody * earth = & sim - > bodies [ 1 ] ;
double initial_distance = vec3_distance ( craft - > position , earth - > position ) ;
@ -47,27 +42,23 @@ TEST_CASE("Prograde burn increases orbital energy", "[spacecraft][burn][prograde
double sim_time = 0.0 ;
while ( sim_time < SECONDS_TO_SIMULATE ) {
update_simulation ( sim ) ;
update_spacecraft ( craft_state , sim ) ;
sim_time + = TIME_STEP ;
}
double final_distance = vec3_distance ( craft - > position , earth - > position ) ;
REQUIRE ( final_distance > initial_distance ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}
TEST_CASE ( " Retrograde burn decreases orbital energy " , " [spacecraft][burn][retrograde] " ) {
const double TIME_STEP = 60.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
Spacecraft * craft = & craft_state - > spacecraft [ 0 ] ;
Spacecraft * craft = & sim - > spacecraft [ 0 ] ;
CelestialBody * earth = & sim - > bodies [ 1 ] ;
double initial_distance = vec3_distance ( craft - > position , earth - > position ) ;
@ -81,27 +72,23 @@ TEST_CASE("Retrograde burn decreases orbital energy", "[spacecraft][burn][retrog
double sim_time = 0.0 ;
while ( sim_time < SECONDS_TO_SIMULATE ) {
update_simulation ( sim ) ;
update_spacecraft ( craft_state , sim ) ;
sim_time + = TIME_STEP ;
}
double final_distance = vec3_distance ( craft - > position , earth - > position ) ;
REQUIRE ( final_distance < initial_distance ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}
TEST_CASE ( " Normal burn changes orbital plane " , " [spacecraft][burn][normal] " ) {
const double TIME_STEP = 60.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
Spacecraft * craft = & craft_state - > spacecraft [ 0 ] ;
Spacecraft * craft = & sim - > spacecraft [ 0 ] ;
double initial_z = craft - > local_position . z ;
@ -111,26 +98,22 @@ TEST_CASE("Normal burn changes orbital plane", "[spacecraft][burn][normal]") {
double sim_time = 0.0 ;
while ( sim_time < SECONDS_TO_SIMULATE ) {
update_simulation ( sim ) ;
update_spacecraft ( craft_state , sim ) ;
sim_time + = TIME_STEP ;
}
REQUIRE ( fabs ( craft - > local_position . z - initial_z ) > 1000.0 ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}
TEST_CASE ( " Custom burn applies arbitrary delta-v " , " [spacecraft][burn][custom] " ) {
const double TIME_STEP = 60.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
Spacecraft * craft = & craft_state - > spacecraft [ 0 ] ;
Spacecraft * craft = & sim - > spacecraft [ 0 ] ;
Vec3 initial_vel = craft - > local_velocity ;
Vec3 delta_v = { 10.0 , 20.0 , 30.0 } ;
@ -141,7 +124,6 @@ TEST_CASE("Custom burn applies arbitrary delta-v", "[spacecraft][burn][custom]")
REQUIRE ( fabs ( craft - > local_velocity . y - initial_vel . y - 20.0 ) < 0.001 ) ;
REQUIRE ( fabs ( craft - > local_velocity . z - initial_vel . z - 30.0 ) < 0.001 ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}
@ -150,13 +132,11 @@ TEST_CASE("Spacecraft propagation maintains stability", "[spacecraft][propagatio
const double DAYS_TO_SIMULATE = 1.0 ;
const double SECONDS_PER_DAY = 86400.0 ;
SimulationState * sim = create_simulation ( 10 , TIME_STEP ) ;
SpacecraftState * craft_state = create_spacecraft_state ( 10 ) ;
SimulationState * sim = create_simulation ( 10 , 10 , TIME_STEP ) ;
REQUIRE ( load_system_config ( sim , " tests/configs/spacecraft_test.toml " ) ) ;
REQUIRE ( load_spacecraft_config ( craft_state , sim , " tests/configs/spacecraft_test.toml " ) ) ;
Spacecraft * craft = & craft_state - > spacecraft [ 0 ] ;
Spacecraft * craft = & sim - > spacecraft [ 0 ] ;
CelestialBody * earth = & sim - > bodies [ 1 ] ;
double initial_distance = vec3_distance ( craft - > position , earth - > position ) ;
@ -165,7 +145,6 @@ TEST_CASE("Spacecraft propagation maintains stability", "[spacecraft][propagatio
double sim_time = 0.0 ;
while ( sim_time < total_time ) {
update_simulation ( sim ) ;
update_spacecraft ( craft_state , sim ) ;
sim_time + = TIME_STEP ;
}
@ -178,6 +157,5 @@ TEST_CASE("Spacecraft propagation maintains stability", "[spacecraft][propagatio
REQUIRE ( distance_drift_percent < 1.0 ) ;
destroy_spacecraft_state ( craft_state ) ;
destroy_simulation ( sim ) ;
}