def test_not_equals_one_two(self):
        self.function = expr.And(self.pos, expr.exprvar("b"),
                                 ~expr.Or(*self.neg))

        cardinality = constraint.equals_one(self.function.support)
        sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one()
        self.assertIsNone(sat)
    def test_equals_one(self, function):
        cardinality_a = constraint.equals_one(function.support)
        sat_a = expr.And(function, *cardinality_a).to_cnf().satisfy_one()

        cardinality_b = constraint.equals(function.support, 1)
        sat_b = expr.And(function, *cardinality_b).to_cnf().satisfy_one()

        self.assertEqual(sat_a is None, sat_b is None)
    def test_equals_one(self):
        self.function = self.pos

        cardinality = constraint.equals_one(self.function.support)
        sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one()

        self.assertIsNotNone(sat)
        self.assertEqual(sat.get(self.pos), 1)
    def test_not_equals_one_not_equivalent(self):
        self.function = ~expr.Or(*self.neg)

        equals = expr.exprvar("equals")
        cardinality = constraint.equals_one(self.function.support, ~equals)
        sat = expr.And(self.function, equals,
                       *cardinality).to_cnf().satisfy_one()

        self.assertIsNotNone(sat)
        self.assertEqual(sat.get(equals), 1)
    def test_equals_one_not_equivalent(self, function):
        equivalent = expr.exprvar("equivalent")

        cardinality_a = constraint.equals_one(function.support, ~equivalent)
        sat_a = expr.And(function, ~equivalent,
                         *cardinality_a).to_cnf().satisfy_one()

        cardinality_b = constraint.equals(function.support, 1, ~equivalent)
        sat_b = expr.And(function, ~equivalent,
                         *cardinality_b).to_cnf().satisfy_one()

        self.assertEqual(sat_a is None, sat_b is None)
        if sat_a or sat_b:
            self.assertEqual(sat_a.get(equivalent), sat_b.get(equivalent))