@@ -24,23 +24,35 @@ class TestWorseAndWorse(TestPlayer):
24
24
25
25
def test_strategy (self ):
26
26
"""
27
- Test that the stratergy chooses to defect according to the correct
28
- probability.
27
+ Test that the strategy gives expected behaviour
29
28
"""
30
- if sys .version_info [0 ] == 2 :
31
- # Python 2.x
32
-
33
- self .responses_test ([], [], [D , C , C , D , D ], random_seed = 1 ,
34
- tournament_length = 5 )
35
-
36
- self .responses_test ([], [], [C , C , D , D , C ], random_seed = 2 ,
37
- tournament_length = 5 )
38
-
39
- elif sys .version_info [0 ] == 3 :
40
- # Python 3.x
41
-
42
- self .responses_test ([], [], [C , C , D , D , D ], random_seed = 1 ,
43
- tournament_length = 5 )
44
-
45
- self .responses_test ([], [], [D , D , D , D , D ], random_seed = 2 ,
46
- tournament_length = 5 )
29
+ axelrod .seed (1 )
30
+ opponent = axelrod .Cooperator ()
31
+ player = axelrod .WorseAndWorse ()
32
+ match = axelrod .Match ((opponent , player ), turns = 5 )
33
+ self .assertEqual (match .play (), [('C' , 'C' ),
34
+ ('C' , 'D' ),
35
+ ('C' , 'D' ),
36
+ ('C' , 'D' ),
37
+ ('C' , 'D' )])
38
+
39
+ # Test that behaviour does not depend on opponent
40
+ opponent = axelrod .Defector ()
41
+ player = axelrod .WorseAndWorse ()
42
+ axelrod .seed (1 )
43
+ match = axelrod .Match ((opponent , player ), turns = 5 )
44
+ self .assertEqual (match .play (), [('D' , 'C' ),
45
+ ('D' , 'D' ),
46
+ ('D' , 'D' ),
47
+ ('D' , 'D' ),
48
+ ('D' , 'D' )])
49
+
50
+ # Test that behaviour changes when does not know length.
51
+ axelrod .seed (1 )
52
+ match = axelrod .Match ((opponent , player ), turns = 5 ,
53
+ match_attributes = {'length' : float ('inf' )})
54
+ self .assertEqual (match .play (), [('D' , 'C' ),
55
+ ('D' , 'C' ),
56
+ ('D' , 'C' ),
57
+ ('D' , 'C' ),
58
+ ('D' , 'C' )])
0 commit comments