Skip to content

Commit

Permalink
Add a particular test.
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Aug 6, 2017
1 parent 712c3ac commit 5e51cf3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/axelrod_dojo/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial
from itertools import repeat
from multiprocessing import Pool
from multiprocessing import Pool, cpu_count
from operator import itemgetter
from random import randrange
from statistics import mean, pstdev
Expand Down Expand Up @@ -168,6 +168,8 @@ def __init__(self, params_class, params_args, size, objective, output_filename,
bottleneck=None, opponents=None, processes=1, weights=None):
self.params_class = params_class
self.bottleneck = bottleneck
if processes == 0:
processes = cpu_count()
self.pool = Pool(processes=processes)
self.outputer = Outputer(output_filename, mode='a')
self.size = size
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/test_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,38 @@ def test_score_with_weights(self):
self.assertIsInstance(parameters, dojo.FSMParams)

self.assertEqual(best[0].__repr__(), best_params)

def test_score_with_particular_players(self):
"""
These are players that are known to be difficult to pickle
"""
name = "score"
turns = 10
noise = 0
repetitions = 5
num_states = 2
mutation_rate = .1
opponents = [axl.ThueMorse(),
axl.MetaHunter(),
axl.BackStabber(),
axl.Alexei()]
size = 10

objective = dojo.prepare_objective(name=name,
turns=turns,
noise=noise,
repetitions=repetitions)

population = dojo.Population(params_class=dojo.FSMParams,
params_args=(num_states, mutation_rate),
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
bottleneck=2,
processes=0)

generations = 4
axl.seed(0)
population.run(generations)
self.assertEqual(population.generation, 4)

0 comments on commit 5e51cf3

Please sign in to comment.