def test_or(self): a, b, c = Qbit("a"), Qbit("b"), Qbit("c") exp = OrConst(a, b, c, label="or") model = exp.compile() self.assertTrue(model.energy({"a": 1, "b": 1, "c": 1}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 1, "b": 0, "c": 1}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 0, "b": 1, "c": 1}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 0, "b": 0, "c": 0}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 1, "b": 1, "c": 0}, vartype="BINARY") > 0) self.assertTrue(model.energy({"a": 1, "b": 0, "c": 0}, vartype="BINARY") > 0) self.assertTrue(model.energy({"a": 0, "b": 1, "c": 0}, vartype="BINARY") > 0) self.assertTrue(model.energy({"a": 0, "b": 0, "c": 1}, vartype="BINARY") > 0)
def test_equality(self): xor1 = XorConst(Binary("a"), Binary("b"), Binary("c"), label="xor") xor2 = XorConst(Binary("a"), Binary("b"), Binary("c"), label="xor") xor3 = XorConst(Binary("b"), Binary("c"), Binary("a"), label="xor") or1 = OrConst(Binary("a"), Binary("b"), Binary("c"), label="xor") self.assertTrue(xor1 + 1 == xor2 + 1) self.assertTrue(xor1 == xor2) self.assertFalse(xor1 == or1) self.assertFalse(xor1 == xor3)