Skip to content

Commit 3635b70

Browse files
gaffney2010drvinceknight
authored andcommitted
Change classifier test to call Classifiers
1 parent 95c221d commit 3635b70

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

axelrod/tests/strategies/test_gambler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class TestGambler(TestPlayer):
3535
}
3636

3737
expected_class_classifier = copy.copy(expected_classifier)
38-
expected_class_classifier["memory_depth"] = float("inf")
3938

4039
def test_strategy(self):
4140
tft_table = {((), (D,), ()): 0, ((), (C,), ()): 1}
@@ -71,7 +70,6 @@ class TestPSOGamblerMem1(TestPlayer):
7170
"manipulates_state": False,
7271
}
7372
expected_class_classifier = copy.copy(expected_classifier)
74-
expected_class_classifier["memory_depth"] = float("inf")
7573

7674
def test_new_data(self):
7775
original_data = {

axelrod/tests/strategies/test_lookerup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class TestLookerUp(TestPlayer):
200200
}
201201

202202
expected_class_classifier = copy.copy(expected_classifier)
203-
expected_class_classifier["memory_depth"] = float("inf")
204203

205204
def test_default_init(self):
206205
player = self.player()
@@ -545,7 +544,6 @@ class TestWinner12(TestPlayer):
545544
}
546545

547546
expected_class_classifier = copy.copy(expected_classifier)
548-
expected_class_classifier["memory_depth"] = float("inf")
549547

550548
def test_new_data(self):
551549
original_data = {
@@ -588,7 +586,6 @@ class TestWinner21(TestPlayer):
588586
}
589587

590588
expected_class_classifier = copy.copy(expected_classifier)
591-
expected_class_classifier["memory_depth"] = float("inf")
592589

593590
def test_new_data(self):
594591
original_data = {

axelrod/tests/strategies/test_player.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ def test_state_distribution(self):
9393
match = axl.Match((player1, player2), turns=5)
9494
_ = match.play()
9595
self.assertEqual(
96-
player1.state_distribution, {(C, C): 1, (C, D): 2, (D, C): 1, (D, D): 1}
96+
player1.state_distribution,
97+
{(C, C): 1, (C, D): 2, (D, C): 1, (D, D): 1},
9798
)
9899
self.assertEqual(
99-
player2.state_distribution, {(C, C): 1, (C, D): 1, (D, C): 2, (D, D): 1}
100+
player2.state_distribution,
101+
{(C, C): 1, (C, D): 1, (D, C): 2, (D, D): 1},
100102
)
101103

102104
def test_noisy_play(self):
@@ -129,7 +131,9 @@ def test_history_assignment(self):
129131
player.history = []
130132

131133
def test_strategy(self):
132-
self.assertRaises(NotImplementedError, self.player().strategy, self.player())
134+
self.assertRaises(
135+
NotImplementedError, self.player().strategy, self.player()
136+
)
133137

134138
def test_clone(self):
135139
"""Tests player cloning."""
@@ -345,7 +349,9 @@ def test_init_kwargs(self):
345349
# Test that passing an unknown keyword argument or a spare one raises
346350
# an error.
347351
self.assertRaises(TypeError, ParameterisedTestPlayer, arg_test3="test")
348-
self.assertRaises(TypeError, ParameterisedTestPlayer, "other", "other", "other")
352+
self.assertRaises(
353+
TypeError, ParameterisedTestPlayer, "other", "other", "other"
354+
)
349355

350356

351357
class TestOpponent(axl.Player):
@@ -496,7 +502,9 @@ def test_clone(self, seed):
496502
self.assertEqual(player1.history, player2.history)
497503

498504
@given(
499-
strategies=strategy_lists(max_size=5, strategies=short_run_time_short_mem),
505+
strategies=strategy_lists(
506+
max_size=5, strategies=short_run_time_short_mem
507+
),
500508
seed=integers(min_value=1, max_value=200),
501509
turns=integers(min_value=1, max_value=200),
502510
)
@@ -544,10 +552,8 @@ def versus_test(
544552
):
545553
"""
546554
Tests a sequence of outcomes for two given players.
547-
548555
Parameters:
549556
-----------
550-
551557
opponent: Player or list
552558
An instance of a player OR a sequence of actions. If a sequence of
553559
actions is passed, a Mock Player is created that cycles over that
@@ -605,20 +611,30 @@ def classifier_test(self, expected_class_classifier=None):
605611
# specified
606612
if expected_class_classifier is None:
607613
expected_class_classifier = player.classifier
608-
self.assertEqual(expected_class_classifier, self.player.classifier)
614+
actual_class_classifier = {
615+
c: axl.Classifiers[c](player)
616+
for c in expected_class_classifier.keys()
617+
}
618+
self.assertEqual(expected_class_classifier, actual_class_classifier)
609619

610620
self.assertTrue(
611-
"memory_depth" in player.classifier, msg="memory_depth not in classifier"
621+
"memory_depth" in player.classifier,
622+
msg="memory_depth not in classifier",
612623
)
613624
self.assertTrue(
614-
"stochastic" in player.classifier, msg="stochastic not in classifier"
625+
"stochastic" in player.classifier,
626+
msg="stochastic not in classifier",
615627
)
616628
for key in TestOpponent.classifier:
617629
self.assertEqual(
618630
axl.Classifiers[key](player),
619631
self.expected_classifier[key],
620632
msg="%s - Behaviour: %s != Expected Behaviour: %s"
621-
% (key, axl.Classifiers[key](player), self.expected_classifier[key]),
633+
% (
634+
key,
635+
axl.Classifiers[key](player),
636+
self.expected_classifier[key],
637+
),
622638
)
623639

624640

axelrod/tests/strategies/test_titfortat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ class TestNTitsForMTats(TestPlayer):
956956
}
957957

958958
expected_class_classifier = copy.copy(expected_classifier)
959-
expected_class_classifier["memory_depth"] = float("inf")
960959

961960
def test_strategy(self):
962961
# TitForTat test_strategy

0 commit comments

Comments
 (0)