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
bfe5eb29
Commit
bfe5eb29
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
Test class for dijkstra class
parent
496af8a5
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
testDijkstra.py
+79
-0
79 additions, 0 deletions
testDijkstra.py
with
79 additions
and
0 deletions
testDijkstra.py
0 → 100644
+
79
−
0
View file @
bfe5eb29
import
unittest
from
dijkstra
import
Dijkstra
class
TestDijkstra
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
dijkstra_solver
=
Dijkstra
(
None
)
def
test_calculate_cost_empty
(
self
):
cell_type
=
0
cost
=
self
.
dijkstra_solver
.
calculate_cost
(
cell_type
)
self
.
assertEqual
(
cost
,
1
)
def
test_calculate_cost_wall
(
self
):
cell_type
=
1
cost
=
self
.
dijkstra_solver
.
calculate_cost
(
cell_type
)
self
.
assertEqual
(
cost
,
float
(
'
inf
'
))
def
test_calculate_cost_goal
(
self
):
cell_type
=
2
cost
=
self
.
dijkstra_solver
.
calculate_cost
(
cell_type
)
self
.
assertEqual
(
cost
,
100
)
def
test_calculate_cost_start
(
self
):
cell_type
=
3
cost
=
self
.
dijkstra_solver
.
calculate_cost
(
cell_type
)
self
.
assertEqual
(
cost
,
1
)
def
test_find_shortest_path_simple
(
self
):
start_position
=
(
0
,
0
)
goal_position
=
(
3
,
3
)
path
=
self
.
dijkstra_solver
.
find_shortest_path
(
start_position
,
goal_position
)
expected_path
=
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
3
,
0
),
(
3
,
1
),
(
3
,
2
),
(
3
,
3
)]
self
.
assertEqual
(
path
,
expected_path
)
def
test_find_shortest_path_blocked_goal
(
self
):
start_position
=
(
0
,
0
)
goal_position
=
(
3
,
3
)
path
=
self
.
dijkstra_solver
.
find_shortest_path
(
start_position
,
goal_position
)
expected_path
=
[]
self
.
assertEqual
(
path
,
expected_path
)
def
test_find_shortest_path_complex
(
self
):
start_position
=
(
0
,
0
)
goal_position
=
(
4
,
4
)
path
=
self
.
dijkstra_solver
.
find_shortest_path
(
start_position
,
goal_position
)
expected_path
=
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
2
,
1
),
(
2
,
2
),
(
2
,
3
),
(
3
,
3
),
(
4
,
3
),
(
4
,
4
)]
self
.
assertEqual
(
path
,
expected_path
)
def
test_get_neighbors_middle
(
self
):
maze
=
Dijkstra
([
[
0
,
0
,
0
,
1
],
[
1
,
1
,
0
,
0
],
[
0
,
1
,
0
,
1
],
[
0
,
0
,
0
,
0
]
])
cell
=
(
1
,
1
)
neighbors
=
maze
.
get_neighbors
(
cell
)
expected_neighbors
=
[(
0
,
1
),
(
2
,
1
),
(
1
,
0
),
(
1
,
2
)]
self
.
assertEqual
(
neighbors
,
expected_neighbors
)
def
test_get_neighbors_corner
(
self
):
maze
=
Dijkstra
([
[
0
,
0
,
0
,
1
],
[
1
,
1
,
0
,
0
],
[
0
,
1
,
0
,
1
],
[
0
,
0
,
0
,
0
]
])
cell
=
(
0
,
0
)
neighbors
=
maze
.
get_neighbors
(
cell
)
expected_neighbors
=
[(
1
,
0
),
(
0
,
1
)]
self
.
assertEqual
(
neighbors
,
expected_neighbors
)
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