unit test that a sim finishes eventually

This commit is contained in:
Dustin Carlino 2018-08-09 12:53:12 -07:00
parent 44239588c8
commit 6d70605355
2 changed files with 36 additions and 0 deletions

View File

@ -400,6 +400,12 @@ impl Sim {
)
}
pub fn is_done(&self) -> bool {
let (_, active_cars) = self.driving_state.get_active_and_waiting_count();
let (_, active_peds) = self.walking_state.get_active_and_waiting_count();
active_cars == 0 && active_peds == 0
}
pub fn debug_ped(&self, id: PedestrianID) {
self.walking_state.debug_ped(id);
}

30
sim/tests/completion.rs Normal file
View File

@ -0,0 +1,30 @@
extern crate abstutil;
extern crate control;
extern crate map_model;
extern crate sim;
#[test]
fn aorta_model_completes() {
// This assumes this map has been built
let input = "../data/small.abst";
let rng_seed = 42;
let spawn_count = 100;
let map = map_model::Map::new(input, &map_model::Edits::new()).expect("Couldn't load map");
let control_map = control::ControlMap::new(&map);
let mut sim = sim::Sim::new(&map, Some(rng_seed), false);
sim.seed_pedestrians(&map, spawn_count);
sim.seed_parked_cars(0.5);
sim.start_many_parked_cars(&map, spawn_count);
loop {
sim.step(&map, &control_map);
if sim.time.is_multiple_of_minute() {
println!("{}", sim.summary());
}
if sim.is_done() {
break;
}
}
}