Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
51a575be
Commit
51a575be
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for movement graph
parent
1ced66cc
No related branches found
No related tags found
1 merge request
!89
Resolve "simple pathfinding"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_utils.py
+79
-0
79 additions, 0 deletions
tests/test_utils.py
with
79 additions
and
0 deletions
tests/test_utils.py
+
79
−
0
View file @
51a575be
import
json
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
import
networkx
import
pytest
from
cooperative_cuisine.environment
import
Environment
from
cooperative_cuisine.state_representation
import
(
create_movement_graph
,
restrict_movement_graph
,
astar_heuristic
,
)
from
cooperative_cuisine.utils
import
(
from
cooperative_cuisine.utils
import
(
url_and_port_arguments
,
url_and_port_arguments
,
add_list_of_manager_ids_arguments
,
add_list_of_manager_ids_arguments
,
...
@@ -9,6 +19,7 @@ from cooperative_cuisine.utils import (
...
@@ -9,6 +19,7 @@ from cooperative_cuisine.utils import (
create_layout_with_counters
,
create_layout_with_counters
,
setup_logging
,
setup_logging
,
)
)
from
tests.test_start
import
env_config
,
layout_empty_config
,
item_info
def
test_parser_gen
():
def
test_parser_gen
():
...
@@ -44,3 +55,71 @@ def test_layout_creation():
...
@@ -44,3 +55,71 @@ def test_layout_creation():
def
test_setup_logging
():
def
test_setup_logging
():
setup_logging
()
setup_logging
()
def
test_movement_graph
(
env_config
,
layout_empty_config
,
item_info
):
env
=
Environment
(
env_config
,
layout_empty_config
,
item_info
,
as_files
=
False
)
player_name
=
"
0
"
env
.
add_player
(
player_name
)
state_string
=
env
.
get_json_state
(
player_id
=
player_name
)
state
=
json
.
loads
(
state_string
)
graph_diag
=
create_movement_graph
(
state
,
diagonal
=
True
)
graph
=
create_movement_graph
(
json
.
loads
(
env
.
get_json_state
(
player_id
=
player_name
)),
diagonal
=
False
)
path
=
networkx
.
astar_path
(
graph
,
source
=
(
0
,
0
),
target
=
(
3
,
3
),
heuristic
=
astar_heuristic
,
)
assert
len
(
path
)
!=
0
,
"
No path found, but should have.
"
graph_restricted
=
restrict_movement_graph
(
graph_diag
,
[(
1
,
0
),
(
0
,
1
),
(
1
,
1
)])
with
pytest
.
raises
(
networkx
.
exception
.
NetworkXNoPath
)
as
e_info
:
path
=
networkx
.
astar_path
(
graph_restricted
,
source
=
(
0
,
0
),
target
=
(
3
,
3
),
heuristic
=
astar_heuristic
,
)
with
pytest
.
raises
(
networkx
.
exception
.
NodeNotFound
)
as
e_info
:
path
=
networkx
.
astar_path
(
graph_restricted
,
source
=
(
20
,
20
),
target
=
(
40
,
40
),
heuristic
=
astar_heuristic
,
)
assert
len
(
path
)
!=
0
,
"
No path found, but should have.
"
path
=
networkx
.
astar_path
(
restrict_movement_graph
(
graph
=
graph_diag
,
player_positions
=
[],
),
source
=
(
0
,
0
),
target
=
(
5
,
5
),
heuristic
=
astar_heuristic
,
)
assert
len
(
path
)
!=
0
graph_diag_restricted
=
restrict_movement_graph
(
graph_diag
,
[(
1
,
0
),
(
0
,
1
),
(
1
,
1
)]
)
with
pytest
.
raises
(
networkx
.
exception
.
NetworkXNoPath
)
as
e_info
:
_
=
networkx
.
astar_path
(
graph_diag_restricted
,
source
=
(
0
,
0
),
target
=
(
3
,
3
),
heuristic
=
astar_heuristic
,
)
with
pytest
.
raises
(
networkx
.
exception
.
NodeNotFound
)
as
e_info
:
_
=
networkx
.
astar_path
(
graph_diag
,
source
=
(
20
,
20
),
target
=
(
40
,
40
),
heuristic
=
astar_heuristic
,
)
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