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
e2637249
Commit
e2637249
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
Created test class for minmax class
parent
3802cb29
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
testMinMax.py
+112
-0
112 additions, 0 deletions
testMinMax.py
with
112 additions
and
0 deletions
testMinMax.py
0 → 100644
+
112
−
0
View file @
e2637249
import
unittest
from
minmax
import
MinMax
class
TestMinMax
(
unittest
.
TestCase
):
def
test_get_valid_moves_middle
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
player_position
=
(
1
,
1
)
valid_moves
=
minmax
.
get_valid_moves
(
player_position
)
expected_moves
=
[(
0
,
1
),
(
2
,
1
),
(
1
,
0
),
(
1
,
2
)]
self
.
assertEqual
(
valid_moves
,
expected_moves
)
def
test_get_valid_moves_corner
(
self
):
maze
=
[[
0
,
1
,
0
],
[
1
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
player_position
=
(
0
,
0
)
valid_moves
=
minmax
.
get_valid_moves
(
player_position
)
expected_moves
=
[(
1
,
0
),
(
0
,
1
)]
self
.
assertEqual
(
valid_moves
,
expected_moves
)
def
test_valid_move
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
valid_position
=
(
1
,
0
)
self
.
assertTrue
(
minmax
.
is_valid_move
(
valid_position
))
def
test_invalid_move_wall
(
self
):
maze
=
[[
0
,
1
,
0
],
[
1
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
wall_position
=
(
0
,
1
)
self
.
assertFalse
(
minmax
.
is_valid_move
(
wall_position
))
def
test_invalid_move_outside
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
outside_position
=
(
3
,
0
)
self
.
assertFalse
(
minmax
.
is_valid_move
(
outside_position
))
def
test_minmax
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax
=
MinMax
(
maze
)
player_position
=
(
0
,
0
)
enemy_position
=
(
2
,
2
)
depth
=
3
alpha
=
float
(
'
-inf
'
)
beta
=
float
(
'
inf
'
)
maximizing_player
=
True
result
=
minmax
.
minmax
(
player_position
,
enemy_position
,
depth
,
alpha
,
beta
,
maximizing_player
)
self
.
assertIsInstance
(
result
,
int
)
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
player_position
=
(
0
,
0
)
enemy_position
=
(
2
,
2
)
depth
=
1
result
=
minmax
.
minmax
(
player_position
,
enemy_position
,
depth
,
float
(
'
-inf
'
),
float
(
'
inf
'
),
maximizing_player
)
print
(
"
Result:
"
,
result
)
def
test_evaluate
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax_object
=
MinMax
(
maze
)
print
(
"
Testing the evaluate method...
"
)
player_position
=
(
1
,
1
)
enemy_position
=
(
1
,
1
)
evaluation_result
=
minmax_object
.
evaluate
(
player_position
,
enemy_position
)
print
(
"
Evaluation result when player and enemy are at the same position:
"
,
evaluation_result
)
player_position
=
(
2
,
2
)
enemy_position
=
(
1
,
1
)
evaluation_result
=
minmax_object
.
evaluate
(
player_position
,
enemy_position
)
print
(
"
Evaluation result when player is closer to the goal than the enemy:
"
,
evaluation_result
)
player_position
=
(
1
,
1
)
enemy_position
=
(
2
,
2
)
evaluation_result
=
minmax_object
.
evaluate
(
player_position
,
enemy_position
)
print
(
"
Evaluation result when enemy is closer to the goal than the player:
"
,
evaluation_result
)
def
test_game_over
(
self
):
maze
=
[[
0
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
0
]]
minmax_object
=
MinMax
(
maze
)
print
(
"
Testing the game_over method...
"
)
game_over_result
=
minmax_object
.
game_over
()
print
(
"
Game over result when the game is not over:
"
,
game_over_result
)
game_over_result
=
minmax_object
.
game_over
()
print
(
"
Game over result when the game is over:
"
,
game_over_result
)
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