class TestPlayer_2opponents: """Test the methods of Player with two opponent players""" def setUp(self): """Setup a Player instance""" payoffs_2opponents = [[[3, 6], [4, 2]], [[1, 0], [5, 7]]] self.player = Player(payoffs_2opponents) def test_payoff_vector_against_pure(self): assert_array_equal(self.player.payoff_vector((0, 1)), [6, 0]) def test_is_best_response_against_pure(self): ok_(not self.player.is_best_response(0, (1, 0))) def test_best_response_against_pure(self): eq_(self.player.best_response((1, 1)), 1) def test_best_response_list_when_tie(self): """ best_response against a mixed action profile with tie_breaking=False """ assert_array_equal( sorted( self.player.best_response(([3 / 7, 4 / 7], [1 / 2, 1 / 2]), tie_breaking=False)), sorted([0, 1]))
class TestPlayer_1opponent: """Test the methods of Player with one opponent player""" def setUp(self): """Setup a Player instance""" coordination_game_matrix = [[4, 0], [3, 2]] self.player = Player(coordination_game_matrix) def test_best_response_against_pure(self): eq_(self.player.best_response(1), 1) def test_best_response_against_mixed(self): eq_(self.player.best_response([1 / 2, 1 / 2]), 1) def test_best_response_list_when_tie(self): """best_response with tie_breaking=False""" assert_array_equal( sorted( self.player.best_response([2 / 3, 1 / 3], tie_breaking=False)), sorted([0, 1])) def test_best_response_with_random_tie_breaking(self): """best_response with tie_breaking='random'""" ok_( self.player.best_response([2 / 3, 1 / 3], tie_breaking='random') in [0, 1]) def test_best_response_with_smallest_tie_breaking(self): """best_response with tie_breaking='smallest' (default)""" eq_(self.player.best_response([2 / 3, 1 / 3]), 0) def test_best_response_with_payoff_perturbation(self): """best_response with payoff_perturbation""" eq_( self.player.best_response([2 / 3, 1 / 3], payoff_perturbation=[0, 0.1]), 1) def test_is_best_response_against_pure(self): ok_(self.player.is_best_response(0, 0)) def test_is_best_response_against_mixed(self): ok_(self.player.is_best_response([1 / 2, 1 / 2], [2 / 3, 1 / 3]))
class TestPlayer_0opponents: """Test for degenerate Player with no opponent player""" def setUp(self): """Setup a Player instance""" payoffs = [0, 1] self.player = Player(payoffs) def test_payoff_vector(self): """Degenerate player: payoff_vector""" assert_array_equal(self.player.payoff_vector(None), [0, 1]) def test_is_best_response(self): """Degenerate player: is_best_response""" ok_(self.player.is_best_response(1, None)) def test_best_response(self): """Degenerate player: best_response""" eq_(self.player.best_response(None), 1)