diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-05-15 23:14:32 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-05-15 23:14:32 +0200 |
commit | 0ebebeccd72ba76a2a9a9ad94c38feaed9b6ab1c (patch) | |
tree | 744e2c93bf925211286cf32e07b7bd74032e980e /tests/live-comparison.rs | |
parent | 1ee2a8c0edf506e50587b6b5cfe90077c9f5d8ae (diff) |
Added end to end tests, comparing against actual game engine
Diffstat (limited to 'tests/live-comparison.rs')
-rw-r--r-- | tests/live-comparison.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/live-comparison.rs b/tests/live-comparison.rs new file mode 100644 index 0000000..e090907 --- /dev/null +++ b/tests/live-comparison.rs @@ -0,0 +1,54 @@ +extern crate zombot; + +use zombot::json; +use zombot::engine::command::{Command, BuildingType}; +use zombot::engine::geometry::Point; + +#[test] +fn it_successfully_simulates_moves() { + let (settings, mut state) = json::read_state_from_file("tests/state0.json").expect("Failed to read state0.json"); + + let all_commands = [ + (Command::Build(Point::new(3,2),BuildingType::Energy), Command::Nothing), + (Command::Nothing, Command::Nothing), + (Command::Nothing, Command::Build(Point::new(4,3),BuildingType::Energy)), + (Command::Build(Point::new(3,1),BuildingType::Energy), Command::Nothing), + (Command::Nothing, Command::Nothing), + (Command::Build(Point::new(3,0),BuildingType::Energy),Command::Build(Point::new(6,0),BuildingType::Energy)), + (Command::Nothing,Command::Nothing), + (Command::Build(Point::new(3,3),BuildingType::Energy),Command::Build(Point::new(7,1),BuildingType::Attack)), + (Command::Nothing,Command::Nothing), + (Command::Build(Point::new(2,3),BuildingType::Attack),Command::Nothing), + + (Command::Build(Point::new(2,1),BuildingType::Energy),Command::Build(Point::new(5,3),BuildingType::Defence)), + (Command::Nothing,Command::Nothing), + (Command::Build(Point::new(1,0),BuildingType::Attack),Command::Nothing), + (Command::Nothing,Command::Build(Point::new(5,0),BuildingType::Defence)), + (Command::Build(Point::new(0,2),BuildingType::Attack),Command::Nothing), + (Command::Build(Point::new(3,1),BuildingType::Energy),Command::Nothing), + (Command::Nothing,Command::Nothing), + (Command::Build(Point::new(0,1),BuildingType::Attack),Command::Build(Point::new(7,2),BuildingType::Defence)), + (Command::Build(Point::new(2,1),BuildingType::Energy),Command::Nothing), + (Command::Nothing,Command::Nothing), + + (Command::Build(Point::new(0,0),BuildingType::Attack),Command::Nothing), + (Command::Build(Point::new(0,3),BuildingType::Attack),Command::Build(Point::new(4,1),BuildingType::Defence)), + (Command::Nothing,Command::Nothing), + (Command::Build(Point::new(1,3),BuildingType::Attack),Command::Nothing), + (Command::Build(Point::new(3,1),BuildingType::Energy),Command::Nothing), + (Command::Nothing,Command::Build(Point::new(6,1),BuildingType::Defence)), + (Command::Build(Point::new(2,2),BuildingType::Energy),Command::Nothing), + (Command::Build(Point::new(1,2),BuildingType::Energy),Command::Nothing), + (Command::Build(Point::new(3,1),BuildingType::Energy),Command::Build(Point::new(7,0),BuildingType::Defence)), + (Command::Build(Point::new(2,1),BuildingType::Energy),Command::Nothing) + ]; + + for (i, &(player, opponent)) in all_commands.iter().enumerate() { + let file = format!("tests/state{}.json", i+1); + state.simulate_mut(&settings, player, opponent); + let (_, mut actual_state) = json::read_state_from_file(&file).unwrap(); + state.sort(); + actual_state.sort(); + assert_eq!(state, actual_state, "\nFailed on state {}\n", i+1); + } +} |