Skip to content

Commit 456d9d2

Browse files
committed
Adding test for alternator
1 parent 6f28c9f commit 456d9d2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

axelrod/tests/test_alternator.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Test for the alternator strategy
3+
"""
4+
import unittest
5+
import axelrod
6+
7+
class TestAlternator(unittest.TestCase):
8+
9+
def test_initial_strategy(self):
10+
"""
11+
Starts by cooperating
12+
"""
13+
P1 = axelrod.Alternator()
14+
P2 = axelrod.Player()
15+
self.assertEqual(P1.strategy(P2), 'C')
16+
17+
def test_effect_of_strategy(self):
18+
"""
19+
Simply does the opposite to what the strategy did last time
20+
"""
21+
P1 = axelrod.Alternator()
22+
P2 = axelrod.Player()
23+
P1.history = ['C', 'D', 'D', 'D']
24+
P2.history = ['C', 'C', 'C', 'C']
25+
self.assertEqual(P1.strategy(P2), 'C')
26+
P1.history = ['C', 'C', 'D', 'D', 'C']
27+
P2.history = ['C', 'D', 'C', 'C', 'C']
28+
self.assertEqual(P1.strategy(P2), 'D')
29+
30+
def test_representation(self):
31+
P1 = axelrod.Alternator()
32+
self.assertEqual(str(P1), 'Alternator')

0 commit comments

Comments
 (0)