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
Commits
f00afd11
Commit
f00afd11
authored
6 months ago
by
tsh2n14
Browse files
Options
Downloads
Patches
Plain Diff
Test Part 3
parent
5aceda09
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_maze_runner.py
+127
-0
127 additions, 0 deletions
test_maze_runner.py
with
127 additions
and
0 deletions
test_maze_runner.py
0 → 100644
+
127
−
0
View file @
f00afd11
"""
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.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment