|
| 1 | +"""Tests for the adaptor""" |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +import axelrod |
| 6 | +from axelrod import Game |
| 7 | + |
| 8 | +from .test_player import TestPlayer, test_four_vector |
| 9 | + |
| 10 | +C, D = axelrod.Action.C, axelrod.Action.D |
| 11 | + |
| 12 | + |
| 13 | +class TestAdaptorBrief(TestPlayer): |
| 14 | + |
| 15 | + name = "AdaptorBrief" |
| 16 | + player = axelrod.AdaptorBrief |
| 17 | + expected_classifier = { |
| 18 | + "memory_depth": float("inf"), |
| 19 | + "stochastic": True, |
| 20 | + "makes_use_of": set(), |
| 21 | + "inspects_source": False, |
| 22 | + "manipulates_source": False, |
| 23 | + "manipulates_state": False, |
| 24 | + } |
| 25 | + |
| 26 | + def test_strategy(self): |
| 27 | + # No error. |
| 28 | + actions = [(C, C), (C, C), (C, C), (C, C)] |
| 29 | + self.versus_test( |
| 30 | + opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=0 |
| 31 | + ) |
| 32 | + |
| 33 | + # Error corrected. |
| 34 | + actions = [(C, C), (C, D), (D, C), (C, C)] |
| 35 | + self.versus_test( |
| 36 | + opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=22 |
| 37 | + ) |
| 38 | + |
| 39 | + # Error corrected, example 2 |
| 40 | + actions = [(D, C), (C, D), (D, C), (C, D), (C, C)] |
| 41 | + self.versus_test( |
| 42 | + opponent=axelrod.AdaptorBrief(), expected_actions=actions, seed=925 |
| 43 | + ) |
| 44 | + |
| 45 | + # Versus Cooperator |
| 46 | + actions = [(C, C)] * 8 |
| 47 | + self.versus_test( |
| 48 | + opponent=axelrod.Cooperator(), expected_actions=actions, seed=0 |
| 49 | + ) |
| 50 | + |
| 51 | + # Versus Defector |
| 52 | + actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, D), (D, D)] |
| 53 | + self.versus_test( |
| 54 | + opponent=axelrod.Defector(), expected_actions=actions, seed=0 |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +class TestAdaptorLong(TestPlayer): |
| 59 | + |
| 60 | + name = "AdaptorLong" |
| 61 | + player = axelrod.AdaptorLong |
| 62 | + expected_classifier = { |
| 63 | + "memory_depth": float("inf"), |
| 64 | + "stochastic": True, |
| 65 | + "makes_use_of": set(), |
| 66 | + "inspects_source": False, |
| 67 | + "manipulates_source": False, |
| 68 | + "manipulates_state": False, |
| 69 | + } |
| 70 | + |
| 71 | + def test_strategy(self): |
| 72 | + # No error. |
| 73 | + actions = [(C, C), (C, C), (C, C), (C, C)] |
| 74 | + self.versus_test( |
| 75 | + opponent=axelrod.AdaptorLong(), expected_actions=actions, seed=0 |
| 76 | + ) |
| 77 | + |
| 78 | + # Error corrected. |
| 79 | + actions = [(C, C), (C, D), (D, D), (C, C), (C, C)] |
| 80 | + self.versus_test( |
| 81 | + opponent=axelrod.AdaptorLong(), expected_actions=actions, seed=22 |
| 82 | + ) |
| 83 | + |
| 84 | + # Versus Cooperator |
| 85 | + actions = [(C, C)] * 8 |
| 86 | + self.versus_test( |
| 87 | + opponent=axelrod.Cooperator(), expected_actions=actions, seed=0 |
| 88 | + ) |
| 89 | + |
| 90 | + # Versus Defector |
| 91 | + actions = [(C, D), (D, D), (C, D), (D, D), (D, D), (C, D), (D, D)] |
| 92 | + self.versus_test( |
| 93 | + opponent=axelrod.Defector(), expected_actions=actions, seed=0 |
| 94 | + ) |
0 commit comments