Skip to content

Commit 543c937

Browse files
committed
removed create_2x2_zero_nfg from games.py
1 parent fa70567 commit 543c937

3 files changed

Lines changed: 89 additions & 60 deletions

File tree

tests/games.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from abc import ABC, abstractmethod
66

77
import numpy as np
8-
import pytest
98

109
import pygambit as gbt
1110

@@ -39,33 +38,6 @@ def create_efg_corresponding_to_bimatrix_game(
3938
return g
4039

4140

42-
################################################################################################
43-
# Normal-form (aka strategic-form) games (nfg)
44-
45-
46-
def create_2x2_zero_nfg() -> gbt.Game:
47-
"""
48-
Returns
49-
-------
50-
Game
51-
2x2 all-zero-payoffs bimatrix, with player names and a duplicate label set intentionally
52-
for testing purposes
53-
"""
54-
game = gbt.Game.new_table([2, 2])
55-
56-
game.players[0].label = "Joe"
57-
game.players["Joe"].strategies[0].label = "cooperate"
58-
game.players["Joe"].strategies[1].label = "defect"
59-
60-
game.players[1].label = "Dan"
61-
game.players["Dan"].strategies[0].label = "defect"
62-
# intentional duplicate label for player
63-
with pytest.warns(FutureWarning):
64-
game.players["Dan"].strategies[1].label = "defect"
65-
66-
return game
67-
68-
6941
################################################################################################
7042
# Extensive-form games (efg)
7143

tests/test_io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pygambit as gbt
88

9-
from .games import create_2x2_zero_nfg, create_selten_horse_game_efg
9+
from . import games
1010

1111

1212
@pytest.mark.parametrize("game_path", glob(os.path.join("tests", "test_games", "*.efg")))
@@ -112,15 +112,15 @@ def test_write_latex():
112112

113113

114114
def test_read_write_efg():
115-
efg_game = create_selten_horse_game_efg()
115+
efg_game = games.create_selten_horse_game_efg()
116116
serialized_efg_game = efg_game.to_efg()
117117
deserialized_efg_game = gbt.read_efg(io.BytesIO(serialized_efg_game.encode()))
118118
double_serialized_efg_game = deserialized_efg_game.to_efg()
119119
assert serialized_efg_game == double_serialized_efg_game
120120

121121

122122
def test_read_write_nfg():
123-
nfg_game = create_2x2_zero_nfg()
123+
nfg_game = games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg")
124124
serialized_nfg_game = nfg_game.to_nfg()
125125
deserialized_nfg_game = gbt.read_nfg(
126126
io.BytesIO(serialized_nfg_game.encode()), normalize_labels=False
@@ -130,7 +130,7 @@ def test_read_write_nfg():
130130

131131

132132
def test_read_write_nfg_normalize():
133-
nfg_game = create_2x2_zero_nfg()
133+
nfg_game = games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg")
134134
serialized_nfg_game = nfg_game.to_nfg()
135135
deserialized_nfg_game = gbt.read_nfg(
136136
io.BytesIO(serialized_nfg_game.encode()), normalize_labels=True

tests/test_mixed.py

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ def test_normalize_zero_value_error(game, profile_data, rational_flag):
7575
),
7676
###############################################################################
7777
# zero matrix nfg
78-
(games.create_2x2_zero_nfg(), [[1, 0], [0, -1]], True),
79-
(games.create_2x2_zero_nfg(), [[1.0, 1.0], [0, -1.0]], False),
78+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), [[1, 0], [0, -1]], True),
79+
(
80+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
81+
[[1.0, 1.0], [0, -1.0]],
82+
False,
83+
),
8084
###############################################################################
8185
# centipede with chance efg
8286
(games.create_centipede_game_with_chance_efg(), [[-1, 0, 0, 0], [1, 0, 0, 0]], True),
@@ -135,8 +139,8 @@ def test_normalize(game, profile_data, expected_data, rational_flag):
135139
[
136140
##############################################################################
137141
# zero matrix nfg
138-
(games.create_2x2_zero_nfg(), "cooperate", False, 0.72),
139-
(games.create_2x2_zero_nfg(), "cooperate", True, "7/9"),
142+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), "cooperate", False, 0.72),
143+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), "cooperate", True, "7/9"),
140144
###############################################################################
141145
# coordination 4x4 nfg outcome version with strategy labels
142146
(games.read_from_file("coordination_4x4_outcome.nfg"), "1-1", 0.25, False),
@@ -165,8 +169,8 @@ def test_set_and_get_probability_by_strategy_label(
165169
[
166170
##############################################################################
167171
# zero matrix nfg
168-
(games.create_2x2_zero_nfg(), "Joe", False, [0.72, 0.28]),
169-
(games.create_2x2_zero_nfg(), "Joe", True, ["7/9", "2/9"]),
172+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), "Joe", False, [0.72, 0.28]),
173+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), "Joe", True, ["7/9", "2/9"]),
170174
##############################################################################
171175
# coordination 4x4 nfg outcome version with strategy labels
172176
(games.read_from_file("coordination_4x4_payoff.nfg"), P1, False, [0.25, 0, 0, 0.75]),
@@ -306,7 +310,7 @@ def test_profile_indexing_by_invalid_strategy_label(
306310

307311

308312
def test_profile_indexing_by_player_and_duplicate_strategy_label():
309-
game = games.create_2x2_zero_nfg()
313+
game = games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg")
310314
profile = game.mixed_strategy_profile()
311315
with pytest.raises(ValueError):
312316
profile["Dan"]["defect"]
@@ -398,8 +402,8 @@ def test_profile_indexing_by_player_label_reference(
398402
[
399403
#########################################################################
400404
# zero matrix nfg
401-
(games.create_2x2_zero_nfg(), False, None, "Joe", 0),
402-
(games.create_2x2_zero_nfg(), True, None, "Joe", 0),
405+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), False, None, "Joe", 0),
406+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), True, None, "Joe", 0),
403407
#########################################################################
404408
# coordination 4x4 nfg
405409
(games.read_from_file("coordination_4x4_payoff.nfg"), False, None, P1, 0.25),
@@ -510,8 +514,8 @@ def test_payoff_by_label_reference(
510514
[
511515
##############################################################################
512516
# zero matrix nfg
513-
(games.create_2x2_zero_nfg(), False, "cooperate", 0),
514-
(games.create_2x2_zero_nfg(), True, "cooperate", 0),
517+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), False, "cooperate", 0),
518+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), True, "cooperate", 0),
515519
##############################################################################
516520
# coordination 4x4 nfg
517521
(games.read_from_file("coordination_4x4_outcome.nfg"), False, "1-1", 0.25),
@@ -553,8 +557,8 @@ def test_as_behavior_roundtrip(game: gbt.Game, rational_flag: bool):
553557
@pytest.mark.parametrize(
554558
"game,rational_flag",
555559
[
556-
(games.create_2x2_zero_nfg(), False),
557-
(games.create_2x2_zero_nfg(), True),
560+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), False),
561+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), True),
558562
(games.read_from_file("coordination_4x4_payoff.nfg"), False),
559563
(games.read_from_file("coordination_4x4_payoff.nfg"), True),
560564
],
@@ -569,7 +573,7 @@ def test_as_behavior_error(game: gbt.Game, rational_flag: bool):
569573
[
570574
###############################################################################
571575
# zero matrix nfg
572-
(games.create_2x2_zero_nfg(), None, True, (0, 0)),
576+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), None, True, (0, 0)),
573577
###############################################################################
574578
# 4x4 coordination nfg
575579
(games.read_from_file("coordination_4x4_payoff.nfg"), None, False, (0.25, 0.25)),
@@ -628,8 +632,8 @@ def test_payoffs_reference(
628632
[
629633
###############################################################################
630634
# zero matrix nfg
631-
(games.create_2x2_zero_nfg(), None, False, ([0, 0], [0, 0])),
632-
(games.create_2x2_zero_nfg(), None, True, ([0, 0], [0, 0])),
635+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), None, False, ([0, 0], [0, 0])),
636+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), None, True, ([0, 0], [0, 0])),
633637
###############################################################################
634638
# 4x4 coordination nfg
635639
(
@@ -693,10 +697,34 @@ def test_strategy_value_reference(
693697
[
694698
##############################################################################
695699
# Zero matrix nfg, all liap_values are zero
696-
(games.create_2x2_zero_nfg(), [["3/4", "1/4"], ["2/5", "3/5"]], 0, ZERO, True),
697-
(games.create_2x2_zero_nfg(), [["1/2", "1/2"], ["1/2", "1/2"]], 0, ZERO, True),
698-
(games.create_2x2_zero_nfg(), [[1, 0], [1, 0]], 0, ZERO, True),
699-
(games.create_2x2_zero_nfg(), [[1 / 4, 3 / 4], [2 / 5, 3 / 5]], 0, TOL, False),
700+
(
701+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
702+
[["3/4", "1/4"], ["2/5", "3/5"]],
703+
0,
704+
ZERO,
705+
True,
706+
),
707+
(
708+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
709+
[["1/2", "1/2"], ["1/2", "1/2"]],
710+
0,
711+
ZERO,
712+
True,
713+
),
714+
(
715+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
716+
[[1, 0], [1, 0]],
717+
0,
718+
ZERO,
719+
True,
720+
),
721+
(
722+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
723+
[[1 / 4, 3 / 4], [2 / 5, 3 / 5]],
724+
0,
725+
TOL,
726+
False,
727+
),
700728
##############################################################################
701729
# 4x4 coordination nfg
702730
(games.read_from_file("coordination_4x4_payoff.nfg"), None, 0, ZERO, True),
@@ -867,10 +895,34 @@ def test_liap_value_reference(
867895
[
868896
##############################################################################
869897
# Zero matrix nfg, all liap_values are zero
870-
(games.create_2x2_zero_nfg(), [["3/4", "1/4"], ["2/5", "3/5"]], [0] * 2, ZERO, True),
871-
(games.create_2x2_zero_nfg(), [["1/2", "1/2"], ["1/2", "1/2"]], [0] * 2, ZERO, True),
872-
(games.create_2x2_zero_nfg(), [[1, 0], [1, 0]], [0] * 2, ZERO, True),
873-
(games.create_2x2_zero_nfg(), [[1 / 4, 3 / 4], [2 / 5, 3 / 5]], [0] * 2, TOL, False),
898+
(
899+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
900+
[["3/4", "1/4"], ["2/5", "3/5"]],
901+
[0] * 2,
902+
ZERO,
903+
True,
904+
),
905+
(
906+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
907+
[["1/2", "1/2"], ["1/2", "1/2"]],
908+
[0] * 2,
909+
ZERO,
910+
True,
911+
),
912+
(
913+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
914+
[[1, 0], [1, 0]],
915+
[0] * 2,
916+
ZERO,
917+
True,
918+
),
919+
(
920+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
921+
[[1 / 4, 3 / 4], [2 / 5, 3 / 5]],
922+
[0] * 2,
923+
TOL,
924+
False,
925+
),
874926
##############################################################################
875927
# 4x4 coordination nfg
876928
(games.read_from_file("coordination_4x4_payoff.nfg"), None, [0] * 2, ZERO, True),
@@ -1048,8 +1100,8 @@ def test_player_regret_max_regret_reference(
10481100
(games.read_from_file("coordination_4x4_payoff.nfg"), True),
10491101
#################################################################################
10501102
# Zero matrix nfg
1051-
(games.create_2x2_zero_nfg(), False),
1052-
(games.create_2x2_zero_nfg(), True),
1103+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), False),
1104+
(games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"), True),
10531105
#################################################################################
10541106
# El Farol bar game efg
10551107
(games.create_el_farol_bar_game_efg(), False),
@@ -1281,7 +1333,7 @@ def test_player_regret_max_regret_consistency(
12811333
#################################################################################
12821334
# Zero matrix nfg
12831335
(
1284-
games.create_2x2_zero_nfg(),
1336+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
12851337
[["1/4", "3/4"], ["3/5", "2/5"]],
12861338
[["1/2", "1/2"], ["3/5", "2/5"]],
12871339
gbt.Rational("5/6"),
@@ -1384,7 +1436,12 @@ def test_linearity_payoff_property(
13841436
),
13851437
#################################################################################
13861438
# Zero matrix nfg
1387-
(games.create_2x2_zero_nfg(), [["4/5", "1/5"], ["4/7", "3/7"]], ZERO, True),
1439+
(
1440+
games.read_from_file("2x2_bimatrix_all_zero_payoffs.nfg"),
1441+
[["4/5", "1/5"], ["4/7", "3/7"]],
1442+
ZERO,
1443+
True,
1444+
),
13881445
#################################################################################
13891446
# Centipede game with chance
13901447
(

0 commit comments

Comments
 (0)