Repository: Axelrod-Python/Axelrod

Issue:
LimitedHistory should override extend.
[LimitedHistory](https://github.com/Axelrod-Python/Axelrod/blob/dev/axelrod/history.py#L107) inherits extend from [base class](https://github.com/Axelrod-Python/Axelrod/blob/dev/axelrod/history.py#L50).  However expected behavior is that LimitedHistory only keeps the last `memory_depth` history.

Should make this unittest on TestLimitedHistory pass.
```
    def test_extend(self):
        h1 = LimitedHistory(3, plays=[C, C, D], coplays=[C, C, C])
        self.assertEqual(list(h1), [C, C, D])
        h1.extend([C, C], [D, D])
        self.assertEqual(list(h1), [D, C, C])
```

Discussion:
drvinceknight: Thanks for this, it looks like the failure is due to a health check done by hypothesis:

```
  =================================== FAILURES ===================================
  _______________________ TestAsymmetricGame.test_equality _______________________
  
  self = <axelrod.tests.unit.test_game.TestAsymmetricGame testMethod=test_equality>
  
      @given(asymgame1=asymmetric_games(), asymgame2=asymmetric_games())
  >   @settings(max_examples=5)
  E   hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 2 valid examples in 1.04 seconds (0 invalid ones and 2 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters).
  E                 count | fraction |    slowest draws (seconds)
  E     asymgame1 |    4  |     63%  |      --   0.096,  0.169,  0.178,  0.208
  E     asymgame2 |    4  |     37%  |      --   0.044,  0.057,  0.091,  0.199
  E   See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.too_slow to the suppress_health_check settings for this test.
```

Could you try disabling the healthcheck (as it suggests in the traceback). If not we can take a look at that.
LindyZh: @drvinceknight The mentioned healthcheck was disabled and all checks have passed. Let me know if there's anything I could address/add!
gaffney2010: lgtm, thanks!
drvinceknight: Looks good to me! Thanks :)

Patch:
diff --git a/axelrod/history.py b/axelrod/history.py
index 12114399..0e914da7 100644
--- a/axelrod/history.py
+++ b/axelrod/history.py
@@ -117,8 +117,8 @@ class LimitedHistory(History):
         memory_depth, int:
             length of history to retain
         """
-        super().__init__(plays=plays, coplays=coplays)
         self.memory_depth = memory_depth
+        super().__init__(plays=plays, coplays=coplays)
 
     def flip_plays(self):
         """Creates a flipped plays history for use with DualTransformer."""
@@ -138,3 +138,11 @@ class LimitedHistory(History):
             first_play, first_coplay = self._plays.pop(0), self._coplays.pop(0)
             self._actions[first_play] -= 1
             self._state_distribution[(first_play, first_coplay)] -= 1
+
+    def extend(self, new_plays, new_coplays):
+        """A function that emulates list.extend, respecting the stated memory depth."""
+        self._plays.extend(new_plays)
+        self._coplays.extend(new_coplays)
+        if len(self._plays) > self.memory_depth:
+            self._plays = self._plays[-self.memory_depth :]
+            self._coplays = self._coplays[-self.memory_depth :]


Test patch:
diff --git a/axelrod/tests/unit/test_game.py b/axelrod/tests/unit/test_game.py
index 083431e2..e124c9e1 100644
--- a/axelrod/tests/unit/test_game.py
+++ b/axelrod/tests/unit/test_game.py
@@ -1,7 +1,7 @@
 import unittest
 
 import numpy as np
-from hypothesis import given, settings
+from hypothesis import HealthCheck, given, settings
 from hypothesis.extra.numpy import array_shapes, arrays
 from hypothesis.strategies import integers
 
@@ -123,7 +123,7 @@ class TestAsymmetricGame(unittest.TestCase):
         self.assertEqual(expected_repr, str(asymgame))
 
     @given(asymgame1=asymmetric_games(), asymgame2=asymmetric_games())
-    @settings(max_examples=5)
+    @settings(max_examples=5, suppress_health_check=(HealthCheck.too_slow,))
     def test_equality(self, asymgame1, asymgame2):
         """Tests equality of AsymmetricGames based on their matrices."""
         self.assertFalse(asymgame1 == "foo")
diff --git a/axelrod/tests/unit/test_history.py b/axelrod/tests/unit/test_history.py
index 7c3fa6ef..4907a2c2 100644
--- a/axelrod/tests/unit/test_history.py
+++ b/axelrod/tests/unit/test_history.py
@@ -123,3 +123,14 @@ class TestLimitedHistory(unittest.TestCase):
             h.state_distribution,
             Counter({(D, D): 1, (C, D): 1, (D, C): 1, (C, C): 0}),
         )
+
+    def test_extend(self):
+        h1 = LimitedHistory(3, plays=[C, C, D], coplays=[C, C, C])
+        self.assertEqual(list(h1), [C, C, D])
+        h1.extend([C, C], [D, D])
+        self.assertEqual(list(h1), [D, C, C])
+        h1.extend([D, C], [D, D])
+        self.assertEqual(list(h1), [C, D, C])
+        h1.memory_depth = 4
+        h1.extend([D, C], [D, D])
+        self.assertEqual(list(h1), [D, C, D, C])