Skip to content

Commit 64cede6

Browse files
committed
Consolidate two subgame root tests into a single path-based verification
1 parent b4a665f commit 64cede6

1 file changed

Lines changed: 10 additions & 49 deletions

File tree

tests/test_node.py

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -199,43 +199,8 @@ def test_node_own_prior_action_non_terminal(game_file, expected_node_data):
199199

200200

201201
# ==============================================================================
202-
# New Test Suite for the Subgame Root Checker
202+
# Test Suite for the Subgame Root Checker
203203
# ==============================================================================
204-
205-
@pytest.mark.parametrize("game, expected_result", [
206-
# Games without Absent-Mindedness for which the legacy method is known to be correct.
207-
(games.read_from_file("wichardt.efg"), {0}),
208-
(games.read_from_file("e02.efg"), {0, 2, 4}),
209-
(games.read_from_file("subgame-roots-finder-one-merge.efg"), {0, 2}),
210-
(
211-
games.read_from_file("subgame-roots-finder-multiple-roots-and-merge.efg"),
212-
{0, 1, 4, 7, 11, 13, 34}
213-
),
214-
(games.Centipede.get_test_data(N=5, m0=2, m1=7)[0], {0, 2, 4, 6, 8}),
215-
(gbt.Game.new_tree(), {}),
216-
(games.read_from_file("subgame-roots-finder-multiple-merges.efg"), {0, 2, 13, 15}),
217-
218-
# Games with Absent-Mindedness where the legacy method is known to fail.
219-
pytest.param(
220-
games.read_from_file("AM-subgames.efg"),
221-
{0, 2, 5, 8}, # The correct set of roots
222-
marks=pytest.mark.xfail(
223-
reason="Legacy method does not detect subgame roots that are members of AM-infosets."
224-
)
225-
),
226-
])
227-
def test_legacy_is_subgame_root_set(game: gbt.Game, expected_result: set):
228-
"""
229-
Tests the legacy `node.is_subgame_root` against an expected set of nodes.
230-
Includes both passing cases and games with Absent-Mindedness where it is expected to fail.
231-
"""
232-
list_nodes = list(game.nodes)
233-
expected_roots = {list_nodes[i] for i in expected_result}
234-
legacy_roots = {node for node in game.nodes if node.is_subgame_root}
235-
assert legacy_roots == expected_roots
236-
237-
238-
# NEW subgame finder algorithm
239204
@pytest.mark.parametrize("game, expected_paths_list", [
240205
# Empty game has no subgames
241206
(
@@ -323,21 +288,17 @@ def test_legacy_is_subgame_root_set(game: gbt.Game, expected_result: set):
323288
]
324289
),
325290
])
326-
def test_new_subgame_root_method_paths(game: gbt.Game, expected_paths_list: list):
291+
def test_subgame_root_consistency(game: gbt.Game, expected_paths_list: list):
327292
"""
328-
Tests `game.subgame_root()` by comparing the paths of the identified root nodes
329-
against the expected paths.
293+
Tests `game.subgame_root` and `node.is_subgame_root` for consistency and correctness
294+
by comparing the paths of the identified root nodes against the expected paths.
330295
"""
331-
actual_root_nodes = {
332-
game.subgame_root(infoset)
333-
for infoset in game.infosets
334-
if not infoset.is_chance
335-
}
336-
337-
actual_paths = [
338-
_get_path_of_action_labels(node)
339-
for node in actual_root_nodes
340-
]
296+
roots_from_lookup = {game.subgame_root(infoset) for infoset in game.infosets}
297+
roots_from_property = {node for node in game.nodes if node.is_subgame_root}
298+
299+
assert roots_from_lookup == roots_from_property
300+
301+
actual_paths = [_get_path_of_action_labels(node) for node in roots_from_lookup]
341302

342303
assert sorted(actual_paths) == sorted(expected_paths_list)
343304

0 commit comments

Comments
 (0)