add tests to test Cell exceptions
This commit is contained in:
parent
2d1124cee1
commit
79d9727273
2 changed files with 45 additions and 3 deletions
2
cell.py
2
cell.py
|
@ -29,7 +29,7 @@ class Cell:
|
||||||
TOP_WALL = 0
|
TOP_WALL = 0
|
||||||
BOTTOM_WALL = 1
|
BOTTOM_WALL = 1
|
||||||
LEFT_WALL = 2
|
LEFT_WALL = 2
|
||||||
RIGHT_WALL = 4
|
RIGHT_WALL = 3
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
46
tests.py
46
tests.py
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from maze import Maze
|
import cell
|
||||||
from cell import Cell
|
from cell import Cell
|
||||||
|
from maze import Maze
|
||||||
|
|
||||||
|
|
||||||
class Tests(unittest.TestCase):
|
class Tests(unittest.TestCase):
|
||||||
|
@ -57,7 +58,48 @@ class Tests(unittest.TestCase):
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
self.assertFalse(maze._cells[0][0].wall_exists(Cell.TOP_WALL))
|
self.assertFalse(maze._cells[0][0].wall_exists(Cell.TOP_WALL))
|
||||||
self.assertFalse(maze._cells[number_of_cell_rows - 1][number_of_cells_per_row - 1].wall_exists(Cell.BOTTOM_WALL))
|
self.assertFalse(
|
||||||
|
maze._cells[number_of_cell_rows - 1]
|
||||||
|
[number_of_cells_per_row - 1].wall_exists(Cell.BOTTOM_WALL)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_invalid_cell_exception(self):
|
||||||
|
"""
|
||||||
|
test_invalid_cell_exception tests the exception for when an attempt
|
||||||
|
is made to create an invalid Cell.
|
||||||
|
"""
|
||||||
|
cases = [
|
||||||
|
{"x1": 30, "y1": 50, "x2": 20, "y2": 100},
|
||||||
|
{"x1": 30, "y1": 50, "x2": 40, "y2": 25},
|
||||||
|
]
|
||||||
|
|
||||||
|
for case in cases:
|
||||||
|
with self.assertRaises(cell.CellInvalidError):
|
||||||
|
_ = Cell(
|
||||||
|
x1=case["x1"],
|
||||||
|
y1=case["y1"],
|
||||||
|
x2=case["x2"],
|
||||||
|
y2=case["y2"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_cell_too_small_exception(self):
|
||||||
|
"""
|
||||||
|
test_cell_too_small_exception tests the excpetion for when an attempt
|
||||||
|
is made to create a Cell that's too small.
|
||||||
|
"""
|
||||||
|
cases = [
|
||||||
|
{"x1": 1, "y1": 50, "x2": 2, "y2": 100},
|
||||||
|
{"x1": 30, "y1": 25, "x2": 40, "y2": 25},
|
||||||
|
]
|
||||||
|
|
||||||
|
for case in cases:
|
||||||
|
with self.assertRaises(cell.CellTooSmallError):
|
||||||
|
_ = Cell(
|
||||||
|
x1=case["x1"],
|
||||||
|
y1=case["y1"],
|
||||||
|
x2=case["x2"],
|
||||||
|
y2=case["y2"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue