Skip to content

Commit 5e51cf3

Browse files
committed
Add a particular test.
1 parent 712c3ac commit 5e51cf3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/axelrod_dojo/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import partial
22
from itertools import repeat
3-
from multiprocessing import Pool
3+
from multiprocessing import Pool, cpu_count
44
from operator import itemgetter
55
from random import randrange
66
from statistics import mean, pstdev
@@ -168,6 +168,8 @@ def __init__(self, params_class, params_args, size, objective, output_filename,
168168
bottleneck=None, opponents=None, processes=1, weights=None):
169169
self.params_class = params_class
170170
self.bottleneck = bottleneck
171+
if processes == 0:
172+
processes = cpu_count()
171173
self.pool = Pool(processes=processes)
172174
self.outputer = Outputer(output_filename, mode='a')
173175
self.size = size

tests/integration/test_fsm.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,38 @@ def test_score_with_weights(self):
112112
self.assertIsInstance(parameters, dojo.FSMParams)
113113

114114
self.assertEqual(best[0].__repr__(), best_params)
115+
116+
def test_score_with_particular_players(self):
117+
"""
118+
These are players that are known to be difficult to pickle
119+
"""
120+
name = "score"
121+
turns = 10
122+
noise = 0
123+
repetitions = 5
124+
num_states = 2
125+
mutation_rate = .1
126+
opponents = [axl.ThueMorse(),
127+
axl.MetaHunter(),
128+
axl.BackStabber(),
129+
axl.Alexei()]
130+
size = 10
131+
132+
objective = dojo.prepare_objective(name=name,
133+
turns=turns,
134+
noise=noise,
135+
repetitions=repetitions)
136+
137+
population = dojo.Population(params_class=dojo.FSMParams,
138+
params_args=(num_states, mutation_rate),
139+
size=size,
140+
objective=objective,
141+
output_filename=self.temporary_file.name,
142+
opponents=opponents,
143+
bottleneck=2,
144+
processes=0)
145+
146+
generations = 4
147+
axl.seed(0)
148+
population.run(generations)
149+
self.assertEqual(population.generation, 4)

0 commit comments

Comments
 (0)