Skip to content

Commit 92c0865

Browse files
authored
MAINT: TEST: Remove nose functions (#597)
Replaced with `numpy.testing` functions
1 parent 1eabdbf commit 92c0865

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

quantecon/game_theory/game_generators/tests/test_bimatrix_generators.py

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"""
55
import numpy as np
66
from scipy.special import comb
7-
from numpy.testing import assert_array_equal
8-
from nose.tools import eq_, ok_, raises
7+
from numpy.testing import assert_array_equal, assert_, assert_raises
98
from quantecon.gridtools import num_compositions
109
from quantecon.game_theory import pure_nash_brute
1110

@@ -15,19 +14,19 @@
1514

1615

1716
class TestBlottoGame:
18-
def setUp(self):
17+
def setup(self):
1918
self.h, self.t = 4, 3
2019
rho = 0.5
2120
self.g = blotto_game(self.h, self.t, rho)
2221

2322
def test_size(self):
2423
n = num_compositions(self.h, self.t)
25-
eq_(self.g.nums_actions, (n, n))
24+
assert_(self.g.nums_actions == (n, n))
2625

2726
def test_constant_diagonal(self):
2827
for i in range(self.g.N):
2928
diag = self.g.payoff_arrays[i].diagonal()
30-
ok_((diag == diag[0]).all())
29+
assert_((diag == diag[0]).all())
3130

3231
def test_seed(self):
3332
seed = 0
@@ -39,21 +38,23 @@ def test_seed(self):
3938

4039

4140
class TestRankingGame:
42-
def setUp(self):
41+
def setup(self):
4342
self.n = 100
4443
self.g = ranking_game(self.n)
4544

4645
def test_size(self):
47-
eq_(self.g.nums_actions, (self.n, self.n))
46+
assert_(self.g.nums_actions == (self.n, self.n))
4847

4948
def test_weakly_decreasing_row_wise_payoffs(self):
5049
for payoff_array in self.g.payoff_arrays:
51-
ok_((payoff_array[:, 1:-1] >= payoff_array[:, 2:]).all())
50+
assert_((payoff_array[:, 1:-1] >= payoff_array[:, 2:]).all())
5251

5352
def test_elements_first_row(self):
54-
eq_(self.g.payoff_arrays[0][0, 0] + self.g.payoff_arrays[1][0, 0], 1.)
53+
assert_(
54+
self.g.payoff_arrays[0][0, 0] + self.g.payoff_arrays[1][0, 0] == 1.
55+
)
5556
for payoff_array in self.g.payoff_arrays:
56-
ok_(np.isin(payoff_array[0, :], [0, 1, 0.5]).all())
57+
assert_(np.isin(payoff_array[0, :], [0, 1, 0.5]).all())
5758

5859
def test_seed(self):
5960
seed = 0
@@ -84,53 +85,52 @@ def test_sgc_game():
8485

8586

8687
class TestTournamentGame:
87-
def setUp(self):
88+
def setup(self):
8889
self.n = 5
8990
self.k = 3
9091
self.m = comb(self.n, self.k, exact=True)
9192
self.g = tournament_game(self.n, self.k)
9293

9394
def test_size(self):
94-
eq_(self.g.nums_actions, (self.n, self.m))
95+
assert_(self.g.nums_actions == (self.n, self.m))
9596

9697
def test_payoff_values(self):
9798
possible_values = [0, 1]
9899
for payoff_array in self.g.payoff_arrays:
99-
ok_(np.isin(payoff_array, possible_values).all())
100+
assert_(np.isin(payoff_array, possible_values).all())
100101

101102
max_num_dominated_subsets = \
102103
sum([comb(i, self.k, exact=True) for i in range(self.n)])
103-
ok_(self.g.payoff_arrays[0].sum() <= max_num_dominated_subsets)
104-
ok_((self.g.payoff_arrays[1].sum(axis=1) == self.k).all())
104+
assert_(self.g.payoff_arrays[0].sum() <= max_num_dominated_subsets)
105+
assert_((self.g.payoff_arrays[1].sum(axis=1) == self.k).all())
105106

106107
def test_seed(self):
107108
seed = 0
108109
g0 = tournament_game(self.n, self.k, random_state=seed)
109110
g1 = tournament_game(self.n, self.k, random_state=seed)
110111
assert_array_equal(g1.payoff_profile_array, g0.payoff_profile_array)
111112

112-
@raises(ValueError)
113113
def test_raises_value_error_too_large_inputs(self):
114114
n, k = 100, 50
115-
tournament_game(n, k)
115+
assert_raises(ValueError, tournament_game, n, k)
116116

117117

118118
class TestUnitVectorGame:
119-
def setUp(self):
119+
def setup(self):
120120
self.n = 100
121121
self.g = unit_vector_game(self.n)
122122

123123
def test_size(self):
124-
eq_(self.g.nums_actions, (self.n, self.n))
124+
assert_(self.g.nums_actions == (self.n, self.n))
125125

126126
def test_payoff_values(self):
127127
# Player 0
128-
ok_((np.sum(self.g.players[0].payoff_array, axis=0) == 1).all())
128+
assert_((np.sum(self.g.players[0].payoff_array, axis=0) == 1).all())
129129

130130
def test_avoid_pure_nash(self):
131131
NEs = pure_nash_brute(unit_vector_game(self.n, avoid_pure_nash=True),
132132
tol=0)
133-
eq_(len(NEs), 0)
133+
assert_(len(NEs) == 0)
134134

135135
def test_seed(self):
136136
seed = 0
@@ -144,12 +144,11 @@ def test_redraw(self):
144144
n = 2
145145
g = unit_vector_game(n, avoid_pure_nash=True, random_state=seed)
146146
NEs = pure_nash_brute(g, tol=0)
147-
eq_(len(NEs), 0)
147+
assert_(len(NEs) == 0)
148148

149-
@raises(ValueError)
150149
def test_raises_value_error_avoid_pure_nash_n_1(self):
151150
n = 1
152-
unit_vector_game(n, avoid_pure_nash=True)
151+
assert_raises(ValueError, unit_vector_game, n, avoid_pure_nash=True)
153152

154153

155154
def test_payoff_range():
@@ -162,13 +161,3 @@ def test_payoff_range():
162161
g = func(**kwargs)
163162
for payoff_array in g.payoff_arrays:
164163
assert_array_equal(np.clip(payoff_array, 0, 1), payoff_array)
165-
166-
167-
if __name__ == '__main__':
168-
import sys
169-
import nose
170-
171-
argv = sys.argv[:]
172-
argv.append('--verbose')
173-
argv.append('--nocapture')
174-
nose.main(argv=argv, defaultTest=__file__)

0 commit comments

Comments
 (0)