From f66c864b6450742e99fc3c70647fd06d4a2d8f87 Mon Sep 17 00:00:00 2001 From: Mrinal Paliwal Date: Thu, 30 Jun 2022 13:48:43 +0530 Subject: [PATCH] Add tests to validate check fix --- src/game.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index a5b5911..01bf892 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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 @@ -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! {"