diff --git a/Makefile.am b/Makefile.am index 84434fe9a..85fa72068 100644 --- a/Makefile.am +++ b/Makefile.am @@ -171,8 +171,6 @@ EXTRA_DIST = \ contrib/games/palf2.efg \ contrib/games/palf3.efg \ contrib/games/palf.efg \ - contrib/games/poker2.efg \ - contrib/games/poker.efg \ contrib/games/pvw2.efg \ contrib/games/pvw.efg \ contrib/games/sh3.efg \ @@ -188,6 +186,7 @@ EXTRA_DIST = \ contrib/games/work1.efg \ contrib/games/work2.efg \ contrib/games/work3.efg \ + contrib/games/2smp.efg \ contrib/games/2x2a.nfg \ contrib/games/2x2const.nfg \ contrib/games/2x2.nfg \ @@ -222,7 +221,6 @@ EXTRA_DIST = \ contrib/games/perfect1.nfg \ contrib/games/perfect2.nfg \ contrib/games/perfect3.nfg \ - contrib/games/poker.nfg \ contrib/games/sh3.nfg \ contrib/games/stengel.nfg \ contrib/games/sww1.nfg \ @@ -235,11 +233,15 @@ EXTRA_DIST = \ contrib/games/yamamoto.nfg \ contrib/games/zero.nfg \ src/README.rst \ - catalog/2smp.efg \ + catalog/bagwell1995.efg \ + catalog/myerson1991/fig2_1.efg \ catalog/myerson1991/fig4_2.efg \ + catalog/reiley2008/fig1.efg \ catalog/selten1975/fig1.efg \ catalog/selten1975/fig2.efg \ - catalog/selten1975/fig3.efg + catalog/selten1975/fig3.efg \ + catalog/watson2013/exercise29_6.efg \ + catalog/watson2013/fig29_1.efg core_SOURCES = \ src/core/core.h \ diff --git a/catalog/reiley2008/fig1.efg b/catalog/reiley2008/fig1.efg index cb3e698a6..9083ff0f6 100644 --- a/catalog/reiley2008/fig1.efg +++ b/catalog/reiley2008/fig1.efg @@ -16,7 +16,7 @@ p "" 1 1 "" { "Bet" "Fold" } 0 p "" 2 1 "" { "Call" "Fold" } 0 t "" 1 "Professor Wins Big" { 2, -2 } t "" 2 "Professor Wins" { 1, -1 } -t "" 4 "Professor Loses" { 1, -1 } +t "" 4 "Professor Loses" { -1, 1 } p "" 1 2 "" { "Bet" "Fold" } 0 p "" 2 1 "" { "Call" "Fold" } 0 t "" 3 "Professor Loses Big" { -2, 2 } diff --git a/doc/tutorials/04_creating_images.ipynb b/doc/tutorials/04_creating_images.ipynb index bd6e7e106..ec15e8f76 100644 --- a/doc/tutorials/04_creating_images.ipynb +++ b/doc/tutorials/04_creating_images.ipynb @@ -38,7 +38,7 @@ "metadata": {}, "outputs": [], "source": [ - "g = gbt.catalog.load(\"2smp\")" + "g = gbt.read_efg(\"../../contrib/games/2smp.efg\")" ] }, { diff --git a/tests/test_catalog.py b/tests/test_catalog.py index be4903a20..c010c2a51 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -4,31 +4,46 @@ import pygambit as gbt -def test_catalog_load_efg(): - """Test loading an extensive form game""" - g = gbt.catalog.load("selten1975/fig1") - assert isinstance(g, gbt.Game) - assert g.title == "Selten's horse (Selten IJGT 1975, Figure 1)" - - -# TODO: Reintroduce this test once we have a .nfg game in the catalog -# def test_catalog_load_nfg(): -# """Test loading a normal form game""" -# g = gbt.catalog.load("pd") -# assert isinstance(g, gbt.Game) -# assert g.title == "Two person Prisoner's Dilemma game" +@pytest.fixture +def game_slugs(): + """Fixture providing a set of all game slugs in the catalog.""" + game_slugs = set() + for resource_path in gbt.catalog._CATALOG_RESOURCE.rglob("*"): + if resource_path.is_file() and resource_path.suffix in gbt.catalog.READERS: + rel_path = resource_path.relative_to(gbt.catalog._CATALOG_RESOURCE) + slug = rel_path.with_suffix("").as_posix() + game_slugs.add(slug) + return game_slugs + + +def test_catalog_load_all_game_slugs(game_slugs): + """Test loading all valid game files in the catalog.""" + errors = [] + for slug in game_slugs: + try: + g = gbt.catalog.load(slug) + assert isinstance(g, gbt.Game), f"Expected gbt.Game, got {type(g)}" + except Exception as e: + errors.append(f"Slug '{slug}' failed with {type(e).__name__}: {e}") + + if errors: + pytest.fail(f"Errors loading {len(errors)} game(s):\n" + "\n".join(errors)) def test_catalog_load_invalid_slug(): - """Test loading an invalid game slug""" + """Test loading an invalid game slug.""" with pytest.raises(FileNotFoundError): gbt.catalog.load("invalid_slug") -def test_catalog_games(): - """Test games() function returns df of game slugs and titles""" +def test_catalog_games(game_slugs): + """Test games() function returns df of game slugs and titles.""" all_games = gbt.catalog.games() assert isinstance(all_games, pd.DataFrame) - assert len(all_games) > 0 - assert "myerson1991/fig4_2" in list(all_games.Game) - assert "Myerson (1991) Figure 4.2" in list(all_games.Title) + + # The games() function should return exactly the set of slugs found above + assert set(all_games["Game"]) == game_slugs + + # Test that standard columns are present + assert "Game" in all_games.columns + assert "Title" in all_games.columns