Skip to content

Commit

Permalink
Merge pull request #716 from marcharper/634
Browse files Browse the repository at this point in the history
Fix prober tests in conjunction with test_reponses and attrs
  • Loading branch information
meatballs authored Sep 19, 2016
2 parents 5c3c981 + b2941f1 commit 4de9c7a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 32 deletions.
2 changes: 1 addition & 1 deletion axelrod/strategies/prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class RemorsefulProber(NaiveProber):

name = 'Remorseful Prober'
classifier = {
'memory_depth': 2, # It remembers if it's previous move was random
'memory_depth': 2, # It remembers if its previous move was random
'stochastic': True,
'makes_use_of': set(),
'long_run_time': False,
Expand Down
1 change: 0 additions & 1 deletion axelrod/tests/unit/test_apavlov.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def test_strategy(self):
opponent.history.append(C)
self.assertEqual(player.strategy(opponent), C)


self.responses_test([C, C, C, C, C, D], [C, C, C, C, D, D], [D],
attrs={"opponent_class": "Random"})
self.responses_test([C, D, D, C, C, C], [D, D, C, C, C, C], [D],
Expand Down
11 changes: 4 additions & 7 deletions axelrod/tests/unit/test_averagecopier.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ def test_strategy(self):
self.responses_test([], [], [D], random_seed=2)

def test_when_oppenent_all_Cs(self):
"""
Tests that if opponent has played all C then player chooses C
"""
"""Tests that if opponent has played all C then player chooses C."""
self.responses_test([C, C, C, C], [C, C, C, C], [C, C, C],
random_seed=5)

def test_when_opponent_all_Ds(self):
"""
Tests that if opponent has played all D then player chooses D
"""
self.responses_test([C, C, C, C], [D, D, D, D], [D, D, D], random_seed=5)
"""Tests that if opponent has played all D then player chooses D."""
self.responses_test([C, C, C, C], [D, D, D, D], [D, D, D],
random_seed=5)


class TestNiceAverageCopier(TestPlayer):
Expand Down
1 change: 0 additions & 1 deletion axelrod/tests/unit/test_axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class TestFeld(TestPlayer):
'manipulates_state': False
}


def test_strategy(self):
self.first_play_test(C)
# Test retaliate
Expand Down
40 changes: 18 additions & 22 deletions axelrod/tests/unit/test_prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class TestRemorsefulProber(TestPlayer):
}

def test_strategy(self):
"Randomly defects (probes) and always retaliates like tit for tat."
"""Randomly defects (probes) and always retaliates like tit for tat."""
self.first_play_test(C)

player = self.player(0.4)
Expand All @@ -192,32 +192,22 @@ def test_strategy(self):
opponent.history = [C, D]
self.assertEqual(player.strategy(opponent), D)

def test_random_defection(self):
# Random defection
player = self.player(0.4)
opponent = axelrod.Random()
test_responses(self, player, opponent, [C], [C], [D], random_seed=1)

def test_remorse(self):
"""After probing, if opponent retaliates, will offer a C"""
"""After probing, if opponent retaliates, will offer a C."""
player = self.player(0.4)
opponent = axelrod.Random()
opponent = axelrod.Cooperator()

random.seed(0)
player.history = [C]
opponent.history = [C]
self.assertEqual(player.strategy(opponent), D) # Random defection
self.assertEqual(player.probing, True)
test_responses(self, player, opponent, [C], [C], [C],
random_seed=0, attrs={'probing': False})

player.history = [C, D]
opponent.history = [C, D]
self.assertEqual(player.strategy(opponent), C) # Remorse
self.assertEqual(player.probing, False)
test_responses(self, player, opponent, [C], [C], [D],
random_seed=1, attrs={'probing': True})

player.history = [C, D, C]
opponent.history = [C, D, D]
self.assertEqual(player.strategy(opponent), D)
self.assertEqual(player.probing, False)
test_responses(self, player, opponent, [C, D], [C, D], [D],
attrs={'probing': False})

test_responses(self, player, opponent, [C, D, C], [C, D, D], [D],
attrs={'probing': False})

def test_reduction_to_TFT(self):
player = self.player(0)
Expand All @@ -236,3 +226,9 @@ def test_reset_probing(self):
player.probing = True
player.reset()
self.assertFalse(player.probing)

def test_random_defection(self):
# Random defection
player = self.player(0.4)
opponent = axelrod.Random()
test_responses(self, player, opponent, [C], [C], [D], random_seed=1)

0 comments on commit 4de9c7a

Please sign in to comment.