diff --git a/README.md b/README.md index bedb78cce3f9769bb50b45a5177249a4f4977b17..900c538148d9ad3d34de82f1f41d9129767a6cf5 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ the test suit with more tests of your own. - `test_runner.py`: Some unit tests for testing the functionality of `runner.py` including creating a runner, turn, and move the runner forward. + - `test_maze.py`: Some unit tests for testing the functionality of the `Maze` + class, including creating a maze, add horizontal and vertical walls. - More tests will be added as the coursework specification evolves. diff --git a/test_maze.py b/test_maze.py new file mode 100644 index 0000000000000000000000000000000000000000..a776474a685301640445e2ea1a6b94598b0580cd --- /dev/null +++ b/test_maze.py @@ -0,0 +1,79 @@ +""" +Created on Tue Nov 12 16:20:23 2024 +""" + +__author__ = "Son Hoang" +__copyright__ = "Copyright (c) 2024, University of Southampton" +__credits__ = ["Son Hoang"] +__licence__ = "MIT" +__version__ = "1.0" +__maintainer__ = "Son Hoang" +__email__ = "T.S.Hoang@soton.ac.uk" +__status__ = "Prototype" + +from maze import Maze + + +def test_constructor_get_dimensions() -> None: + """A Unit test for :py:func:`~maze.__init__` and + accessing the width and height properties. + + Below is the test sequence: + + 1. Create a maze of size (11, 5). + + 2. Assert the width (11) and height (5) of the newly created maze. + created runner. + """ + maze = Maze(11, 5) + assert maze.width == 11 + assert maze.height == 5 + + +def test_constructor_get_walls() -> None: + """A Unit test for :py:func:`~Maze.__init__` and + :py:func:`~Maze.get_walls` + + Below is the test sequence: + + 1. Create a maze of size (11, 5). + + 2. Assert that there are no walls at the (4, 2)-coordinate. + """ + maze = Maze(11, 5) + assert maze.get_walls(4, 2) == (False, False, False, False) + + +def test_add_horizontal_wall() -> None: + """A Unit test for :py:func:`~Maze.add_horizontal_wall` and + :py:func:`~Maze.get_walls` + + Below is the test sequence: + + 1. Create a maze of size (11, 5). + + 2. Add a horizontal wall at (5, 2). + + 4. Assert that there are no walls at the (5, 2)-coordinate, except the South. + """ + maze = Maze(11, 5) + maze.add_horizontal_wall(5, 2) + + assert maze.get_walls(5, 2) == (False, False, True, False) + + +def test_add_vertical_wall() -> None: + """A Unit test for :py:func:`~Maze.add_vertical_wall` and + :py:func:`~Maze.get_walls` + + Below is the test sequence: + + 1. Create a maze of size (11, 5). + + 2. Add a vertical wall at (2, 4). + + 3. Assert that there are no walls at the (4, 2)-coordinate, except the West. + """ + maze = Maze(11, 5) + maze.add_vertical_wall(2, 4) + assert maze.get_walls(4, 2) == (False, False, False, True) diff --git a/test_runner.py b/test_runner.py index d89d57521257a2125e17338c49acf9fadb2ffbf8..839bc9d0e9f0734e9f9ef8a58d60827bb1105fa6 100644 --- a/test_runner.py +++ b/test_runner.py @@ -1,3 +1,17 @@ +""" +Created on Fri Oct 25 12:07:22 2024 +""" + +__author__ = "Son Hoang" +__copyright__ = "Copyright (c) 2024, University of Southampton" +__credits__ = ["Son Hoang"] +__licence__ = "MIT" +__version__ = "1.0" +__maintainer__ = "Son Hoang" +__email__ = "T.S.Hoang@soton.ac.uk" +__status__ = "Prototype" + + from runner import ( # type: ignore create_runner, get_orientation, @@ -9,7 +23,15 @@ from runner import ( # type: ignore def test_create_runner() -> None: - """A Unit test for :func:runner.create_runner function""" + """A Unit test for :py:func:`~runner.create_runner` + + Below is the test sequence: + + 1. Create a runner at position (1,2), facing South. + + 2. Assert the x, y positions (1, 2), and the orientation ("S") of the newly + created runner. + """ runner = create_runner(1, 2, "S") assert get_x(runner) == 1 assert get_y(runner) == 2 @@ -17,7 +39,16 @@ def test_create_runner() -> None: def test_turn() -> None: - """A Unit test for :func:runner.turn function""" + """A Unit test for :py:func:`~runner.turn` + + Below is the test sequence: + + 1. Create a runner at position (1,2), facing South. + + 2. Let the runner turn to the Left. + + 3. Assert the x, y positions (1, 2), and the orientation ("E") of the runner. + """ runner = create_runner(1, 2, "S") runner = turn(runner, "Left") assert get_x(runner) == 1 @@ -26,7 +57,16 @@ def test_turn() -> None: def test_forward() -> None: - """A Unit test for :func:runner.forward function""" + """A Unit test for :py:func:`~runner.forward` + + Below is the test sequence: + + 1. Create a runner at position (1,2), facing South. + + 2. Let the runner more forward. + + 3. Assert the x, y positions (1, 1), and the orientation ("S") of the runner. + """ runner = create_runner(1, 2, "S") runner = forward(runner) assert get_x(runner) == 1