Esempio n. 1
0
 def test_equality_false(self):
     table_a = LookupTable.from_pattern((C, D), 1, 0, 0)
     table_b = LookupTable.from_pattern((D, C), 1, 0, 0)
     table_c = LookupTable.from_pattern((C, D), 0, 1, 0)
     self.assertFalse(table_a.__eq__(table_b))
     self.assertFalse(table_a.__eq__(table_c))
     self.assertFalse(table_a.__eq__(table_a.dictionary))
Esempio n. 2
0
 def test_equality_false(self):
     table_a = LookupTable.from_pattern((C, D), 1, 0, 0)
     table_b = LookupTable.from_pattern((D, C), 1, 0, 0)
     table_c = LookupTable.from_pattern((C, D), 0, 1, 0)
     self.assertFalse(table_a.__eq__(table_b))
     self.assertFalse(table_a.__eq__(table_c))
     self.assertFalse(table_a.__eq__(table_a.dictionary))
Esempio n. 3
0
 def test_from_pattern_raises_error_pattern_len_ne_dict_size(self):
     too_big = (C, ) * 17
     too_small = (C, ) * 15
     just_right = (C, ) * 16
     with self.assertRaises(ValueError):
         LookupTable.from_pattern(too_big, 2, 2, 0)
     with self.assertRaises(ValueError):
         LookupTable.from_pattern(too_small, 2, 2, 0)
     self.assertIsInstance(LookupTable.from_pattern(just_right, 2, 2, 0),
                           LookupTable)
Esempio n. 4
0
 def test_from_pattern_raises_error_pattern_len_ne_dict_size(self):
     too_big = (C,) * 17
     too_small = (C,) * 15
     just_right = (C,) * 16
     with self.assertRaises(ValueError):
         LookupTable.from_pattern(too_big, 2, 2, 0)
     with self.assertRaises(ValueError):
         LookupTable.from_pattern(too_small, 2, 2, 0)
     self.assertIsInstance(
         LookupTable.from_pattern(just_right, 2, 2, 0), LookupTable
     )
Esempio n. 5
0
 def test_from_pattern(self):
     pattern = (C, D, D, C, C, D, D, C)
     table = LookupTable.from_pattern(pattern,
                                      player_depth=2,
                                      op_depth=1,
                                      op_openings_depth=0)
     self.assertEqual(table.dictionary,
                      make_keys_into_plays(self.lookup_dict))
Esempio n. 6
0
 def test_display_default(self):
     table = LookupTable.from_pattern((C, ) * 8,
                                      player_depth=2,
                                      op_depth=0,
                                      op_openings_depth=1)
     self.assertEqual(table.display(),
                      ("op_openings|self_plays | op_plays  \n" +
                       "     C     ,   C, C    ,           : C,\n" +
                       "     C     ,   C, D    ,           : C,\n" +
                       "     C     ,   D, C    ,           : C,\n" +
                       "     C     ,   D, D    ,           : C,\n" +
                       "     D     ,   C, C    ,           : C,\n" +
                       "     D     ,   C, D    ,           : C,\n" +
                       "     D     ,   D, C    ,           : C,\n" +
                       "     D     ,   D, D    ,           : C,\n"))
Esempio n. 7
0
 def test_display_assign_order(self):
     table = LookupTable.from_pattern((C, ) * 8,
                                      player_depth=0,
                                      op_depth=3,
                                      op_openings_depth=0)
     self.assertEqual(
         table.display(sort_by=('op_openings', 'op_plays', 'self_plays')),
         ("op_openings| op_plays  |self_plays \n" +
          "           ,  C, C, C  ,           : C,\n" +
          "           ,  C, C, D  ,           : C,\n" +
          "           ,  C, D, C  ,           : C,\n" +
          "           ,  C, D, D  ,           : C,\n" +
          "           ,  D, C, C  ,           : C,\n" +
          "           ,  D, C, D  ,           : C,\n" +
          "           ,  D, D, C  ,           : C,\n" +
          "           ,  D, D, D  ,           : C,\n"))
Esempio n. 8
0
 def test_display_assign_order(self):
     table = LookupTable.from_pattern(
         (C,) * 8, player_depth=0, op_depth=3, op_openings_depth=0
     )
     self.assertEqual(
         table.display(sort_by=("op_openings", "op_plays", "self_plays")),
         (
             "op_openings| op_plays  |self_plays \n"
             + "           ,  C, C, C  ,           : C,\n"
             + "           ,  C, C, D  ,           : C,\n"
             + "           ,  C, D, C  ,           : C,\n"
             + "           ,  C, D, D  ,           : C,\n"
             + "           ,  D, C, C  ,           : C,\n"
             + "           ,  D, C, D  ,           : C,\n"
             + "           ,  D, D, C  ,           : C,\n"
             + "           ,  D, D, D  ,           : C,\n"
         ),
     )
