Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Abdi Danny (2019) ZHAC232
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Commits
e1971210
Commit
e1971210
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
Created test class for aStar class
parent
e2637249
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
Single and Multi-Agent Pathfinding in Maze games
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testAStar.py
+68
-0
68 additions, 0 deletions
testAStar.py
with
68 additions
and
0 deletions
testAStar.py
0 → 100644
+
68
−
0
View file @
e1971210
import
unittest
from
aStar
import
AStar
class
TestAStar
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
maze
=
[
[
1
,
0
,
0
,
0
],
[
0
,
1
,
1
,
0
],
[
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
]
]
self
.
a_star_solver
=
AStar
(
self
.
maze
)
def
test_heuristic1
(
self
):
current_position
=
(
1
,
1
)
visited_corners
=
set
()
heuristic_result
=
self
.
a_star_solver
.
heuristic1
(
current_position
,
self
.
a_star_solver
.
corners
,
visited_corners
)
self
.
assertEqual
(
heuristic_result
,
3
)
current_position
=
(
2
,
2
)
visited_corners
=
set
()
heuristic_result
=
self
.
a_star_solver
.
heuristic1
(
current_position
,
self
.
a_star_solver
.
corners
,
visited_corners
)
self
.
assertEqual
(
heuristic_result
,
...)
def
test_heuristic2
(
self
):
current_position
=
(
1
,
1
)
visited_corners
=
set
()
heuristic_result
=
self
.
a_star_solver
.
heuristic2
(
current_position
,
self
.
a_star_solver
.
corners
,
visited_corners
)
self
.
assertEqual
(
heuristic_result
,
...)
current_position
=
(
2
,
2
)
visited_corners
=
set
()
heuristic_result
=
self
.
a_star_solver
.
heuristic2
(
current_position
,
self
.
a_star_solver
.
corners
,
visited_corners
)
self
.
assertEqual
(
heuristic_result
,
...)
def
test_all_corners_visited
(
self
):
corners
=
{(
1
,
1
),
(
2
,
2
),
(
3
,
3
)}
visited_corners
=
{(
1
,
1
),
(
2
,
2
)}
result
=
self
.
a_star_solver
.
all_corners_visited
(
corners
,
visited_corners
)
self
.
assertFalse
(
result
)
def
test_find_goal_position
(
self
):
maze_with_goal
=
...
goal_position
=
self
.
a_star_solver
.
find_goal_position
(
maze_with_goal
)
self
.
assertIsNotNone
(
goal_position
)
maze_without_goal
=
...
goal_position
=
self
.
a_star_solver
.
find_goal_position
(
maze_without_goal
)
self
.
assertIsNone
(
goal_position
)
def
test_find_shortest_path_with_valid_heuristic
(
self
):
def
valid_heuristic
(
current
,
corners
,
visited_corners
):
return
0
path
=
self
.
a_star_solver
.
find_shortest_path
(
valid_heuristic
)
self
.
assertIsNotNone
(
path
)
def
test_find_shortest_path_with_invalid_heuristic
(
self
):
def
invalid_heuristic
(
current
,
corners
,
visited_corners
):
return
None
path
=
self
.
a_star_solver
.
find_shortest_path
(
invalid_heuristic
)
self
.
assertIsNone
(
path
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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