From 281ce2cbca28ba7aa5161212c2e9350606b59aba Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sun, 4 Nov 2018 16:56:29 +0900 Subject: [PATCH] FIX: is_dominated: Return False if num_actions == 1 --- quantecon/game_theory/normal_form_game.py | 2 ++ .../game_theory/tests/test_normal_form_game.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index 6df250df6..8feb1b942 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -420,6 +420,8 @@ def is_dominated(self, action, tol=None, method=None): ind[action] = False D = payoff_array[ind] D -= payoff_array[action] + if D.shape[0] == 0: # num_actions == 1 + return False if self.num_opponents >= 2: D.shape = (D.shape[0], np.prod(D.shape[1:])) diff --git a/quantecon/game_theory/tests/test_normal_form_game.py b/quantecon/game_theory/tests/test_normal_form_game.py index e390757db..bd583ff30 100644 --- a/quantecon/game_theory/tests/test_normal_form_game.py +++ b/quantecon/game_theory/tests/test_normal_form_game.py @@ -376,6 +376,24 @@ def test_normalformgame_setitem_1p(): eq_(g.players[0].payoff_array[0], 10) +# Trivial cases with one action # + +class TestPlayer_1action: + def setUp(self): + """Setup a Player instance""" + self.payoffs = [[0, 1]] + self.player = Player(self.payoffs) + + 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), []) + + # Test __repr__ # def test_player_repr():