|
1 | 1 | """Tests for the main tournament class."""
|
2 | 2 |
|
3 |
| -import unittest |
4 | 3 | import axelrod
|
5 | 4 | import logging
|
6 | 5 | import multiprocessing
|
| 6 | +import random |
| 7 | +import unittest |
7 | 8 |
|
8 | 9 | from hypothesis import given
|
9 |
| -from hypothesis.strategies import lists, sampled_from, Settings |
| 10 | +from hypothesis.strategies import integers, lists, sampled_from, Settings |
10 | 11 |
|
11 | 12 | try:
|
12 | 13 | # Python 3
|
@@ -104,23 +105,36 @@ def test_serial_play(self):
|
104 | 105 |
|
105 | 106 | @given(s=lists(sampled_from(axelrod.strategies),
|
106 | 107 | min_size=2, # Errors are returned is less than 2 strategies
|
107 |
| - max_size=10, unique=True), settings=Settings(max_examples=5)) |
108 |
| - def test_property_serial_play(self, s): |
| 108 | + max_size=5, unique=True), |
| 109 | + seed=integers(), |
| 110 | + settings=Settings(max_examples=10, |
| 111 | + timeout=0)) |
| 112 | + def test_property_serial_play(self, s, seed): |
109 | 113 | """Test serial play using hypothesis"""
|
110 | 114 | # Test that we get an instance of ResultSet
|
111 |
| - players = [strat() for strat in s] |
112 |
| - |
113 |
| - tournament = axelrod.Tournament( |
114 |
| - name=self.test_name, |
115 |
| - players=players, |
116 |
| - game=self.game, |
117 |
| - turns=200, |
118 |
| - repetitions=self.test_repetitions) |
119 |
| - results = tournament.play() |
120 |
| - self.assertIsInstance(results, axelrod.ResultSet) |
121 |
| - self.assertEqual(len(results.cooperation), len(players)) |
122 |
| - self.assertEqual(results.nplayers, len(players)) |
123 |
| - self.assertEqual(results.players, players) |
| 115 | + try: |
| 116 | + # Make test use a seed |
| 117 | + # Because of the given, if the test failed, Hypothesis would tell us |
| 118 | + # what seed it failed on... |
| 119 | + state = random.getstate() |
| 120 | + random.seed(seed) |
| 121 | + |
| 122 | + # The actual test |
| 123 | + players = [strat() for strat in s] |
| 124 | + |
| 125 | + tournament = axelrod.Tournament( |
| 126 | + name=self.test_name, |
| 127 | + players=players, |
| 128 | + game=self.game, |
| 129 | + turns=200, |
| 130 | + repetitions=self.test_repetitions) |
| 131 | + results = tournament.play() |
| 132 | + self.assertIsInstance(results, axelrod.ResultSet) |
| 133 | + self.assertEqual(len(results.cooperation), len(players)) |
| 134 | + self.assertEqual(results.nplayers, len(players)) |
| 135 | + self.assertEqual(results.players, players) |
| 136 | + finally: |
| 137 | + random.setstate(state) |
124 | 138 |
|
125 | 139 | def test_parallel_play(self):
|
126 | 140 | # Test that we get an instance of ResultSet
|
|
0 commit comments