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))
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)
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 )
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))
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"))
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"))
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" ), )
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" ), )
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)
def test_dictionary_property_returns_new_dict_object(self): table = LookupTable(lookup_dict=self.lookup_dict) self.assertIsNot(table.dictionary, table.dictionary)
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))
def test_equality_true(self): table_a = LookupTable(self.lookup_dict) table_b = LookupTable(self.lookup_dict) self.assertTrue(table_a.__eq__(table_b))
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)
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)
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))