Skip to content

Commit

Permalink
Significant extension and improvement of test_behav.py, in particular…
Browse files Browse the repository at this point in the history
… to cover the new indexing of behav profiles, and to check profile order consistency for payoff-related calculations
  • Loading branch information
rahulsavani authored and tturocy committed Jan 16, 2024
1 parent b42bd10 commit aaf56a7
Show file tree
Hide file tree
Showing 6 changed files with 731 additions and 201 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
- Improved test suite for mixed strategy profiles (#374)
- Test suite for pygambit moved from src/pygambit/tests/ to tests/
- Improved __repr__ methods in pygambit for game-related classes

- Further extension of test suite for mixed behavior profiles to cover new indexing and profile
order consistency for payoff-related calculations

## [16.1.1] - 2024-01-10

Expand Down
2 changes: 1 addition & 1 deletion src/pygambit/behavmixed.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class MixedBehaviorProfile:
The player to get the payoff for. If a string is passed, the
player is determined by finding the player with that label, if any.
node : Node or str
The node to get the payoff att. If a string is passed, the
The node to get the payoff at. If a string is passed, the
node is determined by finding the node with that label, if any.

Raises
Expand Down
10 changes: 5 additions & 5 deletions tests/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ def create_mixed_behav_game() -> gbt.Game:
return read_from_file("mixed_behavior_game.efg")


def create_complicated_extensive_game() -> gbt.Game:
def create_myerson_2_card_poker() -> gbt.Game:
"""
Returns
-------
Game
Two-player extensive poker game with a chance move with two moves, then player 1 can raise
or fold; after raising player 2 is in an infoset with two nodes and can choose to meet or
pass
Myerson 2-card poker: Two-player extensive poker game with a chance move with two moves,
then player 1 can raise or fold; after raising player 2 is in an infoset with two nodes
and can choose to meet or pass
"""
return read_from_file("complicated_extensive_game.efg")
return read_from_file("myerson_2_card_poker.efg")


def create_strategic_game() -> gbt.Game:
Expand Down
28 changes: 14 additions & 14 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.mark.parametrize(
"game,label",
[(games.read_from_file("complicated_extensive_game.efg"), "random label")]
[(games.create_myerson_2_card_poker(), "random label")]
)
def test_set_action_label(game: gbt.Game, label: str):
game.root.infoset.actions[0].label = label
Expand All @@ -15,9 +15,9 @@ def test_set_action_label(game: gbt.Game, label: str):

@pytest.mark.parametrize(
"game,inprobs,outprobs",
[(games.read_from_file("complicated_extensive_game.efg"),
[(games.create_myerson_2_card_poker(),
[0.75, 0.25], [0.75, 0.25]),
(games.read_from_file("complicated_extensive_game.efg"),
(games.create_myerson_2_card_poker(),
["16/17", "1/17"], [gbt.Rational("16/17"), gbt.Rational("1/17")])]
)
def test_set_chance_valid_probability(game: gbt.Game, inprobs: list, outprobs: list):
Expand All @@ -28,9 +28,9 @@ def test_set_chance_valid_probability(game: gbt.Game, inprobs: list, outprobs: l

@pytest.mark.parametrize(
"game,inprobs",
[(games.read_from_file("complicated_extensive_game.efg"), [0.75, -0.10]),
(games.read_from_file("complicated_extensive_game.efg"), [0.75, 0.40]),
(games.read_from_file("complicated_extensive_game.efg"), ["foo", "bar"])]
[(games.create_myerson_2_card_poker(), [0.75, -0.10]),
(games.create_myerson_2_card_poker(), [0.75, 0.40]),
(games.create_myerson_2_card_poker(), ["foo", "bar"])]
)
def test_set_chance_improper_probability(game: gbt.Game, inprobs: list):
with pytest.raises(ValueError):
Expand All @@ -39,8 +39,8 @@ def test_set_chance_improper_probability(game: gbt.Game, inprobs: list):

@pytest.mark.parametrize(
"game,inprobs",
[(games.read_from_file("complicated_extensive_game.efg"), [0.25, 0.75, 0.25]),
(games.read_from_file("complicated_extensive_game.efg"), [1.00])]
[(games.create_myerson_2_card_poker(), [0.25, 0.75, 0.25]),
(games.create_myerson_2_card_poker(), [1.00])]
)
def test_set_chance_bad_dimension(game: gbt.Game, inprobs: list):
with pytest.raises(IndexError):
Expand All @@ -49,7 +49,7 @@ def test_set_chance_bad_dimension(game: gbt.Game, inprobs: list):

@pytest.mark.parametrize(
"game",
[games.read_from_file("complicated_extensive_game.efg")]
[games.create_myerson_2_card_poker()]
)
def test_set_chance_personal(game: gbt.Game):
with pytest.raises(gbt.UndefinedOperationError):
Expand All @@ -58,7 +58,7 @@ def test_set_chance_personal(game: gbt.Game):

@pytest.mark.parametrize(
"game",
[games.read_from_file("complicated_extensive_game.efg")]
[games.create_myerson_2_card_poker()]
)
def test_action_precedes(game: gbt.Game):
child = game.root.children[0]
Expand All @@ -68,7 +68,7 @@ def test_action_precedes(game: gbt.Game):

@pytest.mark.parametrize(
"game",
[games.read_from_file("complicated_extensive_game.efg")]
[games.create_myerson_2_card_poker()]
)
def test_action_precedes_nonnode(game: gbt.Game):
with pytest.raises(TypeError):
Expand All @@ -77,7 +77,7 @@ def test_action_precedes_nonnode(game: gbt.Game):

@pytest.mark.parametrize(
"game",
[games.read_from_file("complicated_extensive_game.efg")]
[games.create_myerson_2_card_poker()]
)
def test_action_delete_personal(game: gbt.Game):
node = game.players[0].infosets[0].members[0]
Expand All @@ -89,7 +89,7 @@ def test_action_delete_personal(game: gbt.Game):

@pytest.mark.parametrize(
"game",
[games.read_from_file("complicated_extensive_game.efg")]
[games.create_myerson_2_card_poker()]
)
def test_action_delete_last(game: gbt.Game):
node = game.players[0].infosets[0].members[0]
Expand All @@ -102,7 +102,7 @@ def test_action_delete_last(game: gbt.Game):
@pytest.mark.parametrize(
"game",
[games.read_from_file("chance_root_3_moves_only_one_nonzero_prob.efg"),
games.read_from_file("complicated_extensive_game.efg"),
games.create_myerson_2_card_poker(),
games.read_from_file("chance_root_5_moves_no_nonterm_player_nodes.efg")]
)
def test_action_delete_chance(game: gbt.Game):
Expand Down

0 comments on commit aaf56a7

Please sign in to comment.