Skip to content

Change classifier test to call Classifiers #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions axelrod/tests/strategies/test_gambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class TestGambler(TestPlayer):
}

expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_strategy(self):
tft_table = {((), (D,), ()): 0, ((), (C,), ()): 1}
Expand Down Expand Up @@ -71,7 +70,6 @@ class TestPSOGamblerMem1(TestPlayer):
"manipulates_state": False,
}
expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_new_data(self):
original_data = {
Expand Down
3 changes: 0 additions & 3 deletions axelrod/tests/strategies/test_lookerup.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class TestLookerUp(TestPlayer):
}

expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_default_init(self):
player = self.player()
Expand Down Expand Up @@ -545,7 +544,6 @@ class TestWinner12(TestPlayer):
}

expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_new_data(self):
original_data = {
Expand Down Expand Up @@ -588,7 +586,6 @@ class TestWinner21(TestPlayer):
}

expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_new_data(self):
original_data = {
Expand Down
38 changes: 27 additions & 11 deletions axelrod/tests/strategies/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ def test_state_distribution(self):
match = axl.Match((player1, player2), turns=5)
_ = match.play()
self.assertEqual(
player1.state_distribution, {(C, C): 1, (C, D): 2, (D, C): 1, (D, D): 1}
player1.state_distribution,
{(C, C): 1, (C, D): 2, (D, C): 1, (D, D): 1},
)
self.assertEqual(
player2.state_distribution, {(C, C): 1, (C, D): 1, (D, C): 2, (D, D): 1}
player2.state_distribution,
{(C, C): 1, (C, D): 1, (D, C): 2, (D, D): 1},
)

def test_noisy_play(self):
Expand Down Expand Up @@ -129,7 +131,9 @@ def test_history_assignment(self):
player.history = []

def test_strategy(self):
self.assertRaises(NotImplementedError, self.player().strategy, self.player())
self.assertRaises(
NotImplementedError, self.player().strategy, self.player()
)

def test_clone(self):
"""Tests player cloning."""
Expand Down Expand Up @@ -345,7 +349,9 @@ def test_init_kwargs(self):
# Test that passing an unknown keyword argument or a spare one raises
# an error.
self.assertRaises(TypeError, ParameterisedTestPlayer, arg_test3="test")
self.assertRaises(TypeError, ParameterisedTestPlayer, "other", "other", "other")
self.assertRaises(
TypeError, ParameterisedTestPlayer, "other", "other", "other"
)


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

@given(
strategies=strategy_lists(max_size=5, strategies=short_run_time_short_mem),
strategies=strategy_lists(
max_size=5, strategies=short_run_time_short_mem
),
seed=integers(min_value=1, max_value=200),
turns=integers(min_value=1, max_value=200),
)
Expand Down Expand Up @@ -544,10 +552,8 @@ def versus_test(
):
"""
Tests a sequence of outcomes for two given players.

Parameters:
-----------

opponent: Player or list
An instance of a player OR a sequence of actions. If a sequence of
actions is passed, a Mock Player is created that cycles over that
Expand Down Expand Up @@ -605,20 +611,30 @@ def classifier_test(self, expected_class_classifier=None):
# specified
if expected_class_classifier is None:
expected_class_classifier = player.classifier
self.assertEqual(expected_class_classifier, self.player.classifier)
actual_class_classifier = {
c: axl.Classifiers[c](player)
for c in expected_class_classifier.keys()
}
self.assertEqual(expected_class_classifier, actual_class_classifier)

self.assertTrue(
"memory_depth" in player.classifier, msg="memory_depth not in classifier"
"memory_depth" in player.classifier,
msg="memory_depth not in classifier",
)
self.assertTrue(
"stochastic" in player.classifier, msg="stochastic not in classifier"
"stochastic" in player.classifier,
msg="stochastic not in classifier",
)
for key in TestOpponent.classifier:
self.assertEqual(
axl.Classifiers[key](player),
self.expected_classifier[key],
msg="%s - Behaviour: %s != Expected Behaviour: %s"
% (key, axl.Classifiers[key](player), self.expected_classifier[key]),
% (
key,
axl.Classifiers[key](player),
self.expected_classifier[key],
),
)


Expand Down
1 change: 0 additions & 1 deletion axelrod/tests/strategies/test_titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ class TestNTitsForMTats(TestPlayer):
}

expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier["memory_depth"] = float("inf")

def test_strategy(self):
# TitForTat test_strategy
Expand Down