1
1
# -*- coding: utf-8 -*-
2
2
import unittest
3
3
import tempfile
4
+ from collections import Counter
4
5
import axelrod
5
6
import axelrod .interaction_utils as iu
6
7
@@ -17,6 +18,14 @@ class TestMatch(unittest.TestCase):
17
18
winners = [False , 0 , 1 , None ]
18
19
cooperations = [(1 , 1 ), (0 , 2 ), (2 , 1 ), None ]
19
20
normalised_cooperations = [(.5 , .5 ), (0 , 1 ), (1 , .5 ), None ]
21
+ state_distribution = [Counter ({('C' , 'D' ): 1 , ('D' , 'C' ): 1 }),
22
+ Counter ({('D' , 'C' ): 2 }),
23
+ Counter ({('C' , 'C' ): 1 , ('C' , 'D' ): 1 }),
24
+ None ]
25
+ normalised_state_distribution = [Counter ({('C' , 'D' ): 0.5 , ('D' , 'C' ): 0.5 }),
26
+ Counter ({('D' , 'C' ): 1.0 }),
27
+ Counter ({('C' , 'C' ): 0.5 , ('C' , 'D' ): 0.5 }),
28
+ None ]
20
29
sparklines = [ u'█ \n █' , u' \n ██' , u'██\n █ ' , None ]
21
30
22
31
@@ -46,6 +55,14 @@ def test_compute_normalised_cooperations(self):
46
55
for inter , coop in zip (self .interactions , self .normalised_cooperations ):
47
56
self .assertEqual (coop , iu .compute_normalised_cooperation (inter ))
48
57
58
+ def test_compute_state_distribution (self ):
59
+ for inter , dist in zip (self .interactions , self .state_distribution ):
60
+ self .assertEqual (dist , iu .compute_state_distribution (inter ))
61
+
62
+ def test_compute_normalised_state_distribution (self ):
63
+ for inter , dist in zip (self .interactions , self .normalised_state_distribution ):
64
+ self .assertEqual (dist , iu .compute_normalised_state_distribution (inter ))
65
+
49
66
def test_compute_sparklines (self ):
50
67
for inter , spark in zip (self .interactions , self .sparklines ):
51
68
self .assertEqual (spark , iu .compute_sparklines (inter ))
0 commit comments