def test_simplify_deduplicate(self): "Test deduplicate" clause = ('x', '=', 'x') another = ('y', '=', 'y') third = ('z', '=', 'z') tests = [ ([], []), (['OR', []], []), (['AND', []], []), ([clause], [clause]), (['OR', clause], [clause]), ([clause, clause], [clause]), (['OR', clause, clause], [clause]), ([clause, [clause, clause]], [clause]), ([clause, another], [clause, another]), (['OR', clause, another], ['OR', clause, another]), ([clause, clause, another], [clause, another]), ([clause, [clause, clause], another], [clause, another]), ([clause, clause, another, another], [clause, another]), ([clause, another, clause, another], [clause, another]), (['AND', ['OR', clause, another], third], ['AND', ['OR', clause, another], third]), ] for input, expected in tests: with self.subTest(input=input): self.assertEqual(simplify(input), expected)
def test_simplify(self): domain = [['x', '=', 3]] self.assertEqual(simplify(domain), [['x', '=', 3]]) domain = [[['x', '=', 3]]] self.assertEqual(simplify(domain), [['x', '=', 3]]) domain = ['OR', ['x', '=', 3]] self.assertEqual(simplify(domain), [['x', '=', 3]]) domain = ['OR', [['x', '=', 3]], [['y', '=', 5]]] self.assertEqual(simplify(domain), ['OR', [['x', '=', 3]], [['y', '=', 5]]]) domain = ['OR', ['x', '=', 3], ['AND', ['y', '=', 5]]] self.assertEqual(simplify(domain), ['OR', ['x', '=', 3], [['y', '=', 5]]]) domain = ['AND'] self.assertEqual(simplify(domain), []) domain = ['OR'] self.assertEqual(simplify(domain), [])