From 3edbf30719d5bec8d1504e4a35b73876554778d2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 25 Jun 2018 09:06:40 -0700 Subject: [PATCH] woops, forgot to fix a sim test ages ago when refactoring json writing/reading --- sim/Cargo.toml | 1 + sim/tests/determinism.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sim/Cargo.toml b/sim/Cargo.toml index ae030f6e18..4913923ce6 100644 --- a/sim/Cargo.toml +++ b/sim/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Dustin Carlino "] [dependencies] +abstutil = { path = "../abstutil" } control = { path = "../control" } derivative = "1.0.0" dimensioned = "0.6.0" diff --git a/sim/tests/determinism.rs b/sim/tests/determinism.rs index f62ff23f78..6ef35ded00 100644 --- a/sim/tests/determinism.rs +++ b/sim/tests/determinism.rs @@ -1,3 +1,4 @@ +extern crate abstutil; extern crate control; extern crate map_model; extern crate sim; @@ -25,8 +26,8 @@ fn from_scratch() { if sim1 != sim2 { // TODO write to temporary files somewhere // TODO need to sort dicts in json output to compare - sim1.write_savestate("sim1_state.json").unwrap(); - sim2.write_savestate("sim2_state.json").unwrap(); + abstutil::write_json("sim1_state.json", &sim1).unwrap(); + abstutil::write_json("sim2_state.json", &sim2).unwrap(); panic!("sim state differs at {}. compare sim1_state.json and sim2_state.json", sim1.time); } sim1.step(&map, &control_map); @@ -57,27 +58,27 @@ fn with_savestating() { } if sim1 != sim2 { - sim1.write_savestate("sim1_state.json").unwrap(); - sim2.write_savestate("sim2_state.json").unwrap(); + abstutil::write_json("sim1_state.json", &sim1).unwrap(); + abstutil::write_json("sim2_state.json", &sim2).unwrap(); panic!("sim state differs at {}. compare sim1_state.json and sim2_state.json", sim1.time); } - sim1.write_savestate("sim1_savestate.json").unwrap(); + abstutil::write_json("sim1_savestate.json", &sim1).unwrap(); for _ in 1..60 { sim1.step(&map, &control_map); } if sim1 == sim2 { - sim1.write_savestate("sim1_state.json").unwrap(); - sim2.write_savestate("sim2_state.json").unwrap(); + abstutil::write_json("sim1_state.json", &sim1).unwrap(); + abstutil::write_json("sim2_state.json", &sim2).unwrap(); panic!("sim state unexpectedly the same at {}. compare sim1_state.json and sim2_state.json", sim1.time); } - let sim3 = sim::straw_model::Sim::load_savestate("sim1_savestate.json").unwrap(); + let sim3: sim::straw_model::Sim = abstutil::read_json("sim1_savestate.json").unwrap(); if sim3 != sim2 { - sim3.write_savestate("sim3_state.json").unwrap(); - sim2.write_savestate("sim2_state.json").unwrap(); + abstutil::write_json("sim3_state.json", &sim3).unwrap(); + abstutil::write_json("sim2_state.json", &sim2).unwrap(); panic!("sim state differs at {}. compare sim3_state.json and sim2_state.json", sim1.time); }