Ejemplo n.º 1
0
class TestPlayer_0opponents:
    """Test for trivial Player with no opponent player"""

    def setUp(self):
        """Setup a Player instance"""
        self.payoffs = [0, 1, -1]
        self.player = Player(self.payoffs)
        self.best_response_action = 1
        self.dominated_actions = [0, 2]

    def test_payoff_vector(self):
        """Trivial player: payoff_vector"""
        assert_array_equal(self.player.payoff_vector(None), self.payoffs)

    def test_is_best_response(self):
        """Trivial player: is_best_response"""
        ok_(self.player.is_best_response(self.best_response_action, None))

    def test_best_response(self):
        """Trivial player: best_response"""
        eq_(self.player.best_response(None), self.best_response_action)

    def test_is_dominated(self):
        """Trivial player: is_dominated"""
        for action in range(self.player.num_actions):
            eq_(self.player.is_dominated(action),
                (action in self.dominated_actions))

    def test_dominated_actions(self):
        """Trivial player: dominated_actions"""
        eq_(self.player.dominated_actions(), self.dominated_actions)
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])
        )
Ejemplo n.º 3
0
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_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_delete_action(self):
        N = self.player.num_opponents + 1
        action_to_delete = 0
        actions_to_remain = \
            np.setdiff1d(np.arange(self.player.num_actions), action_to_delete)
        for i in range(N):
            player_new = self.player.delete_action(action_to_delete, i)
            assert_array_equal(
                player_new.payoff_array,
                self.player.payoff_array.take(actions_to_remain, axis=i)
            )

    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])
        )

    def test_is_dominated(self):
        for action in range(self.player.num_actions):
            for method in LP_METHODS:
                eq_(self.player.is_dominated(action, method=method), False)

    def test_dominated_actions(self):
        for method in LP_METHODS:
            eq_(self.player.dominated_actions(method=method), [])
Ejemplo n.º 5
0
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_delete_action(self):
        N = self.player.num_opponents + 1
        action_to_delete = 0
        actions_to_remain = \
            np.setdiff1d(np.arange(self.player.num_actions), action_to_delete)
        for i in range(N):
            player_new = self.player.delete_action(action_to_delete, i)
            assert_array_equal(
                player_new.payoff_array,
                self.player.payoff_array.take(actions_to_remain, axis=i))

    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]))

    def test_is_dominated(self):
        for action in range(self.player.num_actions):
            for method in LP_METHODS:
                eq_(self.player.is_dominated(action, method=method), False)

    def test_dominated_actions(self):
        for method in LP_METHODS:
            eq_(self.player.dominated_actions(method=method), [])
Ejemplo n.º 6
0
class TestPlayer_0opponents:
    """Test for trivial Player with no opponent player"""
    def setUp(self):
        """Setup a Player instance"""
        payoffs = [0, 1]
        self.player = Player(payoffs)

    def test_payoff_vector(self):
        """Trivial player: payoff_vector"""
        assert_array_equal(self.player.payoff_vector(None), [0, 1])

    def test_is_best_response(self):
        """Trivial player: is_best_response"""
        ok_(self.player.is_best_response(1, None))

    def test_best_response(self):
        """Trivial player: best_response"""
        eq_(self.player.best_response(None), 1)
class TestPlayer_0opponents:
    """Test for trivial Player with no opponent player"""

    def setUp(self):
        """Setup a Player instance"""
        payoffs = [0, 1]
        self.player = Player(payoffs)

    def test_payoff_vector(self):
        """Trivial player: payoff_vector"""
        assert_array_equal(self.player.payoff_vector(None), [0, 1])

    def test_is_best_response(self):
        """Trivial player: is_best_response"""
        ok_(self.player.is_best_response(1, None))

    def test_best_response(self):
        """Trivial player: best_response"""
        eq_(self.player.best_response(None), 1)
class TestPlayer_0opponents:
    """Test for trivial Player with no opponent player"""

    def setUp(self):
        """Setup a Player instance"""
        self.payoffs = [0, 1, -1]
        self.player = Player(self.payoffs)
        self.best_response_action = 1
        self.dominated_actions = [0, 2]

    def test_delete_action(self):
        N = self.player.num_opponents + 1
        actions_to_delete = [0, 2]
        actions_to_remain = \
            np.setdiff1d(np.arange(self.player.num_actions), actions_to_delete)
        for i in range(N):
            player_new = self.player.delete_action(actions_to_delete, i)
            assert_array_equal(
                player_new.payoff_array,
                self.player.payoff_array.take(actions_to_remain, axis=i)
            )

    def test_payoff_vector(self):
        """Trivial player: payoff_vector"""
        assert_array_equal(self.player.payoff_vector(None), self.payoffs)

    def test_is_best_response(self):
        """Trivial player: is_best_response"""
        ok_(self.player.is_best_response(self.best_response_action, None))

    def test_best_response(self):
        """Trivial player: best_response"""
        eq_(self.player.best_response(None), self.best_response_action)

    def test_is_dominated(self):
        """Trivial player: is_dominated"""
        for action in range(self.player.num_actions):
            eq_(self.player.is_dominated(action),
                (action in self.dominated_actions))

    def test_dominated_actions(self):
        """Trivial player: dominated_actions"""
        eq_(self.player.dominated_actions(), self.dominated_actions)
Ejemplo n.º 9
0
class TestPlayer_0opponents:
    """Test for trivial Player with no opponent player"""
    def setup(self):
        """Setup a Player instance"""
        self.payoffs = [0, 1, -1]
        self.player = Player(self.payoffs)
        self.best_response_action = 1
        self.dominated_actions = [0, 2]

    def test_delete_action(self):
        N = self.player.num_opponents + 1
        actions_to_delete = [0, 2]
        actions_to_remain = \
            np.setdiff1d(np.arange(self.player.num_actions), actions_to_delete)
        for i in range(N):
            player_new = self.player.delete_action(actions_to_delete, i)
            assert_array_equal(
                player_new.payoff_array,
                self.player.payoff_array.take(actions_to_remain, axis=i))

    def test_payoff_vector(self):
        """Trivial player: payoff_vector"""
        assert_array_equal(self.player.payoff_vector(None), self.payoffs)

    def test_is_best_response(self):
        """Trivial player: is_best_response"""
        assert_(self.player.is_best_response(self.best_response_action, None))

    def test_best_response(self):
        """Trivial player: best_response"""
        assert_(self.player.best_response(None) == self.best_response_action)

    def test_is_dominated(self):
        """Trivial player: is_dominated"""
        for action in range(self.player.num_actions):
            assert_(
                self.player.is_dominated(action) == (
                    action in self.dominated_actions))

    def test_dominated_actions(self):
        """Trivial player: dominated_actions"""
        assert_(self.player.dominated_actions() == self.dominated_actions)