def testSatisfyConstraints4(self):
        h = HandInformation(hand_size=2, possible_cards=set(range(6)))
        h.addConstraint([0, 1, 2])
        h.addConstraint([0, 2, 3])
        h.addConstraint([0, 4, 5])

        hands = h.satisfyConstraints()

        self.assertEqual(len(hands), 3)
        # Hand order doesn't technically matter, but I've assumed an order.
        # Solutions computed by hand.

        # Hand 0, Card 0, all other cards allowed
        assertCardConstraints(self, hands[0], required_cards=[0])

        # Hand 1, Cards 2 and 4, but 0 not allowed
        assertCardConstraints(self,
                              hands[1],
                              required_cards=[2, 4],
                              missing_cards=[0])

        # Hand 2, Cards 2 and 5 allowed, but 0 and 4 not allowed
        assertCardConstraints(self,
                              hands[2],
                              required_cards=[2, 5],
                              missing_cards=[0, 4])
    def testSatisfyConstraintsImpossibleConstraint(self):
        h = HandInformation(hand_size=1, possible_cards=set(range(6)))
        h.addKnownCard(0)
        h.addConstraint([1, 2])

        hands = h.satisfyConstraints()
        self.assertEqual(len(hands), 0)
    def testSatisfyConstraintsNoConstraints(self):
        # This test ensures that a hand with no constraints returns itself.

        h = HandInformation(hand_size=2)

        hands = h.satisfyConstraints()

        self.assertEqual(len(hands), 1)
        self.assertEqual(hands[0], h)
    def testSatisfyConstraintsSatisfiedConstraint(self):
        # This test ensures that a satisifed constraint is not processed.
        h = HandInformation(hand_size=2, possible_cards=set(range(6)))
        h.addKnownCard(0)
        h.addConstraint([0, 1, 2])

        hands = h.satisfyConstraints()

        self.assertEqual(len(hands), 1)
        self.assertEqual(hands[0].hand_size, h.hand_size)
        self.assertEqual(hands[0].known_cards, h.known_cards)
        self.assertEqual(hands[0].possible_cards, h.possible_cards)
    def testSatisfyConstraintsCheckHands(self):
        # This test ensures that the list of possible hands match between
        # the original hand and the list of sub-hands.

        h = HandInformation(hand_size=3, possible_cards=set(range(10)))
        h.addConstraint([0, 1, 2])

        possible_hands_sol = h.getPossibleHands()

        hands = h.satisfyConstraints()
        possible_hands_test = []
        for hand in hands:
            possible_hands_test.extend(hand.getPossibleHands())

        self.assertEqual(len(possible_hands_test), len(possible_hands_sol))

        for hand in possible_hands_test:
            self.assertTrue(hand in possible_hands_sol)
    def testSatisfyConstraints3(self):
        h = HandInformation(hand_size=2, possible_cards=set(range(6)))
        h.addConstraint([0, 1, 2])
        h.addConstraint([0, 2, 3])

        hands = h.satisfyConstraints()
        self.assertEqual(len(hands), 3)
        # Note that hand order technically doesn't matter, but I've matched
        # the order here for ease of testing.

        # Hand 0, Card 0, all other cards allowed
        assertCardConstraints(self, hands[0], required_cards=[0])

        # Hand 1, Card 2, but no card 0
        assertCardConstraints(self,
                              hands[1],
                              required_cards=[2],
                              missing_cards=[0])

        # Hand 2, Cards 3 and 1, but no cards 0 or 2
        assertCardConstraints(self,
                              hands[2],
                              required_cards=[1, 3],
                              missing_cards=[0, 2])