Skip to content

Commit

Permalink
Test the initialisation of a mixed behavior profile on the creation f…
Browse files Browse the repository at this point in the history
…or incorrect input data
  • Loading branch information
Konstantinos Varsos committed Jan 23, 2024
1 parent 030dc13 commit 4158424
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions tests/test_behav.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,58 @@ def test_specific_profile(game: gbt.Game, rational_flag: bool, data: float):
for each player over his actions.
"""
profile = game.mixed_behavior_profile(rational=rational_flag, data=data)
for p in range(len(game.players)):
assert profile[game.players[p]] == data[p]
for (player, behavior) in zip(game.players, data):
assert profile[player] == behavior


@pytest.mark.parametrize(
"game,rational_flag,data",
[(games.create_mixed_behav_game(), True,
[[[0, 1, 0]], [[1, 0]], [[1, 0]]]),
(games.create_mixed_behav_game(), True,
[[[0, 1]], [[1, 0]], [[1, 0]], [[0, 1]]]),
(games.create_complicated_extensive_game(), True,
[[[1/5, 4/5], [3/5, 2/5]], [[1/4, 3/4], [1/4, 3/4]]]),
(games.create_el_farol_bar_game(), True,
[[4/9, 5/9], [0], [1/2, 1/2], [11/12, 1/12], [1/2, 1/2]]),
(games.create_el_farol_bar_game(), True,
[[1/2, 1/2]]),
(games.create_mixed_behav_game(), False,
[[[0, 1, 0]], [[1, 0]], [[1, 0]]]),
(games.create_mixed_behav_game(), False,
[[[0, 1]], [[1, 0]], [[1, 0]], [[0, 1]]]),
(games.create_complicated_extensive_game(), False,
[[[1/5, 4/5], [3/5, 2/5]], [[1/4, 3/4], [1/4, 3/4]]]),
(games.create_el_farol_bar_game(), False,
[[4/9, 5/9], [0], [1/2, 1/2], [11/12, 1/12], [1/2, 1/2]]),
(games.create_el_farol_bar_game(), False,
[[1/2, 1/2]])
]
)
def test_profile_data_error(game: gbt.Game, rational_flag: bool, data: float):
"""Test to ensure a pygambit.ValueError is raised when the data do not
match with the number of players, the number of the infosets, and the
number of actions per infoset.
"""
with pytest.raises(ValueError):
game.mixed_behavior_profile(rational=rational_flag,data=data)


@pytest.mark.parametrize(
"game,rational_flag,data",
[(games.create_coord_4x4_nfg(), True,
[["1/5", "2/5", "0/5", "2/5"], ["1/4", "3/8", "0/4", "3/8"]]),
(games.create_strategic_game(), True,
[["4/9", "5/9"], ["1/3", "2/3"]]),
(games.create_coord_4x4_nfg(), False,
[["1/5", "2/5", "0/5", "2/5"], ["1/4", "3/8", "0/4", "3/8"]]),
(games.create_strategic_game(), False,
[["4/9", "5/9"], ["1/3", "2/3"]])
]
)
def test_tree_representation_error(game: gbt.Game, rational_flag: bool, data: float):
"""Test to ensure a pygambit.UndefinedOperationError is raised when the game
to create a mixed behavior profile does not have a tree representation.
"""
with pytest.raises(gbt.UndefinedOperationError):
game.mixed_behavior_profile(rational=rational_flag,data=data)

0 comments on commit 4158424

Please sign in to comment.