|
2 | 2 |
|
3 | 3 | import axelrod
|
4 | 4 |
|
5 |
| -from .test_player import TestPlayer |
| 5 | +from .test_player import TestPlayer, TestHeadsUp |
6 | 6 |
|
7 | 7 | C, D = axelrod.Actions.C, axelrod.Actions.D
|
8 | 8 |
|
@@ -105,3 +105,71 @@ def test_strategy(self):
|
105 | 105 | ('D', 'C'),
|
106 | 106 | ('D', 'C'),
|
107 | 107 | ('D', 'C')])
|
| 108 | + |
| 109 | + |
| 110 | +class TestWorseAndWorse2(TestPlayer): |
| 111 | + |
| 112 | + name = "Worse and Worse 2" |
| 113 | + player = axelrod.WorseAndWorse2 |
| 114 | + expected_classifier = { |
| 115 | + 'memory_depth': float('inf'), |
| 116 | + 'stochastic': True, |
| 117 | + 'makes_use_of': set(), |
| 118 | + 'long_run_time': False, |
| 119 | + 'inspects_source': False, |
| 120 | + 'manipulates_source': False, |
| 121 | + 'manipulates_state': False |
| 122 | + } |
| 123 | + |
| 124 | + def test_strategy(self): |
| 125 | + """ |
| 126 | + Test that the strategy gives expected behaviour |
| 127 | + """ |
| 128 | + |
| 129 | + # Test that first move is C |
| 130 | + self.first_play_test('C') |
| 131 | + |
| 132 | + # Test that given a history, next move matches opponent (round <= 20) |
| 133 | + self.responses_test([C], [C], [C]) |
| 134 | + self.responses_test([C, C], [C, D], [D]) |
| 135 | + self.responses_test([C] * 19, [C] * 19, [C]) |
| 136 | + self.responses_test([C] * 19, [C] * 18 + [D], [D]) |
| 137 | + |
| 138 | + # Test that after round 20, strategy follows stochastic behaviour given |
| 139 | + # a seed |
| 140 | + self.responses_test([C] * 20, [C] * 20, [C, D, C, C, C, C, D, C, C, C], random_seed=8) |
| 141 | + self.responses_test([C] * 20, [C] * 20, [D, D, C, C, D, C, C, C, C, C], random_seed=2) |
| 142 | + |
| 143 | + |
| 144 | +class TestWorseAndWorse3(TestPlayer): |
| 145 | + |
| 146 | + name = "Worse and Worse 3" |
| 147 | + player = axelrod.WorseAndWorse3 |
| 148 | + expected_classifier = { |
| 149 | + 'memory_depth': float('inf'), |
| 150 | + 'stochastic': True, |
| 151 | + 'makes_use_of': set(), |
| 152 | + 'long_run_time': False, |
| 153 | + 'inspects_source': False, |
| 154 | + 'manipulates_source': False, |
| 155 | + 'manipulates_state': False |
| 156 | + } |
| 157 | + |
| 158 | + def test_strategy(self): |
| 159 | + """ |
| 160 | + Test that the strategy gives expected behaviour |
| 161 | + """ |
| 162 | + |
| 163 | + # Test that first move is C |
| 164 | + self.first_play_test('C') |
| 165 | + |
| 166 | + # Test that if opponent only defects, strategy also defects |
| 167 | + self.responses_test([D] * 5, [D] * 5, [D]) |
| 168 | + |
| 169 | + # Test that if opponent only cooperates, strategy also cooperates |
| 170 | + self.responses_test([C] * 5, [C] * 5, [C]) |
| 171 | + |
| 172 | + # Test that given a non 0/1 probability of defecting, strategy follows |
| 173 | + # stochastic behaviour, given a seed |
| 174 | + self.responses_test([C] * 5, [C, D, C, D, C], [D, C, C, D, C, C, C, C, C, C], random_seed=8) |
| 175 | + self.responses_test([C] * 5, [D] * 5, [D, D, D, C, C, D, D, D, C, C], random_seed=2) |
0 commit comments