Skip to content

Commit ef1482b

Browse files
committed
Added comprehensive tests for GameStructureChangedError (#700)
1 parent 65f6a12 commit ef1482b

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

tests/test_game.py

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,36 +159,123 @@ def test_game_dereference_invalid():
159159
_ = strategy.label
160160

161161

162-
def test_strategy_profile_invalidation_table():
163-
"""Test for invalidating mixed strategy profiles on tables when game changes."""
164-
g = gbt.Game.new_table([2, 2])
162+
def test_mixed_strategy_profile_game_structure_changed_no_tree():
163+
g = gbt.Game.from_arrays([[2, 2], [0, 0]], [[0, 0], [1, 1]])
165164
profiles = [g.mixed_strategy_profile(rational=b) for b in [False, True]]
166-
g.delete_strategy(g.players[0].strategies[0])
165+
g.outcomes[0][g.players[0]] = 3
167166
for profile in profiles:
168167
with pytest.raises(gbt.GameStructureChangedError):
169-
profile.payoff(g.players[0])
168+
profile.copy()
170169
with pytest.raises(gbt.GameStructureChangedError):
171170
profile.liap_value()
171+
with pytest.raises(gbt.GameStructureChangedError):
172+
profile.max_regret()
173+
with pytest.raises(gbt.GameStructureChangedError):
174+
# triggers error via __getitem__
175+
next(profile.mixed_strategies())
176+
with pytest.raises(gbt.GameStructureChangedError):
177+
profile.normalize()
178+
with pytest.raises(gbt.GameStructureChangedError):
179+
profile.payoff(g.players[0])
180+
with pytest.raises(gbt.GameStructureChangedError):
181+
profile.player_regret(g.players[0])
182+
with pytest.raises(gbt.GameStructureChangedError):
183+
profile.strategy_regret(g.strategies[0])
184+
with pytest.raises(gbt.GameStructureChangedError):
185+
profile.strategy_value(g.strategies[0])
186+
with pytest.raises(gbt.GameStructureChangedError):
187+
profile.strategy_value_deriv(g.strategies[0], g.strategies[1])
188+
with pytest.raises(gbt.GameStructureChangedError):
189+
# triggers error via __getitem__
190+
next(profile.__iter__())
191+
with pytest.raises(gbt.GameStructureChangedError):
192+
profile.__setitem__(g.strategies[0], 0)
193+
with pytest.raises(gbt.GameStructureChangedError):
194+
profile.__getitem__(g.strategies[0])
172195

173196

174-
def test_strategy_profile_invalidation_payoff():
175-
g = gbt.Game.from_arrays([[2, 2], [0, 0]], [[0, 0], [1, 1]])
197+
def test_mixed_strategy_profile_game_structure_changed_tree():
198+
g = games.read_from_file("basic_extensive_game.efg")
176199
profiles = [g.mixed_strategy_profile(rational=b) for b in [False, True]]
177-
g.outcomes[0][g.players[0]] = 3
200+
g.delete_action(g.players[0].infosets[0].actions[0])
178201
for profile in profiles:
179202
with pytest.raises(gbt.GameStructureChangedError):
180-
profile.payoff(g.players[0])
203+
profile.as_behavior()
204+
with pytest.raises(gbt.GameStructureChangedError):
205+
profile.copy()
181206
with pytest.raises(gbt.GameStructureChangedError):
182207
profile.liap_value()
208+
with pytest.raises(gbt.GameStructureChangedError):
209+
profile.max_regret()
210+
with pytest.raises(gbt.GameStructureChangedError):
211+
# triggers error via __getitem__
212+
next(profile.mixed_strategies())
213+
with pytest.raises(gbt.GameStructureChangedError):
214+
profile.normalize()
215+
with pytest.raises(gbt.GameStructureChangedError):
216+
profile.payoff(g.players[0])
217+
with pytest.raises(gbt.GameStructureChangedError):
218+
profile.player_regret(g.players[0])
219+
with pytest.raises(gbt.GameStructureChangedError):
220+
profile.strategy_regret(g.strategies[0])
221+
with pytest.raises(gbt.GameStructureChangedError):
222+
profile.strategy_value(g.strategies[0])
223+
with pytest.raises(gbt.GameStructureChangedError):
224+
profile.strategy_value_deriv(g.strategies[0], g.strategies[1])
225+
with pytest.raises(gbt.GameStructureChangedError):
226+
# triggers error via __getitem__
227+
next(profile.__iter__())
228+
with pytest.raises(gbt.GameStructureChangedError):
229+
profile.__setitem__(g.strategies[0], 0)
230+
with pytest.raises(gbt.GameStructureChangedError):
231+
profile.__getitem__(g.strategies[0])
183232

184233

185-
def test_behavior_profile_invalidation():
186-
"""Test for invalidating mixed strategy profiles on tables when game changes."""
234+
def test_mixed_behavior_profile_game_structure_changed():
187235
g = games.read_from_file("basic_extensive_game.efg")
188236
profiles = [g.mixed_behavior_profile(rational=b) for b in [False, True]]
189237
g.delete_action(g.players[0].infosets[0].actions[0])
190238
for profile in profiles:
239+
with pytest.raises(gbt.GameStructureChangedError):
240+
profile.action_regret(g.actions[0])
241+
with pytest.raises(gbt.GameStructureChangedError):
242+
profile.action_value(g.actions[0])
243+
with pytest.raises(gbt.GameStructureChangedError):
244+
profile.as_strategy()
245+
with pytest.raises(gbt.GameStructureChangedError):
246+
profile.belief(list(g.nodes)[0])
247+
with pytest.raises(gbt.GameStructureChangedError):
248+
profile.copy()
249+
with pytest.raises(gbt.GameStructureChangedError):
250+
profile.infoset_prob(g.infosets[0])
251+
with pytest.raises(gbt.GameStructureChangedError):
252+
profile.infoset_regret(g.infosets[0])
253+
with pytest.raises(gbt.GameStructureChangedError):
254+
profile.infoset_value(g.infosets[0])
255+
with pytest.raises(gbt.GameStructureChangedError):
256+
profile.is_defined_at(g.infosets[0])
257+
with pytest.raises(gbt.GameStructureChangedError):
258+
profile.liap_value()
259+
with pytest.raises(gbt.GameStructureChangedError):
260+
profile.max_regret()
261+
with pytest.raises(gbt.GameStructureChangedError):
262+
# triggers error via __getitem__
263+
next(profile.mixed_actions())
264+
with pytest.raises(gbt.GameStructureChangedError):
265+
# triggers error via __getitem__
266+
next(profile.mixed_behaviors())
267+
with pytest.raises(gbt.GameStructureChangedError):
268+
profile.node_value(g.players[0], g.root)
269+
with pytest.raises(gbt.GameStructureChangedError):
270+
profile.normalize()
191271
with pytest.raises(gbt.GameStructureChangedError):
192272
profile.payoff(g.players[0])
193273
with pytest.raises(gbt.GameStructureChangedError):
194-
profile.agent_liap_value()
274+
profile.realiz_prob(g.root)
275+
with pytest.raises(gbt.GameStructureChangedError):
276+
# triggers error via __getitem__
277+
next(profile.__iter__())
278+
with pytest.raises(gbt.GameStructureChangedError):
279+
profile.__setitem__(g.infosets[0].actions[0], 0)
280+
with pytest.raises(gbt.GameStructureChangedError):
281+
profile.__getitem__(g.infosets[0])

0 commit comments

Comments
 (0)