@@ -47,10 +47,13 @@ class TestDefectorHunter(TestPlayer):
47
47
48
48
def test_strategy (self ):
49
49
self .first_play_test (C )
50
- for i in range (3 ):
51
- self .responses_test ([C ], [C ] * i , [D ] * i )
52
- self .responses_test ([D ], [C ] * 4 , [D ] * 4 )
53
50
51
+ actions = [(C , D )] * 4 + [(D , D )] * 10
52
+ self .versus_test (opponent = axelrod .Defector (), expected_actions = actions )
53
+
54
+ actions = [(C , C )] * 14
55
+ self .versus_test (opponent = axelrod .Cooperator (),
56
+ expected_actions = actions )
54
57
55
58
class TestCooperatorHunter (TestPlayer ):
56
59
@@ -67,10 +70,13 @@ class TestCooperatorHunter(TestPlayer):
67
70
}
68
71
69
72
def test_strategy (self ):
70
- self .first_play_test (C )
71
- for i in range (3 ):
72
- self .responses_test ([C ], [C ] * i , [C ] * i )
73
- self .responses_test ([D ], [C ] * 4 , [C ] * 4 )
73
+ actions = [(C , C )] * 4 + [(D , C )] * 10
74
+ self .versus_test (opponent = axelrod .Cooperator (),
75
+ expected_actions = actions )
76
+
77
+ actions = [(C , D )] * 14
78
+ self .versus_test (opponent = axelrod .Defector (),
79
+ expected_actions = actions )
74
80
75
81
76
82
class TestAlternatorHunter (TestPlayer ):
@@ -89,14 +95,13 @@ class TestAlternatorHunter(TestPlayer):
89
95
90
96
def test_strategy (self ):
91
97
self .first_play_test (C )
92
- self .responses_test ([C ], [C ] * 2 , [C , D ], attrs = {'is_alt' : False })
93
- self .responses_test ([C ], [C ] * 3 , [C , D , C ], attrs = {'is_alt' : False })
94
- self .responses_test ([C ], [C ] * 4 , [C , D ] * 2 , attrs = {'is_alt' : False })
95
- self .responses_test ([C ], [C ] * 5 , [C , D ] * 2 + [C ],
96
- attrs = {'is_alt' : False })
97
- self .responses_test ([D ], [C ] * 6 , [C , D ] * 3 , attrs = {'is_alt' : True })
98
- self .responses_test ([D ], [C ] * 7 , [C , D ] * 3 + [C ],
99
- attrs = {'is_alt' : True })
98
+ actions = [(C , C ), (C , D )] * 3 + [(D , C ), (D , D )] * 5
99
+ self .versus_test (opponent = axelrod .Alternator (),
100
+ expected_actions = actions , attrs = {'is_alt' : True })
101
+
102
+ actions = [(C , D )] * 14
103
+ self .versus_test (opponent = axelrod .Defector (),
104
+ expected_actions = actions , attrs = {'is_alt' : False })
100
105
101
106
def test_reset_attr (self ):
102
107
p = self .player ()
@@ -200,7 +205,9 @@ class TestMathConstantHunter(TestPlayer):
200
205
}
201
206
202
207
def test_strategy (self ):
203
- self .responses_test ([D ], [C ] * 8 , [C ] * 7 + [D ])
208
+ opponent = axelrod .MockPlayer ([C ] * 7 + [D ] * 3 )
209
+ actions = [(C , C )] * 7 + [(C , D )]
210
+ self .versus_test (opponent = opponent , expected_actions = actions )
204
211
205
212
206
213
class TestRandomHunter (TestPlayer ):
@@ -220,16 +227,15 @@ class TestRandomHunter(TestPlayer):
220
227
def test_strategy (self ):
221
228
222
229
# We should catch the alternator here.
223
- self .responses_test ([D ], [C ] * 12 , [C , D ] * 6 )
224
-
225
- # It is still possible for this test to fail, but very unlikely.
226
- history1 = [C ] * 100
227
- history2 = [random .choice ([C , D ]) for i in range (100 )]
228
- self .responses_test (D , history1 , history2 )
229
-
230
- history1 = [D ] * 100
231
- history2 = [random .choice ([C , D ]) for i in range (100 )]
232
- self .responses_test (D , history1 , history2 )
230
+ actions = [(C , C ), (C , D )] * 5 + [(C , C ), (D , D ), (D , C )]
231
+ self .versus_test (opponent = axelrod .Alternator (),
232
+ expected_actions = actions , attrs = {"countCC" : 5 ,
233
+ "countDD" : 0 })
234
+
235
+ actions = [(C , D )] * 14
236
+ self .versus_test (opponent = axelrod .Defector (),
237
+ expected_actions = actions , attrs = {"countCC" : 0 ,
238
+ "countDD" : 0 })
233
239
234
240
def test_reset (self ):
235
241
player = self .player ()
0 commit comments