diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-25 14:45:01 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-25 14:45:01 +0200 |
commit | 84ff4aa8fc7714b5841097e0dd800085982321e4 (patch) | |
tree | efff225e0312447de2d8282a61ea50b9eb29a140 /tests/test_board.py | |
parent | 16c470e7782487db34c5af8dba3d4c427ff9e434 (diff) |
Implements levels to Board
Diffstat (limited to 'tests/test_board.py')
-rw-r--r-- | tests/test_board.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/tests/test_board.py b/tests/test_board.py index 19795b9..be4b9dc 100644 --- a/tests/test_board.py +++ b/tests/test_board.py @@ -2,7 +2,7 @@ # pylint: disable = protected-access import unittest -from board.board import Board +from board.board import Board, Level, LevelSpecs class TestBoardClass(unittest.TestCase): """ pelilauden testit""" @@ -11,15 +11,23 @@ class TestBoardClass(unittest.TestCase): b = Board() self.assertTrue(b.get_width()>0) - def test_init_with_size(self): - """ olion luominen onnistuu tietyllä koolla""" - b = Board(30, 15) - self.assertEqual(b.get_width(), 30) - self.assertEqual(b.get_height(), 15) + def test_init_with_level(self): + """ olion luominen onnistuu vaikeustasolla""" + b = Board(level=Level.EXPERT) + self.assertEqual(b.get_width(), LevelSpecs[Level.EXPERT][0]) + self.assertEqual(b.get_height(), LevelSpecs[Level.EXPERT][1]) + self.assertEqual(b.get_bombs(), LevelSpecs[Level.EXPERT][2]) + + def test_init_with_incorect_dimensions(self): + """ luominen ei saa onnitua mahdottomilla mitoilla """ + b = Board(width=1, height=999) + self.assertEqual(b.get_width(), LevelSpecs[Level.BEGINNER][0]) + self.assertEqual(b.get_height(), LevelSpecs[Level.BEGINNER][1]) + self.assertEqual(b.get_bombs(), LevelSpecs[Level.BEGINNER][2]) def test_get_view_and_guess(self): """ laudan näkymä on oikein senkin jälkeen kun on arvattu""" - b = Board(3,3) + b = Board(width=3, height=3) b._Board__tiles=[[0,0,0],[0,1,1],[0,1,9]] v = b.get_view() @@ -37,7 +45,7 @@ class TestBoardClass(unittest.TestCase): def test_is_winning(self): """ toimiiko voittotilanteen tunnistus """ - b = Board(2,2) + b = Board(width=2, height=2) b._Board__tiles=[[1,9],[9,9]] b._Board__masked=[[12,12],[12,12]] self.assertFalse(b.is_winning()) @@ -48,7 +56,7 @@ class TestBoardClass(unittest.TestCase): def test_error_conditions_in_guess(self): """ ruudun avaus alueen ulkopuolelta tai avatussa ruudussa ei onnistu""" - b = Board(2,2) + b = Board(width=2, height=2) b._Board__tiles=[[1,9],[9,9]] self.assertFalse(b.guess(2,2)) self.assertTrue(b.guess(0,0)) @@ -56,13 +64,13 @@ class TestBoardClass(unittest.TestCase): def test_get_mask(self): """ maski annetaan oikein """ - b = Board(2,2) + b = Board(width=2, height=2) b._Board__tiles=[[1,9],[9,9]] self.assertEqual(b.get_mask(0,0), 12) def test_flag(self): """ ruudun liputus toimii """ - b = Board(2,2) + b = Board(width=2, height=2) b._Board__tiles=[[1,9],[9,9]] self.assertEqual(b.get_mask(0,0), 12) self.assertTrue(b.flag(0,0)) @@ -78,7 +86,7 @@ class TestBoardClass(unittest.TestCase): def test_flag_error_conditions(self): """ liputus ei onnistu jos avattu, alueen ulkopuolella, outo arvo """ - b = Board(2,2) + b = Board(width=2, height=2) b._Board__tiles=[[1,9],[9,9]] b._Board__masked[0][0]=6 self.assertFalse(b.flag(0,0)) @@ -90,10 +98,16 @@ class TestBoardClass(unittest.TestCase): def test_reveal(self): """ paljastuksen jälkeen näkyy laatat sellaisenaan """ - b = Board(2,2) + b = Board(width=2, height=2) b.reveal() t = b._Board__tiles v = b.get_view() for i in range(2): self.assertEqual(v[i],t[i]) -
\ No newline at end of file + + def test_get_level(self): + """ Testataan että nykyinen vaikeustaso palautuu oikein """ + b = Board(level=Level.INTERMEDIATE) + self.assertEqual(b.get_level(), Level.INTERMEDIATE) + b = Board(level=Level.INTERMEDIATE, width=25) + self.assertEqual(b.get_level(), None) |