Skip to content

Commit 08987ae

Browse files
committed
Fix a few more tests and cover some remaining lines
1 parent dcd9d92 commit 08987ae

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

axelrod/strategies/meta.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,6 @@ def _post_init(self):
563563
# deterministic, and we can avoid _random.
564564
if distribution:
565565
total = sum(distribution)
566-
if total == 0:
567-
return
568566
distribution = np.array(distribution) / total
569567
if 1 in distribution:
570568
self.index = list(distribution).index(1)

axelrod/tests/strategies/test_apavlov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_strategy_PavlovD(self):
7373
opponent, expected_actions=actions, attrs={"opponent_class": "PavlovD"}
7474
)
7575

76-
def test_strategy_PavlovD(self):
76+
def test_strategy_PavlovD2(self):
7777
"""Tests that PavolvD is identified by DDCDDC and that the response
7878
is D then C"""
7979
opponent = axl.MockPlayer(actions=[D, D, C, D, D, C, D])

axelrod/tests/strategies/test_evolvable_player.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class PartialedClass(cls):
1717
seed = kwargs["seed"]
1818
except KeyError:
1919
kwargs["seed"] = 1
20-
else:
21-
if seed is None:
22-
kwargs["seed"] = 1
2320
__init__ = functools.partialmethod(
2421
cls.__init__, **kwargs)
2522

@@ -65,7 +62,7 @@ def player(self, seed=1):
6562
if seed is None:
6663
raise Exception()
6764
params = self.init_parameters.copy()
68-
if "seed" not in params:
65+
if "seed" not in params: # pragma: no cover
6966
params["seed"] = seed
7067
return self.player_class(**params)
7168

axelrod/tests/strategies/test_finite_state_machines.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,13 @@ def test_create_vector_bounds(self):
10941094
self.assertEqual(lb, [0] * (4 * num_states + 1))
10951095
self.assertEqual(ub, [1] * (4 * num_states + 1))
10961096

1097+
def test_mutate(self):
1098+
"""Test to trigger random lines in mutate"""
1099+
for seed in [18, 22]:
1100+
player = axl.EvolvableFSMPlayer(
1101+
num_states=4, mutation_probability=0.5, seed=seed)
1102+
player.mutate()
1103+
10971104

10981105
class TestEvolvableFSMPlayer2(TestEvolvablePlayer):
10991106
name = "EvolvableFSMPlayer"

axelrod/tests/strategies/test_meta.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,21 @@ def test_strategy(self):
732732
# Test TitForTat behavior in first 15 turns
733733
opponent = axl.Cooperator()
734734
actions = list([(C, C)]) * 15
735-
self.versus_test(opponent, expected_actions=actions)
735+
self.versus_test(opponent, expected_actions=actions, seed=1)
736736

737737
opponent = axl.Defector()
738738
actions = [(C, D)] + list([(D, D)]) * 14
739-
self.versus_test(opponent, expected_actions=actions)
739+
self.versus_test(opponent, expected_actions=actions, seed=1)
740740

741741
opponent = axl.Alternator()
742742
actions = [(C, C)] + [(C, D), (D, C)] * 7
743-
self.versus_test(opponent, expected_actions=actions)
743+
self.versus_test(opponent, expected_actions=actions, seed=1)
744744

745745
opponent_actions = [C, D, D, C, D, C, C, D, C, D, D, C, C, D, D]
746746
opponent = axl.MockPlayer(actions=opponent_actions)
747747
mem_actions = [C, C, D, D, C, D, C, C, D, C, D, D, C, C, D]
748748
actions = list(zip(mem_actions, opponent_actions))
749-
self.versus_test(opponent, expected_actions=actions)
749+
self.versus_test(opponent, expected_actions=actions, seed=1)
750750

751751
def test_strategy2(self):
752752
opponent = axl.Random()
@@ -812,3 +812,14 @@ def test_alternative_starting_strategies(self):
812812
"start_strategy_duration": 0,
813813
},
814814
)
815+
816+
def test_memory_alter_delete(self):
817+
"""Trigger memory_alter and memory_delete."""
818+
opponent = axl.Cooperator()
819+
actions = list([(C, C)]) * 50
820+
self.versus_test(
821+
opponent,
822+
expected_actions=actions,
823+
init_kwargs={"start_strategy": axl.Cooperator},
824+
seed=11
825+
)

axelrod/tests/strategies/test_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def versus_test(
656656
for attr, value in attrs.items():
657657
self.assertEqual(getattr(player1, attr), value)
658658

659-
def search_seeds(self, *args, **kwargs):
659+
def search_seeds(self, *args, **kwargs): # pragma: no cover
660660
"""Search for a seed that will pass the test. To use to find a new seed
661661
for a versus_test, change self.versus_test to self.search_seeds
662662
within a TestPlayer or TestMatch class.

axelrod/tests/strategies/test_rand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_stochastic_behavior1(self):
3434
actions = [(C, C), (D, C), (D, C), (C, C)]
3535
self.versus_test(opponent, expected_actions=actions, seed=1)
3636

37-
def test_stochastic_behavior1(self):
37+
def test_stochastic_behavior2(self):
3838
opponent = axl.MockPlayer()
3939
actions = [(D, C), (C, C), (D, C)]
4040
self.versus_test(opponent, expected_actions=actions, seed=2)

0 commit comments

Comments
 (0)