@@ -47,10 +47,13 @@ class TestDefectorHunter(TestPlayer):
4747
4848 def test_strategy (self ):
4949 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 )
5350
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 )
5457
5558class TestCooperatorHunter (TestPlayer ):
5659
@@ -67,10 +70,13 @@ class TestCooperatorHunter(TestPlayer):
6770 }
6871
6972 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 )
7480
7581
7682class TestAlternatorHunter (TestPlayer ):
@@ -89,14 +95,13 @@ class TestAlternatorHunter(TestPlayer):
8995
9096 def test_strategy (self ):
9197 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 })
100105
101106 def test_reset_attr (self ):
102107 p = self .player ()
@@ -200,7 +205,9 @@ class TestMathConstantHunter(TestPlayer):
200205 }
201206
202207 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 )
204211
205212
206213class TestRandomHunter (TestPlayer ):
@@ -220,16 +227,15 @@ class TestRandomHunter(TestPlayer):
220227 def test_strategy (self ):
221228
222229 # 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 })
233239
234240 def test_reset (self ):
235241 player = self .player ()
0 commit comments