@@ -24,10 +24,7 @@ def setUpClass(cls):
2424 cls .res_cooperators = cooperators .play ()
2525 cls .res_defector_wins = defector_wins .play ()
2626
27- def test_init (self ):
28- """Are the populations created correctly?"""
29-
30- # By default create populations of equal size
27+ def test_default_population_sizes (self ):
3128 eco = axelrod .Ecosystem (self .res_cooperators )
3229 pops = eco .population_sizes
3330 self .assertEqual (eco .num_players , 4 )
@@ -36,7 +33,7 @@ def test_init(self):
3633 self .assertAlmostEqual (sum (pops [0 ]), 1.0 )
3734 self .assertEqual (list (set (pops [0 ])), [0.25 ])
3835
39- # Can pass list of initial population distributions
36+ def test_non_default_population_sizes ( self ):
4037 eco = axelrod .Ecosystem (self .res_cooperators , population = [.7 , .25 , .03 , .02 ])
4138 pops = eco .population_sizes
4239 self .assertEqual (eco .num_players , 4 )
@@ -45,7 +42,7 @@ def test_init(self):
4542 self .assertAlmostEqual (sum (pops [0 ]), 1.0 )
4643 self .assertEqual (pops [0 ], [.7 , .25 , .03 , .02 ])
4744
48- # Distribution will automatically normalise
45+ def test_population_normalization ( self ):
4946 eco = axelrod .Ecosystem (self .res_cooperators , population = [70 , 25 , 3 , 2 ])
5047 pops = eco .population_sizes
5148 self .assertEqual (eco .num_players , 4 )
@@ -54,22 +51,20 @@ def test_init(self):
5451 self .assertAlmostEqual (sum (pops [0 ]), 1.0 )
5552 self .assertEqual (pops [0 ], [.7 , .25 , .03 , .02 ])
5653
57- # If passed list is of incorrect size get error
54+ def test_results_and_population_of_different_sizes ( self ):
5855 self .assertRaises (TypeError , axelrod .Ecosystem , self .res_cooperators ,
5956 population = [.7 , .2 , .03 , .1 , .1 ])
6057
61- # If passed list has negative values
58+ def test_negative_populations ( self ):
6259 self .assertRaises (TypeError , axelrod .Ecosystem , self .res_cooperators ,
6360 population = [.7 , - .2 , .03 , .2 ])
6461
65- def test_fitness (self ):
62+ def test_fitness_function (self ):
6663 fitness = lambda p : 2 * p
6764 eco = axelrod .Ecosystem (self .res_cooperators , fitness = fitness )
6865 self .assertTrue (eco .fitness (10 ), 20 )
6966
70- def test_cooperators (self ):
71- """Are cooperators stable over time?"""
72-
67+ def test_cooperators_are_stable_over_time (self ):
7368 eco = axelrod .Ecosystem (self .res_cooperators )
7469 eco .reproduce (100 )
7570 pops = eco .population_sizes
@@ -79,9 +74,7 @@ def test_cooperators(self):
7974 self .assertEqual (sum (p ), 1.0 )
8075 self .assertEqual (list (set (p )), [0.25 ])
8176
82- def test_defector_wins (self ):
83- """Does one defector win over time?"""
84-
77+ def test_defector_wins_with_only_cooperators (self ):
8578 eco = axelrod .Ecosystem (self .res_defector_wins )
8679 eco .reproduce (1000 )
8780 pops = eco .population_sizes
0 commit comments