From 3520a76613997f94f413b1a565a7022f05c8c113 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 19 Nov 2020 01:39:12 +0100 Subject: [PATCH] Test to create/resume a game --- dungeonbattle/tests/game_test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dungeonbattle/tests/game_test.py b/dungeonbattle/tests/game_test.py index 6784dd2..8e7970d 100644 --- a/dungeonbattle/tests/game_test.py +++ b/dungeonbattle/tests/game_test.py @@ -26,6 +26,7 @@ class TestGame(unittest.TestCase): """ old_state = self.game.save_state() + self.game.handle_key_pressed(KeyValues.DOWN) self.game.handle_key_pressed(KeyValues.DOWN) self.assertEqual(self.game.main_menu.validate(), MainMenuValues.SAVE) self.game.handle_key_pressed(KeyValues.ENTER) # Save game @@ -94,6 +95,9 @@ class TestGame(unittest.TestCase): self.assertEqual(self.game.main_menu.validate(), MainMenuValues.START) self.game.handle_key_pressed(KeyValues.DOWN) + self.assertEqual(self.game.main_menu.validate(), + MainMenuValues.RESUME) + self.game.handle_key_pressed(KeyValues.DOWN) self.assertEqual(self.game.main_menu.validate(), MainMenuValues.SAVE) self.game.handle_key_pressed(KeyValues.DOWN) @@ -124,6 +128,9 @@ class TestGame(unittest.TestCase): self.assertEqual(self.game.main_menu.validate(), MainMenuValues.SAVE) self.game.handle_key_pressed(KeyValues.UP) + self.assertEqual(self.game.main_menu.validate(), + MainMenuValues.RESUME) + self.game.handle_key_pressed(KeyValues.UP) self.assertEqual(self.game.main_menu.validate(), MainMenuValues.START) @@ -162,6 +169,29 @@ class TestGame(unittest.TestCase): self.game.handle_key_pressed(KeyValues.SPACE) self.assertEqual(self.game.state, GameMode.MAINMENU) + def test_new_game(self) -> None: + """ + Ensure that the start button starts a new game. + """ + old_map = self.game.map + old_player = self.game.player + self.game.handle_key_pressed(KeyValues.ENTER) # Start new game + new_map = self.game.map + new_player = self.game.player + # Ensure that + self.assertNotEqual(old_map, new_map) + self.assertNotEqual(old_player, new_player) + + self.game.handle_key_pressed(KeyValues.SPACE) + old_map = new_map + old_player = new_player + self.game.handle_key_pressed(KeyValues.DOWN) + self.game.handle_key_pressed(KeyValues.ENTER) # Resume game + new_map = self.game.map + new_player = self.game.player + self.assertEqual(old_map, new_map) + self.assertEqual(old_player, new_player) + def test_settings_menu(self) -> None: """ Ensure that the settings menu is working properly. @@ -172,6 +202,7 @@ class TestGame(unittest.TestCase): self.game.handle_key_pressed(KeyValues.DOWN) self.game.handle_key_pressed(KeyValues.DOWN) self.game.handle_key_pressed(KeyValues.DOWN) + self.game.handle_key_pressed(KeyValues.DOWN) self.game.handle_key_pressed(KeyValues.ENTER) self.assertEqual(self.game.state, GameMode.SETTINGS)