mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
start a test to see if simulations are deterministic. they... aren't :(
This commit is contained in:
parent
9f3fd72417
commit
93245a79ca
34
sim/tests/determinism.rs
Normal file
34
sim/tests/determinism.rs
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user