Skip to content
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

Standardize tests for memoryone and memorytwo files. #1333

Merged
merged 1 commit into from
Jun 5, 2020
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
8 changes: 8 additions & 0 deletions axelrod/data/all_classifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,14 @@ Opposite Grudger:
manipulates_state: false
memory_depth: .inf
stochastic: false
Original Gradual:
inspects_source: false
long_run_time: false
makes_use_of: !!set {}
manipulates_source: false
manipulates_state: false
memory_depth: .inf
stochastic: false
PSO Gambler 1_1_1:
inspects_source: false
long_run_time: false
Expand Down
3 changes: 0 additions & 3 deletions axelrod/strategies/memoryone.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def set_initial_four_vector(self, four_vector):
warnings.warn("Memory one player is set to default (1, 0, 0, 1).")

self.set_four_vector(four_vector)
if self.name == "Generic Memory One Player":
self.name = "%s: %s" % (self.name, four_vector)

def set_four_vector(self, four_vector: Tuple[float, float, float, float]):
if not all(0 <= p <= 1 for p in four_vector):
Expand Down Expand Up @@ -340,4 +338,3 @@ class ReactivePlayer(MemoryOnePlayer):
def __init__(self, probabilities: Tuple[float, float]) -> None:
four_vector = (*probabilities, *probabilities)
super().__init__(four_vector)
self.name = "%s: %s" % (self.name, probabilities)
10 changes: 5 additions & 5 deletions axelrod/strategies/memorytwo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import itertools
import warnings
from typing import Dict, Tuple
from typing import Dict, Optional, Tuple

from axelrod.action import Action
from axelrod.player import Player
Expand Down Expand Up @@ -55,7 +55,7 @@ class MemoryTwoPlayer(Player):
}

def __init__(
self, sixteen_vector: Tuple[float, ...] = None, initial: Action = C
self, sixteen_vector: Tuple[float, ...] = None, initial: Optional[Action] = None
) -> None:
"""
Parameters
Expand All @@ -67,6 +67,8 @@ def __init__(
The initial 2 moves
"""
super().__init__()
if initial is None:
initial = C
self._initial = initial
self.set_initial_sixteen_vector(sixteen_vector)

Expand All @@ -76,8 +78,6 @@ def set_initial_sixteen_vector(self, sixteen_vector):
warnings.warn("Memory two player is set to default, Cooperator.")

self.set_sixteen_vector(sixteen_vector)
if self.name == "Generic Memory Two Player":
self.name = "%s: %s" % (self.name, sixteen_vector)

def set_sixteen_vector(self, sixteen_vector: Tuple):
if not all(0 <= p <= 1 for p in sixteen_vector):
Expand Down Expand Up @@ -127,7 +127,7 @@ class AON2(MemoryTwoPlayer):

In [Hilbe2017]_ the following vectors are reported as "equivalent" to AON2
with their respective self-cooperation rate (note that these are not the same):

1. [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], self-cooperation
rate: 0.952
2. [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], self-cooperation
Expand Down
29 changes: 0 additions & 29 deletions axelrod/tests/strategies/test_memoryone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
C, D = axl.Action.C, axl.Action.D


class TestGenericPlayerOne(unittest.TestCase):
"""A class to test the naming and classification of generic memory one
players."""

p1 = axl.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
p2 = axl.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
p3 = axl.MemoryOnePlayer(four_vector=(1, 0.5, 1, 0.5))

def test_name(self):
self.assertEqual(self.p1.name, "Generic Memory One Player: (0, 0, 0, 0)")
self.assertEqual(self.p2.name, "Generic Memory One Player: (1, 0, 1, 0)")
self.assertEqual(self.p3.name, "Generic Memory One Player: (1, 0.5, 1, 0.5)")

def test_stochastic_classification(self):
self.assertFalse(axl.Classifiers["stochastic"](self.p1))
self.assertFalse(axl.Classifiers["stochastic"](self.p2))
self.assertTrue(axl.Classifiers["stochastic"](self.p3))


class TestWinStayLoseShift(TestPlayer):

name = "Win-Stay Lose-Shift: C"
Expand Down Expand Up @@ -292,11 +273,6 @@ class TestGenericReactiveStrategy(unittest.TestCase):
p2 = axl.ReactivePlayer(probabilities=(1, 0))
p3 = axl.ReactivePlayer(probabilities=(1, 0.5))

def test_name(self):
self.assertEqual(self.p1.name, "Reactive Player: (0, 0)")
self.assertEqual(self.p2.name, "Reactive Player: (1, 0)")
self.assertEqual(self.p3.name, "Reactive Player: (1, 0.5)")

def test_four_vector(self):
self.assertEqual(
self.p1._four_vector, {(C, D): 0.0, (D, C): 0.0, (C, C): 0.0, (D, D): 0.0}
Expand All @@ -308,11 +284,6 @@ def test_four_vector(self):
self.p3._four_vector, {(C, D): 0.5, (D, C): 1.0, (C, C): 1.0, (D, D): 0.5}
)

def test_stochastic_classification(self):
self.assertFalse(axl.Classifiers["stochastic"](self.p1))
self.assertFalse(axl.Classifiers["stochastic"](self.p2))
self.assertTrue(axl.Classifiers["stochastic"](self.p3))

def test_subclass(self):
self.assertIsInstance(self.p1, MemoryOnePlayer)
self.assertIsInstance(self.p2, MemoryOnePlayer)
Expand Down
63 changes: 1 addition & 62 deletions axelrod/tests/strategies/test_memorytwo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,6 @@
C, D = axl.Action.C, axl.Action.D


class TestGenericPlayerTwo(unittest.TestCase):
"""A class to test the naming and classification of generic memory two
players."""

p1 = MemoryTwoPlayer(
sixteen_vector=(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
)
p2 = MemoryTwoPlayer(
sixteen_vector=(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
)
p3 = MemoryTwoPlayer(
sixteen_vector=(
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
)
)
p4 = MemoryTwoPlayer(
sixteen_vector=(0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.5, 0, 0.6, 0, 0.7, 0, 0.8, 0)
)

def test_name(self):
self.assertEqual(
self.p1.name,
"Generic Memory Two Player: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",
)
self.assertEqual(
self.p2.name,
"Generic Memory Two Player: (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)",
)
self.assertEqual(
self.p3.name,
"Generic Memory Two Player: (0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)",
)
self.assertEqual(
self.p4.name,
"Generic Memory Two Player: (0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.5, 0, 0.6, 0, 0.7, 0, 0.8, 0)",
)

def test_deterministic_classification(self):
self.assertFalse(axl.Classifiers["stochastic"](self.p1))
self.assertFalse(axl.Classifiers["stochastic"](self.p2))

def test_stochastic_classification(self):
self.assertTrue(axl.Classifiers["stochastic"](self.p3))
self.assertTrue(axl.Classifiers["stochastic"](self.p4))


class TestMemoryTwoPlayer(unittest.TestCase):
def test_default_if_four_vector_not_set(self):
player = MemoryTwoPlayer()
Expand Down Expand Up @@ -142,7 +81,7 @@ def test_exception_if_probability_vector_outside_valid_values(self):

class TestMemoryStochastic(TestPlayer):
name = (
"Generic Memory Two Player: (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1): C"
"Generic Memory Two Player"
)
player = axl.MemoryTwoPlayer
expected_classifier = {
Expand Down