def test_xor(self): ctx = Backward() ans = ctx.read("a ^ b") self.assertEqual(str(ans), "[xor((atom(a), atom(b)))]") ans = ctx.read("!a ^ b") self.assertEqual(str(ans), "[xor((not(atom(a)), atom(b)))]") ans = ctx.read("a ^ !b") self.assertEqual(str(ans), "[xor((atom(a), not(atom(b))))]") ans = ctx.read("a ^ b | c") self.assertEqual(str(ans), "[or((xor((atom(a), atom(b))), atom(c)))]")
def test_or(self): ctx = Backward() ans = ctx.read("a | b") self.assertEqual(str(ans), "[or((atom(a), atom(b)))]") ans = ctx.read("!a | b") self.assertEqual(str(ans), "[or((not(atom(a)), atom(b)))]") ans = ctx.read("a | !b") self.assertEqual(str(ans), "[or((atom(a), not(atom(b))))]") ans = ctx.read("a | b & c") self.assertEqual(str(ans), "[and((or((atom(a), atom(b))), atom(c)))]")
def test_empty(self): ctx = Backward() ans = ctx.read("") self.assertEqual(str(ans), "[]")
def test_not(self): ctx = Backward() ans = ctx.read("!a") self.assertEqual(str(ans), "[not(atom(a))]") ans = ctx.read("!a !b") self.assertEqual(str(ans), "[not(atom(a)), not(atom(b))]")
def test_atom(self): ctx = Backward() ans = ctx.read("a") self.assertEqual(str(ans), "[atom(a)]") ans = ctx.read("a b c") self.assertEqual(str(ans), "[atom(a), atom(b), atom(c)]")