moving two sim tests over to the new runner

This commit is contained in:
Dustin Carlino 2018-11-23 15:57:50 -08:00
parent 878889133a
commit cec29beda5
6 changed files with 129 additions and 124 deletions

View File

@ -220,12 +220,3 @@ impl ControlStopSign {
Ok(())
}
}
#[cfg(test)]
mod tests {
#[test]
fn ordering() {
use stop_signs::TurnPriority;
assert!(TurnPriority::Priority > TurnPriority::Yield);
}
}

View File

@ -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

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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

View File

@ -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();
}),
);
}