Esempio n. 9
0
 def test_display_default(self):
     table = LookupTable.from_pattern(
         (C,) * 8, player_depth=2, op_depth=0, op_openings_depth=1
     )
     self.assertEqual(
         table.display(),
         (
             "op_openings|self_plays | op_plays  \n"
             + "     C     ,   C, C    ,           : C,\n"
             + "     C     ,   C, D    ,           : C,\n"
             + "     C     ,   D, C    ,           : C,\n"
             + "     C     ,   D, D    ,           : C,\n"
             + "     D     ,   C, C    ,           : C,\n"
             + "     D     ,   C, D    ,           : C,\n"
             + "     D     ,   D, C    ,           : C,\n"
             + "     D     ,   D, D    ,           : C,\n"
         ),
     )
Esempio n. 10
0
    def test_init(self):

        table = LookupTable(self.lookup_dict)

        self.assertEqual(table.table_depth, 2)
        self.assertEqual(table.player_depth, 2)
        self.assertEqual(table.op_depth, 1)
        self.assertEqual(table.op_openings_depth, 0)
        self.assertEqual(
            table.dictionary, {
                Plays(self_plays=(C, C), op_plays=(C, ), op_openings=()): C,
                Plays(self_plays=(C, C), op_plays=(D, ), op_openings=()): D,
                Plays(self_plays=(C, D), op_plays=(C, ), op_openings=()): D,
                Plays(self_plays=(C, D), op_plays=(D, ), op_openings=()): C,
                Plays(self_plays=(D, C), op_plays=(C, ), op_openings=()): C,
                Plays(self_plays=(D, C), op_plays=(D, ), op_openings=()): D,
                Plays(self_plays=(D, D), op_plays=(C, ), op_openings=()): D,
                Plays(self_plays=(D, D), op_plays=(D, ), op_openings=()): C
            })
        self.assertIsInstance(next(iter(table.dictionary)), Plays)
Esempio n. 11
0
 def test_dictionary_property_returns_new_dict_object(self):
     table = LookupTable(lookup_dict=self.lookup_dict)
     self.assertIsNot(table.dictionary, table.dictionary)
Esempio n. 12
0
 def test_not_equal(self):
     table_a = LookupTable(self.lookup_dict)
     table_b = LookupTable(self.lookup_dict)
     not_equal = LookupTable.from_pattern((C, C), 1, 0, 0)
     self.assertFalse(table_a.__ne__(table_b))
     self.assertTrue(table_a.__ne__(not_equal))
Esempio n. 13
0
 def test_equality_true(self):
     table_a = LookupTable(self.lookup_dict)
     table_b = LookupTable(self.lookup_dict)
     self.assertTrue(table_a.__eq__(table_b))
Esempio n. 14
0
 def test_init_raises_error_keys_do_not_cover_all_combinations(self):
     lookup_dict = {((C, ), (C, ), ()): C, ((D, ), (D, ), ()): C}
     with self.assertRaises(ValueError):
         LookupTable(lookup_dict=lookup_dict)
Esempio n. 15
0
 def test_init_raises_error_when_keys_for_lookup_dict_do_not_match(self):
     lookup_dict = {((C, ), (C, ), ()): C, ((D, D), (D, D), ()): C}
     with self.assertRaises(ValueError):
         LookupTable(lookup_dict=lookup_dict)
Esempio n. 16
0
 def test_not_equal(self):
     table_a = LookupTable(self.lookup_dict)
     table_b = LookupTable(self.lookup_dict)
     not_equal = LookupTable.from_pattern((C, C), 1, 0, 0)
     self.assertFalse(table_a.__ne__(table_b))
     self.assertTrue(table_a.__ne__(not_equal))
Esempio n. 17
0
 def test_from_pattern(self):
     pattern = (C, D, D, C, C, D, D, C)
     table = LookupTable.from_pattern(
         pattern, player_depth=2, op_depth=1, op_openings_depth=0
     )
     self.assertEqual(table.dictionary, make_keys_into_plays(self.lookup_dict))
Esempio n. 18
0
 def test_equality_true(self):
     table_a = LookupTable(self.lookup_dict)
     table_b = LookupTable(self.lookup_dict)
     self.assertTrue(table_a.__eq__(table_b))