Skip to content

Commit

Permalink
Add tests to validate check fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mnpw committed Jun 30, 2022
1 parent 5833b5f commit f66c864
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mod tests {
}

#[test]
fn next_move_win() {
fn next_move_win_top_left() {
let state = indoc! {"
1024,1024,0,0
0,0,0,0
Expand All @@ -151,6 +151,78 @@ mod tests {
assert_eq!(state, GameState::Won);
}

#[test]
fn next_move_win_top_right() {
let state = indoc! {"
0,0,1024,1024
0,0,0,0
0,0,0,0
0,0,0,0
"};

let mut game = Game::from(4, 2048, state);
let state = game.check().unwrap();
assert_eq!(state, GameState::InProgress);

game.play("right").unwrap();
let state = game.check().unwrap();
assert_eq!(state, GameState::Won);
}

#[test]
fn next_move_win_bottom_left() {
let state = indoc! {"
0,0,0,0
0,0,0,0
0,0,0,0
1024,1024,0,0
"};

let mut game = Game::from(4, 2048, state);
let state = game.check().unwrap();
assert_eq!(state, GameState::InProgress);

game.play("left").unwrap();
let state = game.check().unwrap();
assert_eq!(state, GameState::Won);
}

#[test]
fn next_move_win_bottom_right() {
let state = indoc! {"
0,0,0,0
0,0,0,0
0,0,0,0
0,0,1024,1024
"};

let mut game = Game::from(4, 2048, state);
let state = game.check().unwrap();
assert_eq!(state, GameState::InProgress);

game.play("right").unwrap();
let state = game.check().unwrap();
assert_eq!(state, GameState::Won);
}

#[test]
fn next_move_win_center() {
let state = indoc! {"
0,0,0,0
0,0,0,0
0,1024,1024,0
0,0,0,0
"};

let mut game = Game::from(4, 2048, state);
let state = game.check().unwrap();
assert_eq!(state, GameState::InProgress);

game.play("left").unwrap();
let state = game.check().unwrap();
assert_eq!(state, GameState::Won);
}

#[test]
fn alter_winning_number() {
let state = indoc! {"
Expand Down

0 comments on commit f66c864

Please sign in to comment.