Skip to content

Commit 57e04cb

Browse files
committed
Update unittest asserts
1 parent a8a4bf2 commit 57e04cb

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tests/test_player.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,56 @@ class TestAll(unittest.TestCase):
1515
def test_init(self):
1616
for strategy in all_strategies:
1717
player = Player(strategy)
18-
assert player.classifier["stochastic"]
19-
assert player.original_name == strategy
20-
assert player.original_function.argtypes == (
18+
self.assertTrue(player.classifier["stochastic"])
19+
self.assertEqual(player.original_name, strategy)
20+
self.assertEqual(player.original_function.argtypes, (
2121
POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int),
22-
POINTER(c_float))
23-
assert player.original_function.restype == c_int
22+
POINTER(c_float)))
23+
self.assertEqual(player.original_function.restype, c_int)
2424

2525
def test_matches(self):
2626
for strategy in all_strategies:
2727
for opponent in (Alternator, Cooperator, Defector):
2828
players = (Player(strategy), opponent())
2929
match = Match(players, turns=200)
30-
assert all(
30+
self.assertTrue(all(
3131
action in (C, D) for interaction in match.play()
32-
for action in interaction)
32+
for action in interaction))
3333

3434
def test_noisy_matches(self):
3535
for strategy in all_strategies:
3636
for opponent in (Alternator, Cooperator, Defector):
3737
players = (Player(strategy), opponent())
3838
match = Match(players, turns=200, noise=0.5)
39-
assert all(
39+
self.assertTrue(all(
4040
action in (C, D) for interaction in match.play()
41-
for action in interaction)
41+
for action in interaction))
4242

4343
def test_probend_matches(self):
4444
for strategy in all_strategies:
4545
for opponent in (Alternator, Cooperator, Defector):
4646
players = (Player(strategy), opponent())
4747
match = Match(players, prob_end=0.5)
48-
assert all(
48+
self.assertTrue(all(
4949
action in (C, D) for interaction in match.play()
50-
for action in interaction)
50+
for action in interaction))
5151

5252
def test_matches_with_different_game(self):
5353
for strategy in all_strategies:
5454
for opponent in (Alternator, Cooperator, Defector):
5555
game = Game(r=4,s=0,p=2,t=6)
5656
players = (Player(strategy, game=game), opponent())
5757
match = Match(players, turns=200, game=game)
58-
assert all(
58+
self.assertTrue(all(
5959
action in (C, D) for interaction in match.play()
60-
for action in interaction)
60+
for action in interaction))
6161

6262
def test_random(self):
6363
random.seed(10)
6464
players = (Player("KRANDOMC"), Player("KRANDOMC"))
6565
match = Match(players, 5)
6666
expected = [(C, D), (C, D), (C, C), (C, D), (C, D)]
67-
assert match.play() == expected
67+
self.assertEqual(match.play(), expected)
6868

6969
def test_original_strategy(self):
7070
"""
@@ -91,7 +91,7 @@ def test_original_strategy(self):
9191
random_value=0,
9292
my_last_move=my_action)
9393

94-
assert my_action in [0, 1]
94+
self.assertTrue(my_action in [0, 1])
9595

9696
scores = actions_to_scores[my_action, action]
9797
their_previous_action = action

tests/test_titfortat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ def test_versus_alternator(self):
1212
players = (Player('ktitfortatc'), axl.Alternator())
1313
match = axl.Match(players, 5)
1414
expected = [(C, C), (C, D), (D, C), (C, D), (D, C)]
15-
assert match.play() == expected
15+
self.assertEqual(match.play(), expected)
1616

1717
def test_versus_cooperator(self):
1818
players = (Player('ktitfortatc'), axl.Cooperator())
1919
match = axl.Match(players, 5)
2020
expected = [(C, C), (C, C), (C, C), (C, C), (C, C)]
21-
assert match.play() == expected
21+
self.assertEqual(match.play(), expected)
2222

2323
def test_versus_defector(self):
2424
players = (Player('ktitfortatc'), axl.Defector())
2525
match = axl.Match(players, 5)
2626
expected = [(C, D), (D, D), (D, D), (D, D), (D, D)]
27-
assert match.play() == expected
27+
self.assertEqual(match.play(), expected)

0 commit comments

Comments
 (0)