From 0ab0e6a00c9fcf29612fb73538cbfdaa9136e6c3 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 8 Nov 2020 23:48:26 +0100 Subject: [PATCH] More tests --- dungeonbattle/display/display.py | 9 +++------ dungeonbattle/display/mapdisplay.py | 1 - dungeonbattle/display/menudisplay.py | 1 - dungeonbattle/display/statsdisplay.py | 1 - dungeonbattle/entities/player.py | 4 ++++ dungeonbattle/tests/game_test.py | 15 ++++++++++++++- dungeonbattle/tests/screen.py | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index b64ac9c..d569d9b 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -7,14 +7,11 @@ from dungeonbattle.tests.screen import FakePad class Display: def __init__(self, screen: Any): self.screen = screen - self.rows = curses.LINES if screen else 4 - self.cols = curses.COLS * 4 // 5 if screen else 4 + self.rows = curses.LINES if screen else 42 + self.cols = curses.COLS * 4 // 5 if screen else 42 def refresh(self) -> None: raise NotImplementedError def newpad(self, height: int, width: int) -> Union[FakePad, Any]: - if self.screen: - return curses.newpad(height, width) - else: - return FakePad() + return curses.newpad(height, width) if self.screen else FakePad() diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index fd2cc89..38a27a2 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -import curses from typing import Any from dungeonbattle.display.display import Display diff --git a/dungeonbattle/display/menudisplay.py b/dungeonbattle/display/menudisplay.py index d8252f8..a619199 100644 --- a/dungeonbattle/display/menudisplay.py +++ b/dungeonbattle/display/menudisplay.py @@ -1,7 +1,6 @@ from dungeonbattle.display.display import Display from dungeonbattle.menus import Menu from typing import Any -import curses class MenuDisplay(Display): diff --git a/dungeonbattle/display/statsdisplay.py b/dungeonbattle/display/statsdisplay.py index 131d914..cc5bc74 100644 --- a/dungeonbattle/display/statsdisplay.py +++ b/dungeonbattle/display/statsdisplay.py @@ -1,4 +1,3 @@ -import curses from typing import Any from dungeonbattle.display.display import Display diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index 4556f9f..9f01d0d 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -4,6 +4,10 @@ from ..interfaces import FightingEntity class Player(FightingEntity): maxhealth: int = 20 strength: int = 5 + intelligence: int = 1 + charisma: int = 1 + dexterity: int = 1 + constitution: int = 1 level: int = 1 current_xp: int = 0 max_xp: int = 10 diff --git a/dungeonbattle/tests/game_test.py b/dungeonbattle/tests/game_test.py index f4c1fdf..b591a68 100644 --- a/dungeonbattle/tests/game_test.py +++ b/dungeonbattle/tests/game_test.py @@ -1,5 +1,7 @@ import unittest +from dungeonbattle.display.display import Display +from dungeonbattle.display.statsdisplay import StatsDisplay from dungeonbattle.game import Game, KeyValues, GameMode from dungeonbattle.menus import MainMenuValues @@ -14,6 +16,7 @@ class TestGame(unittest.TestCase): def test_load_game(self) -> None: self.assertRaises(NotImplementedError, Game.load_game, "game.save") + self.assertRaises(NotImplementedError, Display(None).refresh) def test_key_translation(self) -> None: """ @@ -37,6 +40,7 @@ class TestGame(unittest.TestCase): self.game.settings.KEY_RIGHT_SECONDARY), KeyValues.RIGHT) self.assertEqual(self.game.translate_key( self.game.settings.KEY_ENTER), KeyValues.ENTER) + self.assertEqual(self.game.translate_key(' '), KeyValues.SPACE) def test_key_press(self) -> None: """ @@ -54,7 +58,8 @@ class TestGame(unittest.TestCase): self.game.handle_key_pressed(KeyValues.ENTER) self.assertEqual(self.game.state, GameMode.SETTINGS) - self.game.state = GameMode.MAINMENU + self.game.handle_key_pressed(KeyValues.SPACE) + self.assertEqual(self.game.state, GameMode.MAINMENU) self.game.handle_key_pressed(KeyValues.DOWN) self.assertEqual(self.game.main_menu.validate(), @@ -95,3 +100,11 @@ class TestGame(unittest.TestCase): new_y, new_x = self.game.player.y, self.game.player.x self.assertEqual(new_y, y) self.assertEqual(new_x, x - 1) + + self.game.handle_key_pressed(KeyValues.SPACE) + self.assertEqual(self.game.state, GameMode.MAINMENU) + + def test_stats_display(self) -> None: + self.game.current_display = StatsDisplay(None, self.game.player, + 42, 42, 0, 0) + self.game.current_display.refresh() diff --git a/dungeonbattle/tests/screen.py b/dungeonbattle/tests/screen.py index 8963ce0..c1aad8c 100644 --- a/dungeonbattle/tests/screen.py +++ b/dungeonbattle/tests/screen.py @@ -10,5 +10,5 @@ class FakePad: smincol: int, smaxrow: int, smaxcol: int) -> None: pass - def clear(self): + def clear(self) -> None: pass