Skip to content

Commit 9fff017

Browse files
refactored import statements to 'import axelrod as axel' axelrod/tests/strategies/*
1 parent 92702ac commit 9fff017

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1450
-1421
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Tests for the Adaptive strategy."""
22

3-
import axelrod
3+
import axelrod as axl
44

55
from .test_player import TestMatch, TestPlayer
66

7-
C, D = axelrod.Action.C, axelrod.Action.D
7+
C, D = axl.Action.C, axl.Action.D
88

99

1010
class TestAdaptive(TestPlayer):
1111

1212
name = "Adaptive"
13-
player = axelrod.Adaptive
13+
player = axl.Adaptive
1414
expected_classifier = {
1515
"memory_depth": float("inf"),
1616
"stochastic": False,
@@ -23,24 +23,24 @@ class TestAdaptive(TestPlayer):
2323

2424
def test_strategy(self):
2525
actions = [(C, C)] * 6 + [(D, C)] * 8
26-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
26+
self.versus_test(axl.Cooperator(), expected_actions=actions)
2727

2828
actions = [(C, D)] * 6 + [(D, D)] * 8
29-
self.versus_test(axelrod.Defector(), expected_actions=actions)
29+
self.versus_test(axl.Defector(), expected_actions=actions)
3030

3131
actions = [(C, C), (C, D)] * 3 + [(D, C), (D, D)] * 4
32-
self.versus_test(axelrod.Alternator(), expected_actions=actions)
32+
self.versus_test(axl.Alternator(), expected_actions=actions)
3333

3434
actions = [(C, C)] * 6 + [(D, C)] + [(D, D)] * 4 + [(C, D), (C, C)]
35-
self.versus_test(axelrod.TitForTat(), expected_actions=actions)
35+
self.versus_test(axl.TitForTat(), expected_actions=actions)
3636

3737
def test_scoring(self):
38-
player = axelrod.Adaptive()
39-
opponent = axelrod.Cooperator()
38+
player = axl.Adaptive()
39+
opponent = axl.Cooperator()
4040
player.play(opponent)
4141
player.play(opponent)
4242
self.assertEqual(3, player.scores[C])
43-
game = axelrod.Game(-3, 10, 10, 10)
43+
game = axl.Game(-3, 10, 10, 10)
4444
player.set_match_attributes(game=game)
4545
player.play(opponent)
4646
self.assertEqual(0, player.scores[C])

axelrod/tests/strategies/test_adaptor.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
import unittest
44

5-
import axelrod
6-
from axelrod import Game
5+
import axelrod as axl
76

87
from .test_player import TestPlayer, test_four_vector
98

10-
C, D = axelrod.Action.C, axelrod.Action.D
9+
C, D = axl.Action.C, axl.Action.D
1110

1211

1312
class TestAdaptorBrief(TestPlayer):
1413

1514
name = "AdaptorBrief"
16-
player = axelrod.AdaptorBrief
15+
player = axl.AdaptorBrief
1716
expected_classifier = {
1817
"memory_depth": float("inf"),
1918
"stochastic": True,
@@ -27,38 +26,38 @@ def test_strategy(self):
2726
# No error.
2827
actions = [(C, C), (C, C), (C, C), (C, C)]
2928
self.versus_test(
30-
opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=0
29+
opponent=axl.AdaptorBrief(), expected_actions=actions, seed=0
3130
)
3231

3332
# Error corrected.
3433
actions = [(C, C), (C, D), (D, C), (C, C)]
3534
self.versus_test(
36-
opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=22
35+
opponent=axl.AdaptorBrief(), expected_actions=actions, seed=22
3736
)
3837

3938
# Error corrected, example 2
4039
actions = [(D, C), (C, D), (D, C), (C, D), (C, C)]
4140
self.versus_test(
42-
opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=925
41+
opponent=axl.AdaptorBrief(), expected_actions=actions, seed=925
4342
)
4443

4544
# Versus Cooperator
4645
actions = [(C, C)] * 8
4746
self.versus_test(
48-
opponent=axelrod.Cooperator(), expected_actions=actions, seed=0
47+
opponent=axl.Cooperator(), expected_actions=actions, seed=0
4948
)
5049

5150
# Versus Defector
5251
actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, D), (D, D)]
5352
self.versus_test(
54-
opponent=axelrod.Defector(), expected_actions=actions, seed=0
53+
opponent=axl.Defector(), expected_actions=actions, seed=0
5554
)
5655

5756

5857
class TestAdaptorLong(TestPlayer):
5958

6059
name = "AdaptorLong"
61-
player = axelrod.AdaptorLong
60+
player = axl.AdaptorLong
6261
expected_classifier = {
6362
"memory_depth": float("inf"),
6463
"stochastic": True,
@@ -72,23 +71,23 @@ def test_strategy(self):
7271
# No error.
7372
actions = [(C, C), (C, C), (C, C), (C, C)]
7473
self.versus_test(
75-
opponent=axelrod.AdaptorLong(), expected_actions=actions, seed=0
74+
opponent=axl.AdaptorLong(), expected_actions=actions, seed=0
7675
)
7776

7877
# Error corrected.
7978
actions = [(C, C), (C, D), (D, D), (C, C), (C, C)]
8079
self.versus_test(
81-
opponent=axelrod.AdaptorLong(), expected_actions=actions, seed=22
80+
opponent=axl.AdaptorLong(), expected_actions=actions, seed=22
8281
)
8382

8483
# Versus Cooperator
8584
actions = [(C, C)] * 8
8685
self.versus_test(
87-
opponent=axelrod.Cooperator(), expected_actions=actions, seed=0
86+
opponent=axl.Cooperator(), expected_actions=actions, seed=0
8887
)
8988

9089
# Versus Defector
9190
actions = [(C, D), (D, D), (C, D), (D, D), (D, D), (C, D), (D, D)]
9291
self.versus_test(
93-
opponent=axelrod.Defector(), expected_actions=actions, seed=0
92+
opponent=axl.Defector(), expected_actions=actions, seed=0
9493
)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Tests for the Alternator strategy."""
22

3-
import axelrod
3+
import axelrod as axl
44

55
from .test_player import TestPlayer
66

7-
C, D = axelrod.Action.C, axelrod.Action.D
7+
C, D = axl.Action.C, axl.Action.D
88

99

1010
class TestAlternator(TestPlayer):
1111

1212
name = "Alternator"
13-
player = axelrod.Alternator
13+
player = axl.Alternator
1414
expected_classifier = {
1515
"memory_depth": 1,
1616
"stochastic": False,
@@ -23,11 +23,11 @@ class TestAlternator(TestPlayer):
2323

2424
def test_strategy(self):
2525
actions = [(C, C), (D, C)] * 5
26-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
26+
self.versus_test(axl.Cooperator(), expected_actions=actions)
2727

2828
actions = [(C, D), (D, D)] * 5
29-
self.versus_test(axelrod.Defector(), expected_actions=actions)
29+
self.versus_test(axl.Defector(), expected_actions=actions)
3030

31-
opponent = axelrod.MockPlayer(actions=[D, C])
31+
opponent = axl.MockPlayer(actions=[D, C])
3232
actions = [(C, D), (D, C)] * 5
3333
self.versus_test(opponent, expected_actions=actions)

axelrod/tests/strategies/test_ann.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Tests for the ANN strategy."""
22
import unittest
33

4-
import axelrod
4+
import axelrod as axl
55
from axelrod.evolvable_player import InsufficientParametersError
66
from axelrod.load_data_ import load_weights
77
from axelrod.strategies.ann import split_weights
88
from .test_player import TestPlayer
99
from .test_evolvable_player import PartialClass, TestEvolvablePlayer
1010

1111

12-
C, D = axelrod.Action.C, axelrod.Action.D
12+
C, D = axl.Action.C, axl.Action.D
1313
nn_weights = load_weights()
1414
num_features, num_hidden, weights = nn_weights["Evolved ANN 5"]
1515

@@ -26,7 +26,7 @@ def test_split_weights(self):
2626
class TestEvolvedANN(TestPlayer):
2727

2828
name = "Evolved ANN"
29-
player = axelrod.EvolvedANN
29+
player = axl.EvolvedANN
3030
expected_classifier = {
3131
"memory_depth": float("inf"),
3232
"stochastic": False,
@@ -39,19 +39,19 @@ class TestEvolvedANN(TestPlayer):
3939

4040
def test_strategy(self):
4141
actions = [(C, C)] * 5
42-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
42+
self.versus_test(axl.Cooperator(), expected_actions=actions)
4343

4444
actions = [(C, D)] + [(D, D)] * 5
45-
self.versus_test(axelrod.Defector(), expected_actions=actions)
45+
self.versus_test(axl.Defector(), expected_actions=actions)
4646

4747
actions = [(C, C)] * 5
48-
self.versus_test(axelrod.TitForTat(), expected_actions=actions)
48+
self.versus_test(axl.TitForTat(), expected_actions=actions)
4949

5050

5151
class TestEvolvedANN5(TestPlayer):
5252

5353
name = "Evolved ANN 5"
54-
player = axelrod.EvolvedANN5
54+
player = axl.EvolvedANN5
5555
expected_classifier = {
5656
"memory_depth": float("inf"),
5757
"stochastic": False,
@@ -64,16 +64,16 @@ class TestEvolvedANN5(TestPlayer):
6464

6565
def test_strategy(self):
6666
actions = [(C, C)] * 5
67-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
67+
self.versus_test(axl.Cooperator(), expected_actions=actions)
6868

6969
actions = [(C, D)] + [(D, D)] * 4
70-
self.versus_test(axelrod.Defector(), expected_actions=actions)
70+
self.versus_test(axl.Defector(), expected_actions=actions)
7171

7272

7373
class TestEvolvedANNNoise05(TestPlayer):
7474

7575
name = "Evolved ANN 5 Noise 05"
76-
player = axelrod.EvolvedANNNoise05
76+
player = axl.EvolvedANNNoise05
7777
expected_classifier = {
7878
"memory_depth": float("inf"),
7979
"stochastic": False,
@@ -86,15 +86,15 @@ class TestEvolvedANNNoise05(TestPlayer):
8686

8787
def test_strategy(self):
8888
actions = [(C, C)] * 5
89-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
89+
self.versus_test(axl.Cooperator(), expected_actions=actions)
9090

9191
actions = [(C, D), (D, D), (D, D)]
92-
self.versus_test(axelrod.Defector(), expected_actions=actions)
92+
self.versus_test(axl.Defector(), expected_actions=actions)
9393

9494

9595
class TestEvolvableANN(unittest.TestCase):
9696

97-
player_class = axelrod.EvolvableANN
97+
player_class = axl.EvolvableANN
9898

9999
def test_normalized_parameters(self):
100100
# Must specify at least one of cycle or cycle_length
@@ -111,16 +111,16 @@ def test_normalized_parameters(self):
111111

112112
class TestEvolvableANN2(TestEvolvablePlayer):
113113
name = "EvolvableANN"
114-
player_class = axelrod.EvolvableANN
115-
parent_class = axelrod.ANN
114+
player_class = axl.EvolvableANN
115+
parent_class = axl.ANN
116116
parent_kwargs = ["num_features", "num_hidden", "weights"]
117117
init_parameters = {"num_features": 17, "num_hidden": 8}
118118

119119

120120
class TestEvolvableANN3(TestEvolvablePlayer):
121121
name = "EvolvableANN"
122-
player_class = axelrod.EvolvableANN
123-
parent_class = axelrod.ANN
122+
player_class = axl.EvolvableANN
123+
parent_class = axl.ANN
124124
parent_kwargs = ["num_features", "num_hidden", "weights"]
125125
init_parameters = {
126126
"num_features": nn_weights["Evolved ANN 5"][0],
@@ -131,7 +131,7 @@ class TestEvolvableANN3(TestEvolvablePlayer):
131131

132132
# Substitute EvolvableANN as a regular EvolvedANN5.
133133
EvolvableANNPlayerWithDefault = PartialClass(
134-
axelrod.EvolvableANN,
134+
axl.EvolvableANN,
135135
num_features=num_features,
136136
num_hidden=num_hidden,
137137
weights=weights

0 commit comments

Comments
 (0)