Skip to content

Commit 87b101d

Browse files
mojonesmartin
authored andcommitted
added start-move-dependent tests
1 parent 246b4c8 commit 87b101d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

axelrod/tests/unit/test_lookerup.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,36 @@ def test_defector_table(self):
4040
self.player = lambda : axelrod.LookerUp(defector_table)
4141
self.responses_test([C,C], [C,C], [D])
4242
self.responses_test([C,D], [D,C], [D])
43-
self.responses_test([D,D], [D,D], [D])
43+
self.responses_test([D,D], [D,D], [D])
44+
45+
def test_starting_move(self):
46+
"""A lookup table that always repeats the opponent's first move"""
47+
48+
first_move_table = {
49+
# if oppponent started by cooperating
50+
('C', 'C', 'D') : 'C',
51+
('C', 'D', 'D') : 'C',
52+
('C', 'C', 'C') : 'C',
53+
('C', 'D', 'C') : 'C',
54+
55+
# if opponent started by defecting
56+
('D', 'C', 'D') : 'D',
57+
('D', 'D', 'D') : 'D',
58+
('D', 'C', 'C') : 'D',
59+
('D', 'D', 'C') : 'D',
60+
}
61+
62+
self.player = lambda : axelrod.LookerUp(first_move_table)
63+
64+
# if the opponent started by cooperating, we should always cooperate
65+
self.responses_test([C,C,C], [C,C,C], [C])
66+
self.responses_test([D,D,D], [C,C,C], [C])
67+
self.responses_test([C,C,C], [C,D,C], [C])
68+
self.responses_test([C,C,D], [C,D,C], [C])
69+
70+
# if the opponent started by defecting, we should always defect
71+
self.responses_test([C,C,C], [D,C,C], [D])
72+
self.responses_test([D,D,D], [D,C,C], [D])
73+
self.responses_test([C,C,C], [D,D,C], [D])
74+
self.responses_test([C,C,D], [D,D,C], [D])
75+

0 commit comments

Comments
 (0)