summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/board.py12
-rw-r--r--doc/muistilista.txt4
-rw-r--r--tests/test_board.py49
3 files changed, 56 insertions, 9 deletions
diff --git a/board/board.py b/board/board.py
index 069b568..22885c7 100644
--- a/board/board.py
+++ b/board/board.py
@@ -93,8 +93,12 @@ class Board():
""" tarkistaa onko peli voitettu """
for y in range(self.size):
for x in range(self.size):
- if self.tiles[x][y] != 9 and self.masked[x][y]:
- return False
+ if self.tiles[x][y] == 9:
+ if not self.masked[x][y]:
+ return False
+ else:
+ if self.masked[x][y]:
+ return False
return True
@@ -123,10 +127,6 @@ class Board():
print("Koordinaatit on pelilaudan ulkopuolella", file=stderr)
return False
- if self.masked[x][y] == 0:
- print("Ei voi liputtaa avattua ruutua", file=stderr)
- return False
-
match self.masked[x][y]:
case 0:
print("Ei voi liputtaa avattua ruutua", file=stderr)
diff --git a/doc/muistilista.txt b/doc/muistilista.txt
index 19e5778..6ee2281 100644
--- a/doc/muistilista.txt
+++ b/doc/muistilista.txt
@@ -1,7 +1,7 @@
MUISTILISTA!
Generoi haarakattavuusraportti:
-poetry run python3 -m coverage run --branch -m pytest && poetry run python3 -m coverage html && firefox htmlcov/index.html
+poetry run python3 -m coverage run --branch -m pytest -v && poetry run python3 -m coverage html && firefox htmlcov/index.html
Linttaus
-poetry run python3 -m pylint -v . \ No newline at end of file
+poetry run python3 -m pylint -v .
diff --git a/tests/test_board.py b/tests/test_board.py
index 9acc39f..0688005 100644
--- a/tests/test_board.py
+++ b/tests/test_board.py
@@ -32,4 +32,51 @@ class TestBoardClass(unittest.TestCase):
self.assertEqual(v[i],t[i])
self.assertFalse(b.make_guess(2,2))
- \ No newline at end of file
+
+ def test_is_winning(self):
+ """ toimiiko voittotilanteen tunnistus """
+ b = Board(2)
+ b.tiles=[[1,9],[9,9]]
+ b.masked=[[10,10],[10,10]]
+ self.assertFalse(b.is_winning())
+ b.masked=[[0,10],[10,10]]
+ self.assertTrue(b.is_winning())
+ b.masked=[[0,0],[10,10]]
+ self.assertFalse(b.is_winning())
+
+ def test_error_conditions_in_make_guess(self):
+ """ ruudun avaus alueen ulkopuolelta tai avatussa ruudussa ei onnistu"""
+ b = Board(2)
+ b.tiles=[[1,9],[9,9]]
+ self.assertFalse(b.make_guess(2,2))
+ self.assertTrue(b.make_guess(0,0))
+ self.assertFalse(b.make_guess(0,0))
+
+ def test_get_mask(self):
+ """ maski annetaan oikein """
+ b = Board(2)
+ b.tiles=[[1,9],[9,9]]
+ self.assertEqual(b.get_mask(0,0), 10)
+
+ def test_flag_tile(self):
+ """ ruudun liputus toimii """
+ b = Board(2)
+ b.tiles=[[1,9],[9,9]]
+ self.assertEqual(b.get_mask(0,0), 10)
+ self.assertTrue(b.flag_tile(0,0))
+ self.assertEqual(b.get_mask(0,0), 11)
+ self.assertTrue(b.flag_tile(0,0))
+ self.assertEqual(b.get_mask(0,0), 12)
+ self.assertTrue(b.flag_tile(0,0))
+ self.assertEqual(b.get_mask(0,0), 10)
+
+ def test_flaf_tile_error_conditions(self):
+ """ liputus ei onnistu jos avattu, alueen ulkopuolella, outo arvo """
+ b = Board(2)
+ b.tiles=[[1,9],[9,9]]
+ b.masked[0][0]=14
+ self.assertFalse(b.flag_tile(0,0))
+ b.masked[0][0]=0
+ self.assertFalse(b.flag_tile(0,0))
+ self.assertFalse(b.flag_tile(2,2))
+ \ No newline at end of file