Skip to content

Commit f6518ab

Browse files
committed
new tests for enumpure_solve in pure strategies and behaviors
1 parent d96f877 commit f6518ab

3 files changed

Lines changed: 107 additions & 12 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ max-line-length = 99
7676
[tool.pytest.ini_options]
7777
addopts = "--strict-markers"
7878
markers = [
79+
"nash_enumpure_strategy: tests of enumpure_solve in pure strategies",
80+
"nash_enumpure_agent: tests of enumpure_solve in pure behaviors",
7981
"nash_enummixed_strategy: tests of enummixed_solve in mixed strategies",
80-
"nash_enumpoly_behavior: tests of enumpoly_solve in behavior strategies",
82+
"nash_enumpoly_behavior: tests of enumpoly_solve in mixed behaviors",
8183
"nash_lcp_strategy: tests of lcp_solve in mixed strategies",
82-
"nash_lcp_behavior: tests of lcp_solve in behavior strategies",
84+
"nash_lcp_behavior: tests of lcp_solve in mixed behaviors",
8385
"nash_lp_strategy: tests of lp_solve in mixed strategies",
84-
"nash_lp_behavior: tests of lp_solve in behavior strategies",
86+
"nash_lp_behavior: tests of lp_solve in mixed behaviors",
8587
"nash: all tests of Nash equilibrium solvers",
8688
"slow: all time-consuming tests",
8789
]

tests/test_nash.py

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,110 @@
1717
TOL = 1e-13 # tolerance for floating point assertions
1818

1919

20-
def test_enumpure_strategy():
21-
"""Test calls of enumeration of pure strategies."""
22-
game = games.read_from_file("poker.efg")
23-
assert len(gbt.nash.enumpure_solve(game, use_strategic=True).equilibria) == 0
20+
@pytest.mark.nash
21+
@pytest.mark.nash_enumpure_strategy
22+
@pytest.mark.parametrize(
23+
"game,pure_strategy_prof_data",
24+
[
25+
# Zero-sum games
26+
(
27+
games.create_two_player_perfect_info_win_lose_efg(),
28+
[
29+
[[0, 0, 1, 0], [1, 0, 0]],
30+
[[0, 0, 1, 0], [0, 1, 0]],
31+
[[0, 0, 1, 0], [0, 0, 1]],
32+
]
33+
),
34+
(games.create_myerson_2_card_poker_efg(), []),
35+
# Non-zero-sum 2-player games
36+
(games.create_one_shot_trust_efg(), [[[0, 1], [0, 1]]]),
37+
(
38+
games.create_EFG_for_nxn_bimatrix_coordination_game(3),
39+
[
40+
[[1, 0, 0], [1, 0, 0]],
41+
[[0, 1, 0], [0, 1, 0]],
42+
[[0, 0, 1], [0, 0, 1]],
43+
],
44+
),
45+
(games.create_EFG_for_6x6_bimatrix_with_long_LH_paths_and_unique_eq(), []),
46+
# 3-player game
47+
(
48+
games.create_mixed_behav_game_efg(),
49+
[
50+
[[1, 0], [1, 0], [1, 0]],
51+
[[0, 1], [0, 1], [1, 0]],
52+
[[0, 1], [1, 0], [0, 1]],
53+
[[1, 0], [0, 1], [0, 1]],
54+
],
55+
),
56+
]
57+
)
58+
def test_enumpure_strategy(game: gbt.Game, pure_strategy_prof_data: list):
59+
"""Test calls of enumeration of pure strategy equilibria
2460
61+
Tests max regret being zero (internal consistency) and compares the computed sequence of
62+
pure strategy equilibria to a previosuly computed sequence (regression test)
63+
"""
64+
result = gbt.nash.enumpure_solve(game, use_strategic=True)
65+
assert len(result.equilibria) == len(pure_strategy_prof_data)
66+
for eq, exp in zip(result.equilibria, pure_strategy_prof_data):
67+
assert eq.max_regret() == 0
68+
expected = game.mixed_strategy_profile(rational=True, data=exp)
69+
assert eq == expected
2570

26-
def test_enumpure_agent():
27-
"""Test calls of enumeration of pure agent strategies."""
28-
game = games.read_from_file("poker.efg")
29-
assert len(gbt.nash.enumpure_solve(game, use_strategic=False).equilibria) == 0
71+
72+
@pytest.mark.nash
73+
@pytest.mark.nash_enumpure_agent
74+
@pytest.mark.parametrize(
75+
"game,pure_behav_prof_data",
76+
[
77+
# Zero-sum games
78+
(
79+
games.create_two_player_perfect_info_win_lose_efg(),
80+
[
81+
[[[1, 0], [1, 0]], [[0, 1], [1, 0]]],
82+
[[[0, 1], [1, 0]], [[1, 0], [1, 0]]],
83+
[[[0, 1], [1, 0]], [[1, 0], [0, 1]]],
84+
[[[0, 1], [1, 0]], [[0, 1], [1, 0]]],
85+
[[[0, 1], [1, 0]], [[0, 1], [0, 1]]]
86+
]
87+
),
88+
(games.create_myerson_2_card_poker_efg(), []),
89+
# Non-zero-sum 2-player games
90+
(games.create_one_shot_trust_efg(), [[[[0, 1]], [[0, 1]]]]),
91+
(
92+
games.create_EFG_for_nxn_bimatrix_coordination_game(3),
93+
[
94+
[[[1, 0, 0]], [[1, 0, 0]]],
95+
[[[0, 1, 0]], [[0, 1, 0]]],
96+
[[[0, 0, 1]], [[0, 0, 1]]],
97+
],
98+
),
99+
(games.create_EFG_for_6x6_bimatrix_with_long_LH_paths_and_unique_eq(), []),
100+
# 3-player game
101+
(
102+
games.create_mixed_behav_game_efg(),
103+
[
104+
[[[1, 0]], [[1, 0]], [[1, 0]]],
105+
[[[1, 0]], [[0, 1]], [[0, 1]]],
106+
[[[0, 1]], [[1, 0]], [[0, 1]]],
107+
[[[0, 1]], [[0, 1]], [[1, 0]]],
108+
],
109+
),
110+
]
111+
)
112+
def test_enumpure_agent(game: gbt.Game, pure_behav_prof_data: list):
113+
"""Test calls of enumeration of pure agent (behavior) equilibria
114+
115+
Tests max regret being zero (internal consistency) and compares the computed sequence of
116+
pure agent equilibria to a previosuly computed sequence (regression test)
117+
"""
118+
result = gbt.nash.enumpure_solve(game, use_strategic=False)
119+
assert len(result.equilibria) == len(pure_behav_prof_data)
120+
for eq, exp in zip(result.equilibria, pure_behav_prof_data):
121+
assert eq.max_regret() == 0
122+
expected = game.mixed_behavior_profile(rational=True, data=exp)
123+
assert eq == expected
30124

31125

32126
def test_enummixed_double():

tests/test_players.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_player_index_by_string():
3939

4040
def test_player_index_out_of_range():
4141
game = gbt.Game.new_table([2, 2])
42-
print(f"Number of players: {len(game.players)}")
4342
assert len(game.players) == 2
4443
with pytest.raises(IndexError):
4544
_ = game.players[2]

0 commit comments

Comments
 (0)