From 93245a79ca40e639fd92d0bd7f8f325950a2709b Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 15 Apr 2018 17:51:45 -0700 Subject: [PATCH] start a test to see if simulations are deterministic. they... aren't :( --- sim/tests/determinism.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sim/tests/determinism.rs diff --git a/sim/tests/determinism.rs b/sim/tests/determinism.rs new file mode 100644 index 0000000000..5b34bd4ab4 --- /dev/null +++ b/sim/tests/determinism.rs @@ -0,0 +1,34 @@ +extern crate control; +extern crate geom; +extern crate map_model; +extern crate sim; + +#[test] +fn from_scratch() { + // This assumes this map has been built + let input = "../data/small.abst"; + let rng_seed = 42; + let spawn_count = 1000; + + println!("Creating two simulations"); + let data = map_model::load_pb(input).expect("Couldn't load input"); + let map = map_model::Map::new(&data); + let geom_map = geom::GeomMap::new(&map); + let control_map = control::ControlMap::new(&map, &geom_map); + + let mut sim1 = sim::straw_model::Sim::new(&map, &geom_map, Some(rng_seed)); + let mut sim2 = sim::straw_model::Sim::new(&map, &geom_map, Some(rng_seed)); + sim1.spawn_many_on_empty_roads(spawn_count); + sim2.spawn_many_on_empty_roads(spawn_count); + + for _ in 1..1200 { + if sim1 != sim2 { + // TODO need to sort dicts in json output to compare + sim1.write_savestate("sim1_state.json").unwrap(); + sim2.write_savestate("sim2_state.json").unwrap(); + panic!("sim state differs at {}. compare sim1_state.json and sim2_state.json", sim1.time); + } + sim1.step(&geom_map, &map, &control_map); + sim2.step(&geom_map, &map, &control_map); + } +}