1- import filecmp
21import unittest
32
3+ import filecmp
4+
45from hypothesis import given , settings
56
6- import axelrod
7+ import axelrod as axl
78from axelrod .strategy_transformers import FinalTransformer
89from axelrod .tests .property import tournaments
910
1011
1112class TestTournament (unittest .TestCase ):
1213 @classmethod
1314 def setUpClass (cls ):
14- cls .game = axelrod .Game ()
15+ cls .game = axl .Game ()
1516 cls .players = [
16- axelrod .Cooperator (),
17- axelrod .TitForTat (),
18- axelrod .Defector (),
19- axelrod .Grudger (),
20- axelrod .GoByMajority (),
17+ axl .Cooperator (),
18+ axl .TitForTat (),
19+ axl .Defector (),
20+ axl .Grudger (),
21+ axl .GoByMajority (),
2122 ]
2223 cls .player_names = [str (p ) for p in cls .players ]
2324 cls .test_name = "test"
@@ -33,7 +34,7 @@ def setUpClass(cls):
3334 cls .expected_outcome .sort ()
3435
3536 @given (tournaments (
36- strategies = axelrod .short_run_time_strategies ,
37+ strategies = axl .short_run_time_strategies ,
3738 min_size = 10 ,
3839 max_size = 30 ,
3940 min_turns = 2 ,
@@ -51,7 +52,7 @@ def test_big_tournaments(self, tournament):
5152 )
5253
5354 def test_serial_play (self ):
54- tournament = axelrod .Tournament (
55+ tournament = axl .Tournament (
5556 name = self .test_name ,
5657 players = self .players ,
5758 game = self .game ,
@@ -63,7 +64,7 @@ def test_serial_play(self):
6364 self .assertEqual (actual_outcome , self .expected_outcome )
6465
6566 def test_parallel_play (self ):
66- tournament = axelrod .Tournament (
67+ tournament = axl .Tournament (
6768 name = self .test_name ,
6869 players = self .players ,
6970 game = self .game ,
@@ -78,12 +79,12 @@ def test_repeat_tournament_deterministic(self):
7879 """A test to check that tournament gives same results."""
7980 deterministic_players = [
8081 s ()
81- for s in axelrod .short_run_time_strategies
82+ for s in axl .short_run_time_strategies
8283 if not s ().classifier ["stochastic" ]
8384 ]
8485 files = []
8586 for _ in range (2 ):
86- tournament = axelrod .Tournament (
87+ tournament = axl .Tournament (
8788 name = "test" ,
8889 players = deterministic_players ,
8990 game = self .game ,
@@ -100,13 +101,13 @@ def test_repeat_tournament_stochastic(self):
100101 """
101102 files = []
102103 for _ in range (2 ):
103- axelrod .seed (0 )
104+ axl .seed (0 )
104105 stochastic_players = [
105106 s ()
106- for s in axelrod .short_run_time_strategies
107+ for s in axl .short_run_time_strategies
107108 if s ().classifier ["stochastic" ]
108109 ]
109- tournament = axelrod .Tournament (
110+ tournament = axl .Tournament (
110111 name = "test" ,
111112 players = stochastic_players ,
112113 game = self .game ,
@@ -121,14 +122,14 @@ def test_repeat_tournament_stochastic(self):
121122class TestNoisyTournament (unittest .TestCase ):
122123 def test_noisy_tournament (self ):
123124 # Defector should win for low noise
124- players = [axelrod .Cooperator (), axelrod .Defector ()]
125- tournament = axelrod .Tournament (players , turns = 5 , repetitions = 3 , noise = 0.0 )
125+ players = [axl .Cooperator (), axl .Defector ()]
126+ tournament = axl .Tournament (players , turns = 5 , repetitions = 3 , noise = 0.0 )
126127 results = tournament .play (progress_bar = False )
127128 self .assertEqual (results .ranked_names [0 ], "Defector" )
128129
129130 # If the noise is large enough, cooperator should win
130- players = [axelrod .Cooperator (), axelrod .Defector ()]
131- tournament = axelrod .Tournament (players , turns = 5 , repetitions = 3 , noise = 0.75 )
131+ players = [axl .Cooperator (), axl .Defector ()]
132+ tournament = axl .Tournament (players , turns = 5 , repetitions = 3 , noise = 0.75 )
132133 results = tournament .play (progress_bar = False )
133134 self .assertEqual (results .ranked_names [0 ], "Cooperator" )
134135
@@ -138,10 +139,10 @@ def test_players_do_not_know_match_length(self):
138139 """Create two players who should cooperate on last two turns if they
139140 don't know when those last two turns are.
140141 """
141- p1 = FinalTransformer (["D" , "D" ])(axelrod .Cooperator )()
142- p2 = FinalTransformer (["D" , "D" ])(axelrod .Cooperator )()
142+ p1 = FinalTransformer (["D" , "D" ])(axl .Cooperator )()
143+ p2 = FinalTransformer (["D" , "D" ])(axl .Cooperator )()
143144 players = [p1 , p2 ]
144- tournament = axelrod .Tournament (players , prob_end = 0.5 , repetitions = 1 )
145+ tournament = axl .Tournament (players , prob_end = 0.5 , repetitions = 1 )
145146 results = tournament .play (progress_bar = False )
146147 # Check that both plays always cooperated
147148 for rating in results .cooperating_rating :
@@ -152,12 +153,12 @@ def test_matches_have_different_length(self):
152153 A match between two players should have variable length across the
153154 repetitions
154155 """
155- p1 = axelrod .Cooperator ()
156- p2 = axelrod .Cooperator ()
157- p3 = axelrod .Cooperator ()
156+ p1 = axl .Cooperator ()
157+ p2 = axl .Cooperator ()
158+ p3 = axl .Cooperator ()
158159 players = [p1 , p2 , p3 ]
159- axelrod .seed (0 )
160- tournament = axelrod .Tournament (players , prob_end = 0.5 , repetitions = 2 )
160+ axl .seed (0 )
161+ tournament = axl .Tournament (players , prob_end = 0.5 , repetitions = 2 )
161162 results = tournament .play (progress_bar = False )
162163 # Check that match length are different across the repetitions
163164 self .assertNotEqual (results .match_lengths [0 ], results .match_lengths [1 ])
0 commit comments