Skip to content

Commit 9db6599

Browse files
committed
add tests for coverage
1 parent 9a02145 commit 9db6599

5 files changed

Lines changed: 45 additions & 4 deletions

File tree

jupyddl/automated_planner.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ def available_actions(self, state):
6969
except (RuntimeError, TypeError, NameError):
7070
self.logger.warning("Runtime, Type or Name error occured when fetching available action from state" + str(state))
7171
return []
72-
else:
73-
self.logger.warning("An error occured when fetching available action from state" + str(state))
74-
return []
7572

7673
def satisfies(self, asserted_state, state):
7774
return self.pddl.satisfy(asserted_state, state, self.domain)[0]
@@ -144,7 +141,7 @@ def astar_best_first_search(self, heuristic_key="basic/goal_count"):
144141
heuristic = DeleteRelaxationHeuristic(self, heuristic_key)
145142
else:
146143
logging.fatal("Not yet implemented")
147-
exit()
144+
return [], 0, 0
148145
astar = AStarBestFirstSearch(self, heuristic.compute)
149146
last_node, total_time, opened_nodes = astar.search()
150147
path = self.__retrace_path(last_node)

tests/test_basic_astar.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ def test_astar_path_length():
3434
)
3535
path, _, _ = apla.astar_best_first_search()
3636
assert len(path) > 0
37+
38+
def test_astar_path_no_path():
39+
apla = AutomatedPlanner(
40+
"pddl-examples/vehicle/domain.pddl", "pddl-examples/vehicle/problem.pddl"
41+
)
42+
path, _, _ = apla.astar_best_first_search()
43+
assert len(path) == 0
44+
45+
def test_astar_path_no_heuristic():
46+
apla = AutomatedPlanner(
47+
"pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl"
48+
)
49+
p, t, c = apla.astar_best_first_search(heuristic_key="idontexist")
50+
assert not p and not t and not c

tests/test_basic_search.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,28 @@ def test_search_astar_delete_relaxation():
5757
res = astar.search() # Goal, computation_time, opened_nodes(in this order)
5858
assert res[1] != 0 # Assert that it took time to compute
5959
assert res[-1] > 0 # Assert that it visited at least one node
60+
61+
def test_search_getter_costs():
62+
apla = AutomatedPlanner(
63+
"pddl-examples/tsp/domain.pddl", "pddl-examples/tsp/problem.pddl"
64+
)
65+
bfs = BreadthFirstSearch(apla)
66+
path, _, _ = bfs.search() # Path, computation time, opened nodes
67+
plan = apla.get_actions_from_path(path)
68+
state_plan = apla.get_state_def_from_path(path)
69+
70+
assert path and plan and state_plan
71+
72+
def test_search_getter_no_costs():
73+
apla = AutomatedPlanner(
74+
"pddl-examples/cargo/domain.pddl", "pddl-examples/cargo/problem.pddl"
75+
)
76+
bfs = BreadthFirstSearch(apla)
77+
path, _, _ = bfs.search() # Path, computation time, opened nodes
78+
plan = apla.get_actions_from_path(path)
79+
state_plan = apla.get_state_def_from_path(path)
80+
81+
assert path and plan and state_plan
82+
83+
84+

tests/test_heuristics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_zero_heuristic():
1818
apla = AutomatedPlanner(
1919
"pddl-examples/dinner/domain.pddl", "pddl-examples/dinner/problem.pddl"
2020
)
21+
apla.display_available_heuristics()
2122
heuristic = hs.BasicHeuristic(apla, "basic/zero")
2223
h = heuristic.compute(apla.initial_state)
2324
assert h == 0
@@ -27,6 +28,7 @@ def test_goal_count_heuristic():
2728
apla = AutomatedPlanner(
2829
"pddl-examples/dinner/domain.pddl", "pddl-examples/dinner/problem.pddl"
2930
)
31+
apla.display_available_heuristics()
3032
heuristic = hs.BasicHeuristic(apla, "basic/goal_count")
3133
h = heuristic.compute(apla.initial_state)
3234
assert h != 0
@@ -36,6 +38,7 @@ def test_delete_relaxation_add_heuristic():
3638
apla = AutomatedPlanner(
3739
"pddl-examples/tsp/domain.pddl", "pddl-examples/tsp/problem.pddl"
3840
)
41+
apla.display_available_heuristics()
3942
heuristic = hs.DeleteRelaxationHeuristic(apla, "delete_relaxation/h_max")
4043
h = heuristic.compute(apla.initial_state)
4144
assert h != 0

tests/test_setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_setup():
2+
import setup

0 commit comments

Comments
 (0)