11"""
22Tests for mclennan_tourky.py
3-
43"""
54import numpy as np
6- from numpy .testing import assert_array_equal
7- from nose .tools import ok_ , raises
5+ from numpy .testing import assert_array_equal , assert_raises , assert_
86from quantecon .game_theory import Player , NormalFormGame , mclennan_tourky
97from quantecon .game_theory .mclennan_tourky import (
10- _best_response_selection , _flatten_action_profile , _is_epsilon_nash
8+ _best_response_selection , _flatten_action_profile , _is_epsilon_nash
119)
1210
1311
1412class TestMclennanTourky ():
15- def setUp (self ):
13+ def setup (self ):
1614 def anti_coordination (N , v ):
1715 payoff_array = np .empty ((2 ,)* N )
1816 payoff_array [0 , :] = 1
@@ -48,37 +46,34 @@ def epsilon_nash_interval(N, v, epsilon):
4846 def test_convergence_default (self ):
4947 for d in self .game_dicts :
5048 NE , res = mclennan_tourky (d ['g' ], full_output = True )
51- ok_ (res .converged )
49+ assert_ (res .converged )
5250
5351 def test_pure_nash (self ):
5452 for d in self .game_dicts :
5553 init = (1 ,) + (0 ,)* (d ['g' ].N - 1 )
5654 NE , res = mclennan_tourky (d ['g' ], init = init , full_output = True )
57- ok_ (res .num_iter == 1 )
55+ assert_ (res .num_iter == 1 )
5856
5957
6058class TestMclennanTourkyInvalidInputs ():
61- def setUp (self ):
59+ def setup (self ):
6260 self .bimatrix = [[(3 , 3 ), (3 , 2 )],
6361 [(2 , 2 ), (5 , 6 )],
6462 [(0 , 3 ), (6 , 1 )]]
6563 self .g = NormalFormGame (self .bimatrix )
6664
67- @raises (TypeError )
6865 def test_mclennan_tourky_invalid_g (self ):
69- mclennan_tourky ( self .bimatrix )
66+ assert_raises ( TypeError , mclennan_tourky , self .bimatrix )
7067
71- @raises (TypeError )
7268 def test_mclennan_tourky_invalid_init_type (self ):
73- mclennan_tourky ( self .g , 1 )
69+ assert_raises ( TypeError , mclennan_tourky , self .g , 1 )
7470
75- @raises (ValueError )
7671 def test_mclennan_tourky_invalid_init_length (self ):
77- mclennan_tourky ( self .g , [1 ])
72+ assert_raises ( ValueError , mclennan_tourky , self .g , [1 ])
7873
7974
8075class TestEpsilonNash ():
81- def setUp (self ):
76+ def setup (self ):
8277 def anti_coordination (N , v ):
8378 payoff_array = np .empty ((2 ,)* N )
8479 payoff_array [0 , :] = 1
@@ -121,17 +116,17 @@ def test_epsilon_nash_with_full_output(self):
121116 NE , res = \
122117 mclennan_tourky (d ['g' ], epsilon = d ['epsilon' ], full_output = True )
123118 for i in range (d ['g' ].N ):
124- ok_ (d ['lb' ] < NE [i ][0 ] < d ['ub' ])
119+ assert_ (d ['lb' ] < NE [i ][0 ] < d ['ub' ])
125120
126121 def test_epsilon_nash_without_full_output (self ):
127122 for d in self .game_dicts :
128123 NE = mclennan_tourky (d ['g' ], epsilon = d ['epsilon' ],
129124 full_output = False )
130125 for i in range (d ['g' ].N ):
131- ok_ (d ['lb' ] < NE [i ][0 ] < d ['ub' ])
126+ assert_ (d ['lb' ] < NE [i ][0 ] < d ['ub' ])
132127
133128 def test_is_epsilon_nash_no_indptr (self ):
134- ok_ (_is_epsilon_nash ([1. , 0. , 0. , 1. , 0. ], self .g , 1e-5 ))
129+ assert_ (_is_epsilon_nash ([1. , 0. , 0. , 1. , 0. ], self .g , 1e-5 ))
135130
136131
137132def test_flatten_action_profile ():
@@ -151,13 +146,3 @@ def test_best_response_selection_no_indptr():
151146 expected_output = np .array ([0. , 1. , 0. , 0. , 1. ])
152147
153148 assert_array_equal (test_obj , expected_output )
154-
155-
156- if __name__ == '__main__' :
157- import sys
158- import nose
159-
160- argv = sys .argv [:]
161- argv .append ('--verbose' )
162- argv .append ('--nocapture' )
163- nose .main (argv = argv , defaultTest = __file__ )
0 commit comments