Skip to content

Commit

Permalink
[#1370] Remove some tests from test_meta.py (#1373)
Browse files Browse the repository at this point in the history
* [#1370] Remove some tests from test_meta.py

Removes some tests that do not target specific strategy behaviors and can change when new strategies are added.

* Add a property based test for valid strategies

Not sure if this is overkill @marcharper, just thought it could be worth
having.

* Run isort.

Co-authored-by: Vince Knight <vincent.knight@gmail.com>
  • Loading branch information
marcharper and drvinceknight committed Sep 25, 2020
1 parent e175c73 commit 2b07a83
Showing 1 changed file with 22 additions and 82 deletions.
104 changes: 22 additions & 82 deletions axelrod/tests/strategies/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import axelrod as axl
from axelrod.classifier import Classifiers
from axelrod.tests.property import strategy_lists
from hypothesis import given, settings
from hypothesis.strategies import integers

Expand Down Expand Up @@ -96,6 +97,27 @@ def test_update_histories(self):
with self.assertRaises(TypeError):
p.update_histories(C)

@settings(max_examples=5, deadline=None)
@given(opponent_list=strategy_lists(max_size=1))
def test_players_return_valid_actions(self, opponent_list):
"""
Whenever a new strategy is added to the library this potentially
modifies the behaviour of meta strategies which in turn requires
modification of the tests.
In https://github.com/Axelrod-Python/Axelrod/pull/1373 specific
behaviour tests for the meta strategies were removed.
This test ensures that a valid example is always returned by checking
that the actions played are a subset of {C, D}.
"""
player = self.player()
opponent = opponent_list[0]()
match = axl.Match(players=(player, opponent))
interactions = match.play()
player_actions = set(player_action for player_action, _ in interactions)
self.assertTrue(player_actions <= set((C, D)))


class TestMetaMajority(TestMetaPlayer):
name = "Meta Majority"
Expand Down Expand Up @@ -390,12 +412,6 @@ class TestMetaMajorityMemoryOne(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=1
)


class TestMetaMajorityFiniteMemory(TestMetaPlayer):
name = "Meta Majority Finite Memory"
Expand All @@ -410,12 +426,6 @@ class TestMetaMajorityFiniteMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=2
)


class TestMetaMajorityLongMemory(TestMetaPlayer):
name = "Meta Majority Long Memory"
Expand All @@ -430,18 +440,6 @@ class TestMetaMajorityLongMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=0
)

def test_strategy2(self):
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=1
)


class TestMetaWinnerMemoryOne(TestMetaPlayer):
name = "Meta Winner Memory One"
Expand All @@ -456,12 +454,6 @@ class TestMetaWinnerMemoryOne(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=1
)


class TestMetaWinnerFiniteMemory(TestMetaPlayer):
name = "Meta Winner Finite Memory"
Expand All @@ -476,12 +468,6 @@ class TestMetaWinnerFiniteMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=1
)


class TestMetaWinnerLongMemory(TestMetaPlayer):
name = "Meta Winner Long Memory"
Expand All @@ -496,12 +482,6 @@ class TestMetaWinnerLongMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=4
)


class TestMetaWinnerDeterministic(TestMetaPlayer):
name = "Meta Winner Deterministic"
Expand All @@ -516,10 +496,6 @@ class TestMetaWinnerDeterministic(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(opponent=axl.Alternator(), expected_actions=actions)


class TestMetaWinnerStochastic(TestMetaPlayer):
name = "Meta Winner Stochastic"
Expand All @@ -534,12 +510,6 @@ class TestMetaWinnerStochastic(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=1
)


class TestMetaMixer(TestMetaPlayer):
name = "Meta Mixer"
Expand Down Expand Up @@ -661,12 +631,6 @@ class TestNMWEDeterministic(TestMetaPlayer):
def classifier_test(self, expected_class_classifier=None):
pass

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=11
)


class TestNMWEStochastic(TestMetaPlayer):
name = "NMWE Stochastic"
Expand All @@ -681,12 +645,6 @@ class TestNMWEStochastic(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=16
)


class TestNMWEFiniteMemory(TestMetaPlayer):
name = "NMWE Finite Memory"
Expand All @@ -701,12 +659,6 @@ class TestNMWEFiniteMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (D, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=7
)


class TestNMWELongMemory(TestMetaPlayer):
name = "NMWE Long Memory"
Expand All @@ -721,12 +673,6 @@ class TestNMWELongMemory(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=3
)


class TestNMWEMemoryOne(TestMetaPlayer):
name = "NMWE Memory One"
Expand All @@ -741,12 +687,6 @@ class TestNMWEMemoryOne(TestMetaPlayer):
"manipulates_state": False,
}

def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (D, D), (D, C)]
self.versus_test(
opponent=axl.Alternator(), expected_actions=actions, seed=2
)


class TestMemoryDecay(TestPlayer):
name = "Memory Decay: 0.1, 0.03, -2, 1, Tit For Tat, 15"
Expand Down

0 comments on commit 2b07a83

Please sign in to comment.