Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_action_delete_chance(game: gbt.Game):
def test_action_plays():
"""Verify `action.plays` returns plays reachable from a given action.
"""
game = games.read_from_file("e01.efg")
game = gbt.catalog.load("selten1975/fig1")
list_nodes = list(game.nodes)
list_infosets = list(game.infosets)

Expand All @@ -160,16 +160,16 @@ def test_action_plays():
@pytest.mark.parametrize(
"game, player_ind, str_ind, infoset_ind, expected_action_ind",
[
(games.read_from_file("e01.efg"), 0, 0, 0, 0),
(games.read_from_file("e01.efg"), 0, 1, 0, 1),
(games.read_from_file("e01.efg"), 1, 0, 1, 0),
(games.read_from_file("e01.efg"), 1, 1, 1, 1),
(games.read_from_file("e01.efg"), 2, 0, 2, 0),
(games.read_from_file("e01.efg"), 2, 1, 2, 1),
(games.read_from_file("e02.efg"), 0, 0, 0, 0),
(games.read_from_file("e02.efg"), 0, 1, 0, 1),
(games.read_from_file("e02.efg"), 1, 0, 2, 0),
(games.read_from_file("e02.efg"), 1, 1, 2, 1),
(gbt.catalog.load("selten1975/fig1"), 0, 0, 0, 0),
(gbt.catalog.load("selten1975/fig1"), 0, 1, 0, 1),
(gbt.catalog.load("selten1975/fig1"), 1, 0, 1, 0),
(gbt.catalog.load("selten1975/fig1"), 1, 1, 1, 1),
(gbt.catalog.load("selten1975/fig1"), 2, 0, 2, 0),
(gbt.catalog.load("selten1975/fig1"), 2, 1, 2, 1),
(gbt.catalog.load("selten1975/fig2"), 0, 0, 0, 0),
(gbt.catalog.load("selten1975/fig2"), 0, 1, 0, 1),
(gbt.catalog.load("selten1975/fig2"), 1, 0, 2, 0),
(gbt.catalog.load("selten1975/fig2"), 1, 1, 2, 1),
(games.read_from_file("basic_extensive_game.efg"), 0, 0, 0, 0),
(games.read_from_file("basic_extensive_game.efg"), 0, 1, 0, 1),
(games.read_from_file("basic_extensive_game.efg"), 1, 0, 1, 0),
Expand All @@ -194,7 +194,7 @@ def test_strategy_action_defined(game, player_ind, str_ind, infoset_ind, expecte
@pytest.mark.parametrize(
"game, player_ind, str_ind, infoset_ind",
[
(games.read_from_file("e02.efg"), 0, 0, 1),
(gbt.catalog.load("selten1975/fig2"), 0, 0, 1),
(games.read_from_file("cent3.efg"), 0, 0, 1),
(games.read_from_file("cent3.efg"), 0, 0, 2),
(games.read_from_file("cent3.efg"), 0, 1, 2),
Expand All @@ -218,10 +218,10 @@ def test_strategy_action_undefined_returns_none(game, player_ind, str_ind, infos
@pytest.mark.parametrize(
"game, player_ind, infoset_ind",
[
(games.read_from_file("e01.efg"), 0, 1),
(games.read_from_file("e01.efg"), 1, 0),
(games.read_from_file("e02.efg"), 0, 2),
(games.read_from_file("e02.efg"), 1, 0),
(gbt.catalog.load("selten1975/fig1"), 0, 1),
(gbt.catalog.load("selten1975/fig1"), 1, 0),
(gbt.catalog.load("selten1975/fig2"), 0, 2),
(gbt.catalog.load("selten1975/fig2"), 1, 0),
(games.read_from_file("basic_extensive_game.efg"), 0, 1),
(games.read_from_file("basic_extensive_game.efg"), 1, 2),
(games.read_from_file("basic_extensive_game.efg"), 2, 0),
Expand All @@ -243,7 +243,7 @@ def test_strategy_action_raises_value_error_for_wrong_player(game, player_ind, i
def test_strategy_action_raises_error_for_strategic_game():
"""Verify `Strategy.action` retrieves the action prescribed by the strategy
"""
game_efg = games.read_from_file("e02.efg")
game_efg = gbt.catalog.load("selten1975/fig2")
game_nfg = game_efg.from_arrays(game_efg.to_arrays()[0], game_efg.to_arrays()[1])
alice = game_nfg.players[0]
strategy = alice.strategies[0]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_behav.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,7 @@ def test_agent_liap_value_reference(
"1/16",
),
(games.read_from_file("mixed_behavior_game.efg"), None, False, 0.25, 0.25, 0.0625, 0.0625),
# Myerson fig 4.2
(games.read_from_file("myerson_fig_4_2.efg"), [0, 1, 0, 1, 1, 0], True, 1, 0, 1, 0),
(gbt.catalog.load("myerson1991/fig4_2"), [0, 1, 0, 1, 1, 0], True, 1, 0, 1, 0),
],
)
def test_agent_max_regret_versus_non_agent(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_extensive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_game_add_players_nolabel():

@pytest.mark.parametrize("game_input,expected_result", [
# Games with perfect recall from files (game_input is a string)
("e02.efg", True),
(gbt.catalog.load("selten1975/fig2"), True),
("stripped_down_poker.efg", True),
# Games with perfect recall from generated games (game_input is a gbt.Game object)
# - Centipede games
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_outcome_index_exception_label():
),
# 2 players; reduction possible for player 1; payoff ties
(
games.read_from_file("e02.efg"),
gbt.catalog.load("selten1975/fig2"),
[["1*", "21", "22"], ["1", "2"]],
[
np.array([[1, 1], [0, 0], [0, 2]]),
Expand All @@ -147,7 +147,7 @@ def test_outcome_index_exception_label():
),
# Selten's Horse: game with three players
(
games.read_from_file("e01.efg"),
gbt.catalog.load("selten1975/fig1"),
[["1", "2"], ["1", "2"], ["1", "2"]],
[
np.array([[[1, 1], [4, 0]], [[3, 0], [3, 0]]]),
Expand Down
30 changes: 15 additions & 15 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_efg_no_newline_end():


def test_string_wrong_magic():
with open("tests/test_games/e01.efg") as f:
file_text = f.read().replace("EFG", "")
file_text = gbt.catalog.load("selten1975/fig1").to_efg()
file_text = file_text.replace("EFG", "")
with pytest.raises(ValueError) as excinfo:
_parse_efg(file_text)
assert (
Expand All @@ -43,16 +43,16 @@ def test_string_wrong_magic():


def test_efg_unsupported_version():
with open("tests/test_games/e01.efg") as f:
file_text = f.read().replace("EFG 2", "EFG 1")
file_text = gbt.catalog.load("selten1975/fig1").to_efg()
file_text = file_text.replace("EFG 2", "EFG 1")
with pytest.raises(ValueError) as excinfo:
_parse_efg(file_text)
assert "Parse error in game file: line 1:6: Accepting only EFG version 2" in str(excinfo.value)


def test_efg_unsupported_precision():
with open("tests/test_games/e01.efg") as f:
file_text = f.read().replace("EFG 2 R", "EFG 2 X")
file_text = gbt.catalog.load("selten1975/fig1").to_efg()
file_text = file_text.replace("EFG 2 R", "EFG 2 X")
with pytest.raises(ValueError) as excinfo:
_parse_efg(file_text)
assert (
Expand All @@ -62,35 +62,35 @@ def test_efg_unsupported_precision():


def test_efg_invalid_node_type():
with open("tests/test_games/e02.efg") as f:
file_text = f.read().replace('p "" 1 1', 'x "" 1 1')
file_text = gbt.catalog.load("selten1975/fig2").to_efg()
file_text = file_text.replace('p "" 1 1', 'x "" 1 1')
with pytest.raises(ValueError) as excinfo:
_parse_efg(file_text)
assert "Parse error in game file: line 4:3: Invalid type of node" in str(excinfo)


def test_efg_payoffs_too_many():
with open("tests/test_games/e02.efg") as f:
file_text = f.read().replace("1, 1", "1, 2, 3")
file_text = gbt.catalog.load("selten1975/fig2").to_efg()
file_text = file_text.replace("1, 1", "1, 2, 3")
with pytest.raises(ValueError) as excinfo:
_parse_efg(file_text)
assert "Parse error in game file: line 5:29: Expected '}'" in str(excinfo)


def test_nfg_title_missing():
with open("tests/test_games/e02.nfg") as f:
file_text = f.read().replace('"Selten (IJGT, 75), Figure 2, normal form"', "")
file_text = gbt.catalog.load("selten1975/fig2").to_nfg()
file_text = file_text.replace('"Selten (IJGT 1975) Figure 2"', "")
with pytest.raises(ValueError) as excinfo:
_parse_nfg(file_text)
assert "Parse error in game file: line 1:11: Game title missing" in str(excinfo)


def test_nfg_player_missing():
with open("tests/test_games/e02.nfg") as f:
file_text = f.read().replace('"Player 2"', "")
file_text = gbt.catalog.load("selten1975/fig2").to_nfg()
file_text = file_text.replace('"Player 2"', "")
with pytest.raises(ValueError) as excinfo:
_parse_nfg(file_text)
assert "Parse error in game file: line 1:73: Expected '}'" in str(excinfo)
assert "Parse error in game file: line 4:2: Expected '}'" in str(excinfo)


def test_nfg_payoffs_not_enough():
Expand Down
12 changes: 0 additions & 12 deletions tests/test_games/e01.efg

This file was deleted.

10 changes: 0 additions & 10 deletions tests/test_games/e02.efg

This file was deleted.

3 changes: 0 additions & 3 deletions tests/test_games/e02.nfg

This file was deleted.

15 changes: 0 additions & 15 deletions tests/test_games/myerson_fig_4_2.efg

This file was deleted.

3 changes: 0 additions & 3 deletions tests/test_games/zero.nfg

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_infosets.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_infoset_add_action_error():
def test_infoset_plays():
"""Verify `infoset.plays` returns plays reachable from a given infoset.
"""
game = games.read_from_file("e01.efg")
game = gbt.catalog.load("selten1975/fig1")
list_nodes = list(game.nodes)
list_infosets = list(game.infosets)

Expand Down Expand Up @@ -150,7 +150,7 @@ class AbsentMindednessTestCase:
# Games without absent-mindedness
pytest.param(
AbsentMindednessTestCase(
factory=functools.partial(games.read_from_file, "e02.efg"),
factory=functools.partial(gbt.catalog.load, "selten1975/fig2"),
expected_am_paths=[]
),
id="short_centipede_perfect_info"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_write_latex():


def test_read_write_efg():
efg_game = games.read_from_file("e01.efg")
efg_game = gbt.catalog.load("selten1975/fig1")
serialized_efg_game = efg_game.to_efg()
deserialized_efg_game = gbt.read_efg(io.BytesIO(serialized_efg_game.encode()))
double_serialized_efg_game = deserialized_efg_game.to_efg()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def test_player_regret_max_regret_consistency(
#################################################################################
# Selten's horse
(
games.read_from_file("e01.efg"),
gbt.catalog.load("selten1975/fig1"),
[["4/9", "5/9"], ["1/11", "10/11"], ["8/9", "1/9"]],
[["4/9", "5/9"], ["10/11", "1/11"], ["8/9", "1/9"]],
gbt.Rational("4/9"),
Expand Down Expand Up @@ -1459,13 +1459,13 @@ def test_linearity_payoff_property(
#################################################################################
# Selten's horse
(
games.read_from_file("e01.efg"),
gbt.catalog.load("selten1975/fig1"),
[["4/9", "5/9"], ["6/11", "5/11"], ["4/7", "3/7"]],
ZERO,
True,
),
(
games.read_from_file("e01.efg"),
gbt.catalog.load("selten1975/fig1"),
[[4 / 9, 5 / 9], [6 / 11, 5 / 11], [4 / 7, 3 / 7]],
TOL,
False,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ def are_the_same(game, found, candidate):
# Examples where the are agent-form pure equillibrium behaviors that are not Nash eq
pytest.param(
EquilibriumTestCase(
factory=functools.partial(games.read_from_file, "myerson_fig_4_2.efg"),
factory=functools.partial(gbt.catalog.load, "myerson1991/fig4_2"),
solver=functools.partial(gbt.nash.enumpure_agent_solve),
expected=[[[d(1, 0), d(0, 1)], [d(0, 1)]], [[d(0, 1), d(0, 1)], [d(1, 0)]]],
),
Expand Down
Loading
Loading