1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
}
|