diff --git a/control/src/stop_signs.rs b/control/src/stop_signs.rs index 6b57588287..98078d8ea3 100644 --- a/control/src/stop_signs.rs +++ b/control/src/stop_signs.rs @@ -220,12 +220,3 @@ impl ControlStopSign { Ok(()) } } - -#[cfg(test)] -mod tests { - #[test] - fn ordering() { - use stop_signs::TurnPriority; - assert!(TurnPriority::Priority > TurnPriority::Yield); - } -} diff --git a/sim/tests/completion.rs b/sim/tests/completion.rs deleted file mode 100644 index 9b40577747..0000000000 --- a/sim/tests/completion.rs +++ /dev/null @@ -1,18 +0,0 @@ -extern crate abstutil; -extern crate control; -extern crate map_model; -extern crate sim; - -#[test] -fn aorta_model_completes() { - let (map, control_map, mut sim) = sim::load( - sim::SimFlags::for_test("aorta_model_completes"), - Some(sim::Tick::from_seconds(30)), - &mut abstutil::Timer::new("setup test"), - ); - sim.small_spawn(&map); - sim.run_until_done(&map, &control_map, Box::new(|_sim| {})); -} - -// TODO other tests (not completion) to add: -// - different behavior (stopping or not) at stop signs diff --git a/sim/tests/determinism.rs b/sim/tests/determinism.rs deleted file mode 100644 index 51995f2c28..0000000000 --- a/sim/tests/determinism.rs +++ /dev/null @@ -1,97 +0,0 @@ -extern crate abstutil; -extern crate control; -extern crate map_model; -extern crate sim; - -#[test] -fn serialization() { - let (map, _, mut sim) = sim::load( - sim::SimFlags::for_test("serialization"), - None, - &mut abstutil::Timer::new("setup test"), - ); - sim.small_spawn(&map); - - // Does savestating produce the same string? - let save1 = abstutil::to_json(&sim); - let save2 = abstutil::to_json(&sim); - assert_eq!(save1, save2); -} - -#[test] -fn from_scratch() { - println!("Creating two simulations"); - let (map, control_map, mut sim1) = sim::load( - sim::SimFlags::for_test("from_scratch_1"), - None, - &mut abstutil::Timer::new("setup test"), - ); - let mut sim2 = sim::Sim::new(&map, "from_scratch_2".to_string(), Some(42), None); - sim1.small_spawn(&map); - sim2.small_spawn(&map); - - for _ in 1..600 { - if sim1 != sim2 { - // TODO need to sort dicts in json output to compare - panic!( - "sim state differs between {} and {}", - sim1.save(), - sim2.save() - ); - } - sim1.step(&map, &control_map); - sim2.step(&map, &control_map); - } -} - -#[test] -fn with_savestating() { - println!("Creating two simulations"); - let (map, control_map, mut sim1) = sim::load( - sim::SimFlags::for_test("with_savestating_1"), - None, - &mut abstutil::Timer::new("setup test"), - ); - let mut sim2 = sim::Sim::new(&map, "with_savestating_2".to_string(), Some(42), None); - sim1.small_spawn(&map); - sim2.small_spawn(&map); - - for _ in 1..600 { - sim1.step(&map, &control_map); - sim2.step(&map, &control_map); - } - - if sim1 != sim2 { - panic!( - "sim state differs between {} and {}", - sim1.save(), - sim2.save() - ); - } - - let sim1_save = sim1.save(); - - for _ in 1..60 { - sim1.step(&map, &control_map); - } - - if sim1 == sim2 { - panic!( - "sim state unexpectly the same -- {} and {}", - sim1.save(), - sim2.save() - ); - } - - let sim3: sim::Sim = - sim::Sim::load(sim1_save.clone(), "with_savestating_3".to_string()).unwrap(); - if sim3 != sim2 { - panic!( - "sim state differs between {} and {}", - sim3.save(), - sim2.save() - ); - } - - std::fs::remove_file(sim1_save).unwrap(); -} diff --git a/tests/src/main.rs b/tests/src/main.rs index cc29666cc1..6faa638863 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -10,6 +10,8 @@ extern crate yansi; mod map_conversion; mod physics; mod runner; +mod sim_completion; +mod sim_determinism; use structopt::StructOpt; @@ -26,6 +28,8 @@ fn main() { map_conversion::run(t.suite("map_conversion")); physics::run(t.suite("physics")); + sim_completion::run(t.suite("sim_completion")); + sim_determinism::run(t.suite("sim_determinism")); t.done(); } diff --git a/tests/src/sim_completion.rs b/tests/src/sim_completion.rs new file mode 100644 index 0000000000..e3bc7fbf6b --- /dev/null +++ b/tests/src/sim_completion.rs @@ -0,0 +1,21 @@ +use abstutil::Timer; +use runner::TestRunner; +use sim; + +pub fn run(t: &mut TestRunner) { + t.run_slow( + "small_spawn_completes", + Box::new(|_| { + let (map, control_map, mut sim) = sim::load( + sim::SimFlags::for_test("aorta_model_completes"), + Some(sim::Tick::from_seconds(30)), + &mut Timer::new("setup test"), + ); + sim.small_spawn(&map); + sim.run_until_done(&map, &control_map, Box::new(|_sim| {})); + }), + ); +} + +// TODO other tests (not completion) to add: +// - different behavior (stopping or not) at stop signs diff --git a/tests/src/sim_determinism.rs b/tests/src/sim_determinism.rs new file mode 100644 index 0000000000..de7d724972 --- /dev/null +++ b/tests/src/sim_determinism.rs @@ -0,0 +1,104 @@ +use abstutil::Timer; +use runner::TestRunner; +use sim; + +pub fn run(t: &mut TestRunner) { + t.run_slow( + "serialization", + Box::new(|_| { + let (map, _, mut sim) = sim::load( + sim::SimFlags::for_test("serialization"), + None, + &mut Timer::new("setup test"), + ); + sim.small_spawn(&map); + + // Does savestating produce the same string? + let save1 = abstutil::to_json(&sim); + let save2 = abstutil::to_json(&sim); + assert_eq!(save1, save2); + }), + ); + + t.run_slow( + "from_scratch", + Box::new(|_| { + println!("Creating two simulations"); + let (map, control_map, mut sim1) = sim::load( + sim::SimFlags::for_test("from_scratch_1"), + None, + &mut Timer::new("setup test"), + ); + let mut sim2 = sim::Sim::new(&map, "from_scratch_2".to_string(), Some(42), None); + sim1.small_spawn(&map); + sim2.small_spawn(&map); + + for _ in 1..600 { + if sim1 != sim2 { + // TODO need to sort dicts in json output to compare + panic!( + "sim state differs between {} and {}", + sim1.save(), + sim2.save() + ); + } + sim1.step(&map, &control_map); + sim2.step(&map, &control_map); + } + }), + ); + + t.run_slow( + "with_savestating", + Box::new(|_| { + println!("Creating two simulations"); + let (map, control_map, mut sim1) = sim::load( + sim::SimFlags::for_test("with_savestating_1"), + None, + &mut Timer::new("setup test"), + ); + let mut sim2 = sim::Sim::new(&map, "with_savestating_2".to_string(), Some(42), None); + sim1.small_spawn(&map); + sim2.small_spawn(&map); + + for _ in 1..600 { + sim1.step(&map, &control_map); + sim2.step(&map, &control_map); + } + + if sim1 != sim2 { + panic!( + "sim state differs between {} and {}", + sim1.save(), + sim2.save() + ); + } + + let sim1_save = sim1.save(); + + for _ in 1..60 { + sim1.step(&map, &control_map); + } + + if sim1 == sim2 { + panic!( + "sim state unexpectly the same -- {} and {}", + sim1.save(), + sim2.save() + ); + } + + let sim3: sim::Sim = + sim::Sim::load(sim1_save.clone(), "with_savestating_3".to_string()).unwrap(); + if sim3 != sim2 { + panic!( + "sim state differs between {} and {}", + sim3.save(), + sim2.save() + ); + } + + std::fs::remove_file(sim1_save).unwrap(); + }), + ); +}