|
1 | 1 | import unittest
|
2 | 2 |
|
3 |
| -import axelrod |
4 |
| -from axelrod.tests.property import * |
| 3 | +from axelrod import Action, Game |
| 4 | +from axelrod.tests.property import games |
5 | 5 |
|
6 | 6 | from hypothesis import given, settings
|
| 7 | +from hypothesis.strategies import integers |
7 | 8 |
|
8 |
| -C, D = axelrod.Action.C, axelrod.Action.D |
| 9 | +C, D = Action.C, Action.D |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class TestGame(unittest.TestCase):
|
12 |
| - @classmethod |
13 |
| - def setUpClass(cls): |
14 |
| - cls.game = axelrod.Game() |
15 | 13 |
|
16 |
| - def test_init(self): |
| 14 | + def test_default_scores(self): |
17 | 15 | expected_scores = {
|
18 | 16 | (C, D): (0, 5),
|
19 | 17 | (D, C): (5, 0),
|
20 | 18 | (D, D): (1, 1),
|
21 | 19 | (C, C): (3, 3),
|
22 | 20 | }
|
23 |
| - self.assertEqual(self.game.scores, expected_scores) |
| 21 | + self.assertEqual(Game().scores, expected_scores) |
24 | 22 |
|
25 |
| - def test_RPST(self): |
| 23 | + def test_default_RPST(self): |
26 | 24 | expected_values = (3, 1, 0, 5)
|
27 |
| - self.assertEqual(self.game.RPST(), expected_values) |
| 25 | + self.assertEqual(Game().RPST(), expected_values) |
28 | 26 |
|
29 |
| - def test_score(self): |
30 |
| - self.assertEqual(self.game.score((C, C)), (3, 3)) |
31 |
| - self.assertEqual(self.game.score((D, D)), (1, 1)) |
32 |
| - self.assertEqual(self.game.score((C, D)), (0, 5)) |
33 |
| - self.assertEqual(self.game.score((D, C)), (5, 0)) |
34 |
| - |
35 |
| - def test_equality(self): |
36 |
| - game_1 = Game(1, 2, 3, 4) |
37 |
| - game_2 = Game(1, 2, 3, 4) |
38 |
| - not_equal = Game() |
39 |
| - |
40 |
| - self.assertEqual(game_1, game_2) |
41 |
| - self.assertNotEqual(not_equal, game_1) |
| 27 | + def test_default_score(self): |
| 28 | + game = Game() |
| 29 | + self.assertEqual(game.score((C, C)), (3, 3)) |
| 30 | + self.assertEqual(game.score((D, D)), (1, 1)) |
| 31 | + self.assertEqual(game.score((C, D)), (0, 5)) |
| 32 | + self.assertEqual(game.score((D, C)), (5, 0)) |
42 | 33 |
|
| 34 | + def test_default_equality(self): |
43 | 35 | self.assertEqual(Game(), Game())
|
44 | 36 |
|
| 37 | + def test_not_default_equality(self): |
| 38 | + self.assertEqual(Game(1, 2, 3, 4), Game(1, 2, 3, 4)) |
| 39 | + self.assertNotEqual(Game(1, 2, 3, 4), Game(1, 2, 3, 5)) |
| 40 | + self.assertNotEqual(Game(1, 2, 3, 4), Game()) |
| 41 | + |
| 42 | + def test_wrong_class_equality(self): |
45 | 43 | self.assertNotEqual(Game(), "wrong class")
|
46 | 44 |
|
47 | 45 | @given(r=integers(), p=integers(), s=integers(), t=integers())
|
48 | 46 | @settings(max_examples=5, max_iterations=20)
|
49 |
| - def test_property_init(self, r, p, s, t): |
50 |
| - """Use the hypothesis library to test init""" |
| 47 | + def test_random_init(self, r, p, s, t): |
| 48 | + """Test init with random scores using the hypothesis library.""" |
51 | 49 | expected_scores = {
|
52 | 50 | (C, D): (s, t),
|
53 | 51 | (D, C): (t, s),
|
54 | 52 | (D, D): (p, p),
|
55 | 53 | (C, C): (r, r),
|
56 | 54 | }
|
57 |
| - game = axelrod.Game(r, s, t, p) |
| 55 | + game = Game(r, s, t, p) |
58 | 56 | self.assertEqual(game.scores, expected_scores)
|
59 | 57 |
|
60 | 58 | @given(r=integers(), p=integers(), s=integers(), t=integers())
|
61 | 59 | @settings(max_examples=5, max_iterations=20)
|
62 |
| - def test_property_RPST(self, r, p, s, t): |
63 |
| - """Use the hypothesis library to test RPST""" |
64 |
| - game = axelrod.Game(r, s, t, p) |
| 60 | + def test_random_RPST(self, r, p, s, t): |
| 61 | + """Test RPST method with random scores using the hypothesis library.""" |
| 62 | + game = Game(r, s, t, p) |
65 | 63 | self.assertEqual(game.RPST(), (r, p, s, t))
|
66 | 64 |
|
67 | 65 | @given(r=integers(), p=integers(), s=integers(), t=integers())
|
68 | 66 | @settings(max_examples=5, max_iterations=20)
|
69 |
| - def test_property_score(self, r, p, s, t): |
70 |
| - """Use the hypothesis library to test score""" |
71 |
| - game = axelrod.Game(r, s, t, p) |
| 67 | + def test_random_score(self, r, p, s, t): |
| 68 | + """Test score method with random scores using the hypothesis library.""" |
| 69 | + game = Game(r, s, t, p) |
72 | 70 | self.assertEqual(game.score((C, C)), (r, r))
|
73 | 71 | self.assertEqual(game.score((D, D)), (p, p))
|
74 | 72 | self.assertEqual(game.score((C, D)), (s, t))
|
75 | 73 | self.assertEqual(game.score((D, C)), (t, s))
|
76 | 74 |
|
77 | 75 | @given(game=games())
|
78 | 76 | @settings(max_examples=5, max_iterations=20)
|
79 |
| - def test_repr(self, game): |
| 77 | + def test_random_repr(self, game): |
| 78 | + """Test repr with random scores using the hypothesis library.""" |
80 | 79 | expected_repr = "Axelrod game: (R,P,S,T) = {}".format(game.RPST())
|
81 | 80 | self.assertEqual(expected_repr, game.__repr__())
|
82 | 81 | self.assertEqual(expected_repr, str(game))
|
0 commit comments