diff --git a/tests/test_actions.py b/tests/test_actions.py index 29c091472..1f1acadcd 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -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) @@ -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), @@ -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), @@ -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), @@ -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] diff --git a/tests/test_behav.py b/tests/test_behav.py index b45c8d10e..23d498dbc 100644 --- a/tests/test_behav.py +++ b/tests/test_behav.py @@ -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( diff --git a/tests/test_extensive.py b/tests/test_extensive.py index 501674ffe..a04618796 100644 --- a/tests/test_extensive.py +++ b/tests/test_extensive.py @@ -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 @@ -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]]), @@ -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]]]), diff --git a/tests/test_file.py b/tests/test_file.py index 490f9f321..b22e36c25 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -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 ( @@ -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 ( @@ -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(): diff --git a/tests/test_games/e01.efg b/tests/test_games/e01.efg deleted file mode 100644 index 6a95e0d0a..000000000 --- a/tests/test_games/e01.efg +++ /dev/null @@ -1,12 +0,0 @@ -EFG 2 R "Selten (IJGT, 75), Figure 1" { "Player 1" "Player 2" "Player 3" } -"" - -p "" 1 1 "(1,1)" { "R" "L" } 0 -p "" 2 1 "(2,1)" { "R" "L" } 0 -t "" 1 "Outcome 1" { 1, 1, 1 } -p "" 3 1 "(3,1)" { "R" "L" } 0 -t "" 2 "Outcome 2" { 4, 4, 0 } -t "" 3 "Outcome 3" { 0, 0, 1 } -p "" 3 1 "(3,1)" { "R" "L" } 0 -t "" 4 "Outcome 4" { 3, 2, 2 } -t "" 5 "Outcome 5" { 0, 0, 0 } diff --git a/tests/test_games/e02.efg b/tests/test_games/e02.efg deleted file mode 100644 index e636e0276..000000000 --- a/tests/test_games/e02.efg +++ /dev/null @@ -1,10 +0,0 @@ -EFG 2 R "Selten (IJGT, 75), Figure 2" { "Player 1" "Player 2" } -"" - -p "" 1 1 "(1,1)" { "R" "L" } 0 -t "" 1 "Outcome 1" { 1, 1 } -p "" 2 1 "(2,1)" { "R" "L" } 0 -t "" 2 "Outcome 2" { 0, 2 } -p "" 1 2 "(1,2)" { "r" "l" } 0 -t "" 3 "Outcome 3" { 0, 3 } -t "" 4 "Outcome 4" { 2, 0 } diff --git a/tests/test_games/e02.nfg b/tests/test_games/e02.nfg deleted file mode 100644 index e9723ea94..000000000 --- a/tests/test_games/e02.nfg +++ /dev/null @@ -1,3 +0,0 @@ -NFG 1 R "Selten (IJGT, 75), Figure 2, normal form" { "Player 1" "Player 2" } { 3 2 } - -1 1 0 2 0 2 1 1 0 3 2 0 diff --git a/tests/test_games/myerson_fig_4_2.efg b/tests/test_games/myerson_fig_4_2.efg deleted file mode 100644 index 713c4a34f..000000000 --- a/tests/test_games/myerson_fig_4_2.efg +++ /dev/null @@ -1,15 +0,0 @@ -EFG 2 R "Myerson (1991) Fig 4.2" { "Player 1" "Player 2" } -"An example from Myerson (1991) Fig 4.2 which has an agent Nash equilibrium that is -not a Nash equilibrium" - -p "" 1 1 "" { "A1" "B1" } 0 -p "" 2 1 "" { "W2" "X2" } 0 -p "" 1 2 "" { "Y1" "Z1" } 0 -t "" 1 "" { 3, 0 } -t "" 2 "" { 0, 0 } -p "" 1 2 "" { "Y1" "Z1" } 0 -t "" 3 "" { 2, 3 } -t "" 4 "" { 4, 1 } -p "" 2 1 "" { "W2" "X2" } 0 -t "" 5 "" { 2, 3 } -t "" 6 "" { 3, 2 } diff --git a/tests/test_games/zero.nfg b/tests/test_games/zero.nfg deleted file mode 100644 index 2a9615186..000000000 --- a/tests/test_games/zero.nfg +++ /dev/null @@ -1,3 +0,0 @@ -NFG 1 D "Two person 2 x 2 game with all zero payoffs" { "1" "2" } { 2 2 } - -0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 diff --git a/tests/test_infosets.py b/tests/test_infosets.py index c39046f43..bd3f0d6e8 100644 --- a/tests/test_infosets.py +++ b/tests/test_infosets.py @@ -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) @@ -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" diff --git a/tests/test_io.py b/tests/test_io.py index 3016c224b..28337e4af 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -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() diff --git a/tests/test_mixed.py b/tests/test_mixed.py index 287ee9eac..e4f288fec 100644 --- a/tests/test_mixed.py +++ b/tests/test_mixed.py @@ -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"), @@ -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, diff --git a/tests/test_nash.py b/tests/test_nash.py index d0e664cd6..abfaa607d 100644 --- a/tests/test_nash.py +++ b/tests/test_nash.py @@ -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)]]], ), diff --git a/tests/test_node.py b/tests/test_node.py index c3d35d04f..8478c5b5a 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -132,7 +132,7 @@ class SubgameRootsTestCase: # ------------------------------------------------------------------------ pytest.param( SubgameRootsTestCase( - factory=functools.partial(games.read_from_file, "e02.efg"), + factory=functools.partial(gbt.catalog.load, "selten1975/fig2"), expected_paths=[[], ["L"], ["L", "L"]] ), id="centipede_3_rounds" @@ -301,7 +301,6 @@ def test_node_own_prior_action_non_terminal(game_file, expected_node_data): @pytest.mark.parametrize("game_file, expected_unreachable_paths", [ # Games without absent-mindedness, where all nodes are reachable - ("e02.efg", []), ("wichardt.efg", []), ("subgames.efg", []), @@ -442,7 +441,7 @@ def _subtrees_equal( def test_copy_tree_onto_nondescendent_terminal_node(): """Test copying a subtree to a non-descendent node.""" - g = games.read_from_file("e01.efg") + g = gbt.catalog.load("selten1975/fig1") list_nodes = list(g.nodes) src_node = list_nodes[3] # path=[1, 0] dest_node = list_nodes[2] # path=[0, 0] @@ -454,7 +453,7 @@ def test_copy_tree_onto_nondescendent_terminal_node(): def test_copy_tree_onto_descendent_terminal_node(): """Test copying a subtree to a node that's a descendent of the original.""" - g = games.read_from_file("e01.efg") + g = gbt.catalog.load("selten1975/fig1") list_nodes = list(g.nodes) src_node = list_nodes[1] # path=[0] dest_node = list_nodes[4] # path=[0, 1, 0] @@ -681,7 +680,7 @@ def _count_subtree_nodes(start_node: gbt.Node, count_terminal: bool) -> int: def test_len_matches_expected_node_count(): """Verify `len(game.nodes)` matches expected node count """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") expected_node_count = 9 direct_len = len(game.nodes) @@ -693,7 +692,7 @@ def test_len_matches_expected_node_count(): def test_len_after_delete_tree(): """Verify `len(game.nodes)` is correct after `delete_tree`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -708,7 +707,7 @@ def test_len_after_delete_tree(): def test_len_after_delete_parent(): """Verify `len(game.nodes)` is correct after `delete_parent`. """ - game = games.read_from_file("e02.efg") + game = gbt.catalog.load("selten1975/fig2") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -726,7 +725,7 @@ def test_len_after_delete_parent(): def test_len_after_append_move(): """Verify `len(game.nodes)` is correct after `append_move`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -742,7 +741,7 @@ def test_len_after_append_move(): def test_len_after_append_infoset(): """Verify `len(game.nodes)` is correct after `append_infoset`. """ - game = games.read_from_file("e02.efg") + game = gbt.catalog.load("selten1975/fig2") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -759,7 +758,7 @@ def test_len_after_append_infoset(): def test_len_after_add_action(): """Verify `len(game.nodes)` is correct after `add_action`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) infoset_to_modify = game.infosets[1] @@ -774,7 +773,7 @@ def test_len_after_add_action(): def test_len_after_delete_action(): """Verify `len(game.nodes)` is correct after `delete_action`. """ - game = games.read_from_file("e02.efg") + game = gbt.catalog.load("selten1975/fig2") initial_number_of_nodes = len(game.nodes) action_to_delete = game.infosets[0].actions[1] @@ -795,7 +794,7 @@ def test_len_after_delete_action(): def test_len_after_insert_move(): """Verify `len(game.nodes)` is correct after `insert_move`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -812,7 +811,7 @@ def test_len_after_insert_move(): def test_len_after_insert_infoset(): """Verify `len(game.nodes)` is correct after `insert_infoset`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) @@ -829,7 +828,7 @@ def test_len_after_insert_infoset(): def test_len_after_copy_tree(): """Verify `len(game.nodes)` is correct after `copy_tree`. """ - game = games.read_from_file("e01.efg") + game = gbt.catalog.load("selten1975/fig1") initial_number_of_nodes = len(game.nodes) list_nodes = list(game.nodes) src_node = list_nodes[3] # path=[1, 0] @@ -844,7 +843,7 @@ def test_len_after_copy_tree(): def test_node_plays(): """Verify `node.plays` returns plays reachable from a given node. """ - game = games.read_from_file("e02.efg") + game = gbt.catalog.load("selten1975/fig2") list_nodes = list(game.nodes) test_node = list_nodes[2] # path=[1] @@ -885,8 +884,8 @@ def test_node_children_other_infoset_action(): pytest.param(games.read_from_file("basic_extensive_game.efg")), pytest.param(games.read_from_file("binary_3_levels_generic_payoffs.efg")), pytest.param(games.read_from_file("cent3.efg")), - pytest.param(games.read_from_file("e01.efg")), - pytest.param(games.read_from_file("e02.efg")), + pytest.param(gbt.catalog.load("selten1975/fig1")), + pytest.param(gbt.catalog.load("selten1975/fig2")), pytest.param(games.read_from_file("stripped_down_poker.efg")), pytest.param(gbt.Game.new_tree()), ],