Skip to content

Commit a33ff3d

Browse files
committed
More test improvements and PEP8
1 parent 4c75add commit a33ff3d

27 files changed

+265
-233
lines changed

axelrod/tests/unit/test_actions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def test_action_values(self):
1212
self.assertEqual(D, 'D')
1313
self.assertNotEqual(D, 'd')
1414
self.assertNotEqual(C, 'c')
15+
self.assertNotEqual(D, 0)
16+
self.assertNotEqual(C, 1)
1517
self.assertNotEqual(C, D)
1618

1719
def test_flip_action(self):

axelrod/tests/unit/test_adaptive.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TestAdaptive(TestPlayer):
2222

2323
def test_strategy(self):
2424
# Test initial play sequence
25-
self.responses_test([C] * 6 + [D] * 5, [], [])
25+
self.responses_test([C] * 6 + [D] * 5)
2626

2727
def test_scoring(self):
2828
player = axelrod.Adaptive()
@@ -42,18 +42,21 @@ def test_rounds(self):
4242
self.versus_test(axelrod.Adaptive(), axelrod.Cooperator(),
4343
[C] * 6 + [D] * 5 + [D] * 3, [C] * 14)
4444

45+
4546
class TestAdaptivevsDefector(TestMatch):
4647
"""Test TFT vs WSLS"""
4748
def test_rounds(self):
4849
self.versus_test(axelrod.Adaptive(), axelrod.Defector(),
4950
[C] * 6 + [D] * 5 + [D] * 3, [D] * 14)
5051

52+
5153
class TestAdaptivevsAlternator(TestMatch):
5254
"""Test TFT vs WSLS"""
5355
def test_rounds(self):
5456
self.versus_test(axelrod.Adaptive(), axelrod.Alternator(),
5557
[C] * 6 + [D] * 5 + [D] * 3, [C, D] * 7)
5658

59+
5760
class TestAdaptivevsTFT(TestMatch):
5861
"""Test TFT vs WSLS"""
5962
def test_rounds(self):

axelrod/tests/unit/test_apavlov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Test APavlov."""
1+
"""Tests APavlov strategies."""
22

33
import axelrod
44
from .test_player import TestPlayer

axelrod/tests/unit/test_axelrod_first.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Test for the First Axelrod strategies."""
1+
"""Tests for the First Axelrod strategies."""
22

33
import random
44

@@ -41,8 +41,8 @@ def test_strategy(self):
4141
# (after 10 rounds)
4242
self.responses_test([C], [C, D, D, D], [C, C, C, C])
4343
self.responses_test([C], [C, C, D, D, D], [C, D, C, C, C])
44-
self.responses_test([D], [C] * 10 + [C, C, D, D, D], [C] * 10 +
45-
[C, D, C, C, C])
44+
self.responses_test([D], [C] * 10 + [C, C, D, D, D],
45+
[C] * 10 + [C, D, C, C, C])
4646

4747

4848
class TestRevisedDowning(TestPlayer):
@@ -141,8 +141,7 @@ class TestGrofman(TestPlayer):
141141
}
142142

143143
def test_strategy(self):
144-
self.responses_test([C, C])
145-
self.responses_test([C], [C, C], [C, C])
144+
self.responses_test([C, C, C])
146145
self.responses_test([D], [C, C], [C, D])
147146
self.responses_test([C], [C] * 6, [C] * 6)
148147
self.responses_test([D], [C] * 6, [D] * 6)
@@ -210,8 +209,7 @@ def test_score_history(self):
210209
def test_strategy(self):
211210
# Test TFT-type initial play
212211
self.first_play_test(C)
213-
self.responses_test([C], [C], [C])
214-
self.responses_test([C], [C, C], [C, C])
212+
self.responses_test([C, C], [C], [C])
215213
self.responses_test([D], [C], [D])
216214
self.responses_test([D], [C, D], [D, C])
217215
self.responses_test([D], [C, D], [D, D])

