Пример #1
0
 def test_exception_if_probability_vector_outside_valid_values(self):
     player = MemoryTwoPlayer()
     x = 2
     with self.assertRaises(ValueError):
         player.set_sixteen_vector(
             [
                 0.1,
                 x,
                 0.5,
                 0.1,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.2,
                 0.5,
                 0.2,
             ]
         )
Пример #2
0
 def test_exception_if_probability_vector_outside_valid_values(self):
     player = MemoryTwoPlayer()
     x = 2
     with self.assertRaises(ValueError):
         player.set_sixteen_vector(
             [
                 0.1,
                 x,
                 0.5,
                 0.1,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.2,
                 0.5,
                 0.1,
                 0.2,
                 0.5,
                 0.2,
             ]
         )
Пример #3
0
class TestGenericPlayerTwo(unittest.TestCase):
    """A class to test the naming and classification of generic memory two
    players."""
    p1 = MemoryTwoPlayer(sixteen_vector=(0, 0, 0, 0, 0, 0, 0, 0,
                                         0, 0, 0, 0, 0, 0, 0, 0))
    p2 = MemoryTwoPlayer(sixteen_vector=(1, 0, 1, 0, 1, 0, 1, 0,
                                         1, 0, 1, 0, 1, 0, 1, 0))
    p3 = MemoryTwoPlayer(sixteen_vector=(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
                                         0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5))
    p4 = MemoryTwoPlayer(sixteen_vector=(0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0,
                                         0.5, 0, 0.6, 0, 0.7, 0, 0.8, 0))

    def test_name(self):
        self.assertEqual(self.p1.name,
                         "Generic Memory Two Player: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)")
        self.assertEqual(self.p2.name,
                         "Generic Memory Two Player: (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)")
        self.assertEqual(self.p3.name,
                         "Generic Memory Two Player: (0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)")
        self.assertEqual(self.p4.name,
                         "Generic Memory Two Player: (0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.5, 0, 0.6, 0, 0.7, 0, 0.8, 0)")

    def test_deterministic_classification(self):
        self.assertFalse(self.p1.classifier['stochastic'])
        self.assertFalse(self.p2.classifier['stochastic'])

    def test_stochastic_classification(self):
        self.assertTrue(self.p3.classifier['stochastic'])
        self.assertTrue(self.p4.classifier['stochastic'])
Пример #4
0
    def test_exception_if_four_vector_not_set(self):
        with warnings.catch_warnings(record=True) as warning:
            warnings.simplefilter("always")
            player = MemoryTwoPlayer()

            self.assertEqual(len(warning), 1)
            self.assertEqual(warning[-1].category, UserWarning)
            self.assertEqual(str(warning[-1].message),
                             "Memory two player is set to default, Cooperator.")
Пример #5
0
 def test_default_if_four_vector_not_set(self):
     player = MemoryTwoPlayer()
     self.assertEqual(player._sixteen_vector,
                      {((C, C), (C, C)): 1.0, ((C, C), (C, D)): 1.0,
                       ((C, D), (C, C)): 1.0, ((C, D), (C, D)): 1.0,
                       ((C, C), (D, C)): 1.0, ((C, C), (D, D)): 1.0,
                       ((C, D), (D, C)): 1.0, ((C, D), (D, D)): 1.0,
                       ((D, C), (C, C)): 1.0, ((D, C), (C, D)): 1.0,
                       ((D, D), (C, C)): 1.0, ((D, D), (C, D)): 1.0,
                       ((D, C), (D, C)): 1.0, ((D, C), (D, D)): 1.0,
                       ((D, D), (D, C)): 1.0, ((D, D), (D, D)): 1.0})