Skip to content

Commit 4d26eea

Browse files
committed
UndefinedOperationError for calls to game.nodes and game.sort_infosets on non-trees
1 parent 80b86ad commit 4d26eea

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/pygambit/game.pxi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,16 @@ class Game:
742742
.. versionchanged:: 16.4
743743
Changed from a method ``nodes()`` to a property.
744744

745+
Raises
746+
------
747+
UndefinedOperationError
748+
If the game does not have a tree representation.
745749
"""
750+
if not self.is_tree:
751+
raise UndefinedOperationError(
752+
"Operation only defined for games with a tree representation"
753+
)
754+
746755
return GameNodes.wrap(self.game)
747756

748757
@property
@@ -1885,11 +1894,20 @@ class Game:
18851894

18861895
.. versionadded:: 16.4.0
18871896

1897+
Raises
1898+
------
1899+
UndefinedOperationError
1900+
If the game does not have a tree representation.
1901+
18881902
See also
18891903
--------
18901904
Player.infosets
18911905
Infoset.members
18921906
"""
1907+
if not self.is_tree:
1908+
raise UndefinedOperationError(
1909+
"Operation only defined for games with a tree representation"
1910+
)
18931911
self.game.deref().SortInfosets()
18941912

18951913
def add_player(self, label: str = "") -> Player:

tests/test_strategic.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ def test_strategic_game_root():
3737

3838
def test_strategic_game_nodes():
3939
game = gbt.Game.new_table([2, 2])
40-
assert list(game.nodes) == []
40+
with pytest.raises(gbt.UndefinedOperationError):
41+
_ = game.nodes
42+
43+
44+
def test_strategic_game_sort_infosets():
45+
game = gbt.Game.new_table([2, 2])
46+
with pytest.raises(gbt.UndefinedOperationError):
47+
_ = game.sort_infosets()
4148

4249

4350
def test_game_behav_profile_error():

0 commit comments

Comments
 (0)