summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-04 19:37:35 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-04 19:37:35 +0200
commitd0b2740ddea28b20fd26d7dbd19149a76df129ff (patch)
tree07e93267d0b9831b079d9348a0c47be9b130c73c /tests
parente051d9bd5554620f7f53d34f6f84331235cfb3cd (diff)
Added tests of indexing into random bitwise building
Diffstat (limited to 'tests')
-rw-r--r--tests/expressive_to_bitwise_comparison.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/expressive_to_bitwise_comparison.rs b/tests/expressive_to_bitwise_comparison.rs
index 4a2a87e..f08b316 100644
--- a/tests/expressive_to_bitwise_comparison.rs
+++ b/tests/expressive_to_bitwise_comparison.rs
@@ -46,31 +46,33 @@ proptest! {
let mut expected_status = GameStatus::Continue;
while expected_status == GameStatus::Continue {
- let player_command = random_player_move(&settings, &expressive_state, &mut rng);
- let opponent_command = random_opponent_move(&settings, &expressive_state, &mut rng);
+ let player_command = random_player_move(&settings, &expressive_state, &bitwise_state, &mut rng);
+ let opponent_command = random_opponent_move(&settings, &expressive_state, &bitwise_state, &mut rng);
println!("Player command: {}", player_command);
println!("Opponent command: {}", opponent_command);
expected_status = expressive_state.simulate(&settings, player_command, opponent_command);
let actual_status = bitwise_state.simulate(&settings, player_command, opponent_command);
+ expressive_state.sort();
+
assert_eq!(&expected_status, &actual_status);
assert_eq!(build_bitwise_from_expressive(&expressive_state), bitwise_state.sorted());
}
}
}
-fn random_player_move<R: Rng, GS: GameState>(settings: &GameSettings, state: &GS, rng: &mut R) -> Command {
- let all_buildings = sensible_buildings(settings, &state.player(), true);
- random_move(&all_buildings, rng, state.unoccupied_player_cell_count(), |i| state.location_of_unoccupied_player_cell(i))
+fn random_player_move<R: Rng, GSE: GameState, GSB: GameState>(settings: &GameSettings, expressive_state: &GSE, bitwise_state: &GSB, rng: &mut R) -> Command {
+ let all_buildings = sensible_buildings(settings, &expressive_state.player(), true);
+ random_move(&all_buildings, rng, expressive_state.unoccupied_player_cell_count(), |i| expressive_state.location_of_unoccupied_player_cell(i), |i| bitwise_state.location_of_unoccupied_player_cell(i))
}
-fn random_opponent_move<R: Rng, GS: GameState>(settings: &GameSettings, state: &GS, rng: &mut R) -> Command {
- let all_buildings = sensible_buildings(settings, &state.opponent(), true);
- random_move(&all_buildings, rng, state.unoccupied_opponent_cell_count(), |i| state.location_of_unoccupied_opponent_cell(i))
+fn random_opponent_move<R: Rng, GSE: GameState, GSB: GameState>(settings: &GameSettings, expressive_state: &GSE, bitwise_state: &GSB, rng: &mut R) -> Command {
+ let all_buildings = sensible_buildings(settings, &expressive_state.opponent(), true);
+ random_move(&all_buildings, rng, expressive_state.unoccupied_opponent_cell_count(), |i| expressive_state.location_of_unoccupied_opponent_cell(i), |i| bitwise_state.location_of_unoccupied_opponent_cell(i))
}
-fn random_move<R: Rng, F:Fn(usize)->Point>(all_buildings: &[BuildingType], rng: &mut R, free_positions_count: usize, get_point: F) -> Command {
+fn random_move<R: Rng, FE:Fn(usize)->Point, FB:Fn(usize)->Point>(all_buildings: &[BuildingType], rng: &mut R, free_positions_count: usize, get_point_expressive: FE, get_point_bitwise: FB) -> Command {
let building_command_count = free_positions_count*all_buildings.len();
let nothing_count = 1;
@@ -81,8 +83,11 @@ fn random_move<R: Rng, F:Fn(usize)->Point>(all_buildings: &[BuildingType], rng:
if choice_index == number_of_commands - 1 {
Command::Nothing
} else {
+ let expressive_point = get_point_expressive(choice_index/all_buildings.len());
+ let bitwise_point = get_point_bitwise(choice_index/all_buildings.len());
+ assert_eq!(expressive_point, bitwise_point);
Command::Build(
- get_point(choice_index/all_buildings.len()),
+ expressive_point,
all_buildings[choice_index%all_buildings.len()]
)
}