

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Maze Class
incomplete
2: Maze Tests
incomplete
3: Break Entrance and Exit
incomplete
4: Break Walls
incomplete
This lesson's interactive features are locked, please to keep using them
It's often hard to unit test graphical apps. It's not impossible, but it can be tricky. One strategy is to try to encapsulate any "pure" logic in its own functions so you can just unit test that logic without the drawing.
import unittest
# assuming your `Maze` class is in a file called `maze.py`
from maze import Maze
class Tests(unittest.TestCase):
def test_maze_create_cells(self):
num_cols = 12
num_rows = 10
m1 = Maze(0, 0, num_rows, num_cols, 10, 10)
self.assertEqual(
len(m1._Maze__cells),
num_cols,
)
self.assertEqual(
len(m1._Maze__cells[0]),
num_rows,
)
Note the object._class__property syntax to access private properties outside the class. This is a result of Python's (feeble) attempt at hiding them through name mangling.
if __name__ == "__main__":
unittest.main()
python3 tests.py
Run and submit the CLI tests.