def test_normalformgame_constant_payoffs(): g = NormalFormGame((2, 2)) ok_(g.is_nash((0, 0))) ok_(g.is_nash((0, 1))) ok_(g.is_nash((1, 0))) ok_(g.is_nash((1, 1)))
class TestNormalFormGame_Sym2p: """Test the methods of NormalFormGame with symmetric two players""" def setUp(self): """Setup a NormalFormGame instance""" coordination_game_matrix = [[4, 0], [3, 2]] self.g = NormalFormGame(coordination_game_matrix) def test_getitem(self): assert_array_equal(self.g[0, 1], [0, 3]) def test_is_nash_pure(self): ok_(self.g.is_nash((0, 0))) def test_is_nash_mixed(self): ok_(self.g.is_nash(([2 / 3, 1 / 3], [2 / 3, 1 / 3])))
class TestNormalFormGame_Asym2p: """Test the methods of NormalFormGame with asymmetric two players""" def setUp(self): """Setup a NormalFormGame instance""" matching_pennies_bimatrix = [[(1, -1), (-1, 1)], [(-1, 1), (1, -1)]] self.g = NormalFormGame(matching_pennies_bimatrix) def test_getitem(self): assert_array_equal(self.g[1, 0], [-1, 1]) def test_is_nash_against_pure(self): ok_(not self.g.is_nash((0, 0))) def test_is_nash_against_mixed(self): ok_(self.g.is_nash(([1 / 2, 1 / 2], [1 / 2, 1 / 2])))
class TestNormalFormGame_3p: """Test the methods of NormalFormGame with three players""" def setUp(self): """Setup a NormalFormGame instance""" payoffs_2opponents = [[[3, 6], [4, 2]], [[1, 0], [5, 7]]] player = Player(payoffs_2opponents) self.g = NormalFormGame([player for i in range(3)]) def test_getitem(self): assert_array_equal(self.g[0, 0, 1], [6, 4, 1]) def test_is_nash_pure(self): ok_(self.g.is_nash((0, 0, 0))) ok_(not self.g.is_nash((0, 0, 1))) def test_is_nash_mixed(self): p = (1 + np.sqrt(65)) / 16 ok_(self.g.is_nash(([1 - p, p], [1 - p, p], [1 - p, p])))
class TestNormalFormGame_1p: """Test for degenerate NormalFormGame with a single player""" def setUp(self): """Setup a NormalFormGame instance""" data = [[0], [1], [1]] self.g = NormalFormGame(data) def test_construction(self): """Degenerate game: construction""" ok_(self.g.N == 1) assert_array_equal(self.g.players[0].payoff_array, [0, 1, 1]) def test_getitem(self): """Degenerate game: __getitem__""" eq_(self.g[0], 0) def test_is_nash_pure(self): """Degenerate game: is_nash with pure action""" ok_(self.g.is_nash((1, ))) ok_(not self.g.is_nash((0, ))) def test_is_nash_mixed(self): """Degenerate game: is_nash with mixed action""" ok_(self.g.is_nash(([0, 1 / 2, 1 / 2], )))