axelrod/tests/unit/test_axelrod_second.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Test for the Second Axelrod strategies."""
1+
"""Tests for the Second Axelrod strategies."""
22

33
import random
44

@@ -72,8 +72,7 @@ def test_strategy(self):
7272
# Initially cooperates
7373
self.first_play_test(C)
7474
# Test cooperate after opponent cooperates
75-
self.responses_test([C], [C], [C])
76-
self.responses_test([C], [C, C], [C, C])
75+
self.responses_test([C, C], [C], [C])
7776
self.responses_test([C], [D, C], [D, C])
7877
self.responses_test([C], [D, C, C], [D, C, C])
7978
# Test defection after opponent defection

axelrod/tests/unit/test_backstabber.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for BackStabber."""
1+
"""Tests for BackStabber and DoubleCrosser."""
22
import axelrod
33
from .test_player import TestPlayer
44

@@ -28,21 +28,17 @@ def test_strategy(self):
2828
self.first_play_test(C)
2929

3030
# Forgives three defections
31-
self.responses_test([C], [C], [D], tournament_length=200)
32-
self.responses_test([C], [C, C], [D, D], tournament_length=200)
33-
self.responses_test([C], [C, C, C], [D, D, D], tournament_length=200)
34-
self.responses_test([D], [C, C, C, C], [D, D, D, D],
35-
tournament_length=200)
31+
self.responses_test([C], [C], [D], length=200)
32+
self.responses_test([C], [C, C], [D, D], length=200)
33+
self.responses_test([C], [C, C, C], [D, D, D], length=200)
34+
self.responses_test([D], [C, C, C, C], [D, D, D, D], length=200)
3635

3736
# Defects on rounds 199, and 200 no matter what
38-
self.responses_test([C, D, D], [C] * 197, [C] * 197,
39-
tournament_length=200)
37+
self.responses_test([C, D, D], [C] * 197, [C] * 197, length=200)
4038
# Test that exceeds tournament length
41-
self.responses_test([D, D, C], [C] * 198, [C] * 198,
42-
tournament_length=200)
39+
self.responses_test([D, D, C], [C] * 198, [C] * 198, length=200)
4340
# But only if the tournament is known
44-
self.responses_test([C, C, C], [C] * 198, [C] * 198,
45-
tournament_length=-1)
41+
self.responses_test([C, C, C], [C] * 198, [C] * 198, length=-1)
4642

4743

4844
class TestDoubleCrosser(TestPlayer):
@@ -70,18 +66,16 @@ def test_strategy(self):
7066
self.first_play_test(C)
7167

7268
# Forgives three defections
73-
self.responses_test([C], [C], [D], tournament_length=200)
74-
self.responses_test([C], [C, C], [D, D], tournament_length=200)
75-
self.responses_test([C], [C, C, C], [D, D, D], tournament_length=200)
76-
self.responses_test([D], [C, C, C, C], [D, D, D, D],
77-
tournament_length=200)
69+
self.responses_test([C], [C], [D], length=200)
70+
self.responses_test([C], [C, C], [D, D], length=200)
71+
self.responses_test([C], [C, C, C], [D, D, D], length=200)
72+
self.responses_test([D], [C, C, C, C], [D, D, D, D], length=200)
7873

7974
# If opponent did not defect in the first six rounds, cooperate until
8075
# round 180
81-
self.responses_test([C] * 174, [C] * 6, [C] * 6, tournament_length=200)
76+
self.responses_test([C] * 174, [C] * 6, [C] * 6, length=200)
8277
self.responses_test([C] * 160, [C] * 12, [C] * 6 + [D] + [C] * 5,
83-
tournament_length=200)
78+
length=200)
8479

8580
# Defects on rounds 199, and 200 no matter what
86-
self.responses_test([C, D, D], [C] * 197, [C] * 197,
87-
tournament_length=200)
81+
self.responses_test([C, D, D], [C] * 197, [C] * 197, length=200)

axelrod/tests/unit/test_better_and_better.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ class TestBetterAndBetter(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
"""
25-
Test that the strategy gives expected behaviour
26-
"""
27-
28-
self.responses_test([D, D, D, D, C, D, D, D, D, D], [], [],
29-
seed=6)
30-
self.responses_test([D, D, D, D, D, D, D, D, D, D], [], [],
31-
seed=8)
24+
"""Tests that the strategy gives expected behaviour."""
25+
self.first_play_test(D, seed=3) # D is very unlikely
26+
self.responses_test([D, D, D, D, C, D, D, D, D, D], seed=6)
27+
self.responses_test([D, D, D, D, D, D, D, D, D, D], seed=8)

0 commit comments

Comments
 (0)