Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
2
2425 - AICE1003 - Coursework Tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tsh2n14
2425 - AICE1003 - Coursework Tests
Compare revisions
5aceda097e01aba8b822d010e6497c93d9a3b5c9 to 731841eb609030346f6032ebd2b1daa6fa6f8a3f
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
tsh2n14/2425-AICE1003-CourseworkTests
Select target project
No results found
731841eb609030346f6032ebd2b1daa6fa6f8a3f
Select Git revision
Branches
main
Swap
Target
tsh2n14/2425-AICE1003-CourseworkTests
Select target project
tsh2n14/2425-AICE1003-CourseworkTests
1 result
5aceda097e01aba8b822d010e6497c93d9a3b5c9
Select Git revision
Branches
main
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Test Part 3
· f00afd11
tsh2n14
authored
5 months ago
f00afd11
Test Part 3
· 731841eb
tsh2n14
authored
5 months ago
731841eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
test_maze_runner.py
+127
-0
127 additions, 0 deletions
test_maze_runner.py
with
130 additions
and
0 deletions
README.md
View file @
731841eb
...
...
@@ -22,6 +22,9 @@ the test suit with more tests of your own.
`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.
-
`test_maze_runner`
: Some unit tests for testing the functionality of the
runner to explore the maze including sensing the walls and turning left,
right and to go straight.
-
More tests will be added as the coursework specification evolves.
...
...
This diff is collapsed.
Click to expand it.
test_maze_runner.py
0 → 100644
View file @
731841eb
"""
Created on Wed Nov 20 15:31:10 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
# type: ignore
from
runner
import
(
# type: ignore
create_runner
,
get_x
,
get_y
,
turn
,
get_orientation
,
)
def
test_runner_sense_walls
()
->
None
:
"""
A Unit test for :py:func:`~Maze.sense_walls`
Below is the test sequence:
1. Create a maze of size (11, 5).
2. Add a horizontal wall at (5, 2).
3. Add a runner at (5, 2) facing East
4. Assert that the runner sense no walls on the left and in the front, but
there is a wall on the right.
"""
maze
=
Maze
(
11
,
5
)
maze
.
add_horizontal_wall
(
5
,
2
)
runner
=
create_runner
(
5
,
2
,
"
E
"
)
assert
maze
.
sense_walls
(
runner
)
==
(
False
,
False
,
True
)
def
test_runner_go_straight
()
->
None
:
"""
A Unit test for :py:func:`~Maze.go_straight`
Below is the test sequence:
1. Create a maze of size (11, 5).
2. Add a horizontal wall at (5, 2).
3. Add a runner at (5, 2) facing East
4. Let the runner go straight
4. Assert that the runner is at (6, 2)
"""
maze
=
Maze
(
11
,
5
)
maze
.
add_horizontal_wall
(
5
,
2
)
runner
=
create_runner
(
5
,
2
,
"
E
"
)
runner
=
maze
.
go_straight
(
runner
)
assert
get_x
(
runner
)
==
6
assert
get_y
(
runner
)
==
2
def
test_move
()
->
None
:
"""
A Unit test for :py:func:`~Maze.move`
Below is the test sequence:
1. Create a maze of size (11, 5).
2. Add a horizontal wall at (5, 2).
3. Add a runner at (5, 2) facing South (toward the wall)
4. Let the runner moves and get the (new) runner and the actions.
5. Assert that the new runner is at one of four locations (5, 3), (5, 1),
(4, 2), (6, 2).
6. Create a test runner at (5, 2) facing South (toward the wall).
7. Replay the actions with the test runner. Rely on go_straight() method to
check if the runner hits the wall.
8. Assert that the test runner is the same as the runner after the replay.
"""
maze
=
Maze
(
11
,
5
)
maze
.
add_horizontal_wall
(
5
,
2
)
runner
=
create_runner
(
5
,
2
,
"
S
"
)
runner
,
actions
=
maze
.
move
(
runner
)
test_runner
=
create_runner
(
5
,
2
,
"
S
"
)
assert
(
get_x
(
runner
),
get_y
(
runner
))
in
[
(
5
,
3
),
(
5
,
1
),
(
4
,
2
),
(
6
,
2
),
],
f
"
Runner moves to far to
{
(
get_x
(
runner
),
get_y
(
runner
))
}
"
for
action
in
actions
:
if
action
==
"
L
"
:
test_runner
=
turn
(
test_runner
,
"
Left
"
)
elif
action
==
"
R
"
:
test_runner
=
turn
(
test_runner
,
"
Right
"
)
elif
action
==
"
F
"
:
test_runner
=
maze
.
go_straight
(
test_runner
)
else
:
assert
False
,
f
"
Unexpected action
{
action
}
"
assert
get_x
(
runner
)
==
get_x
(
test_runner
),
"
Incorrect x-coordinate for the runner
"
assert
get_y
(
runner
)
==
get_y
(
test_runner
),
"
Incorrect y-coordinate for the runner
"
assert
get_orientation
(
runner
)
==
get_orientation
(
test_runner
),
"
Incorrect orientation for the runner
"
def
test_explore
()
->
None
:
"""
The test for :py:func:~Maze.explore should be similar to test_move() above
(i.e., replaying the action to see if a test runner can follow the action to
get to the target destination. This will be left as an exercise for any keen
testers.
"""
pass
This diff is collapsed.
Click to expand it.