示例#1
0
    def testHandsDifferentNumCards(self):

        cards = [
            Card(RED, 2),
            Card(YELLOW, 4),
            Card(GREEN, 3),
            Card(GREEN, "J"),
        ]
        hand1 = Hand()
        hand1.add_cards(cards)

        self.assertEqual(28, hand1.score)
        self.assertEqual(4, len(hand1))

        self.assertNotEqual(99, hand1.score)
        self.assertNotEqual(1, len(hand1))

        cards = [
            Card(RED, 3),
            Card(YELLOW, 3),
            Card(GREEN, 4),
        ]
        hand2 = Hand()
        hand2.add_cards(cards)

        self.assertEqual(19, hand2.score)
        self.assertEqual(3, len(hand2))

        self.assertNotEqual(99, hand2.score)
        self.assertNotEqual(1, len(hand2))

        ##################################################
        self.assertFalse(hand1.same_number_of_cards(hand2))
        self.assertFalse(hand2.same_number_of_cards(hand1))

        with self.assertRaises(ValueError):
            self.assertTrue(hand1 == hand2)

        with self.assertRaises(ValueError):
            self.assertTrue(hand1 != hand2)

        with self.assertRaises(ValueError):
            self.assertNotEqual(hand1, hand2)

        with self.assertRaises(ValueError):
            self.assertFalse(hand1 == hand2)

        with self.assertRaises(ValueError):
            self.assertTrue(hand1 != hand2)

        with self.assertRaises(ValueError):
            self.assertFalse(hand1.is_tie(hand2))

        with self.assertRaises(ValueError):
            self.assertFalse(hand1.is_winner(hand2))

        with self.assertRaises(ValueError):
            self.assertTrue(hand1.is_loser(hand2))
示例#2
0
    def testDeckTwoHandsMockDeal3(self):
        """
        Shuffle a clean deck twice, deal 2 hands,
        validate number of cards, score, and winner.

        Tests run with a mocked random number generator
        """

        deck = Deck.initialize_deck(num_cards=20, colors=[RED])
        deck.shuffler = Shuffler(0.3972)

        deck.shuffle()
        self.assertEqual(20, len(deck))

        deck.shuffle()
        self.assertEqual(20, len(deck))

        hand1 = Hand()
        hand2 = Hand()

        hand1.add_card(deck.deal_card())
        hand2.add_card(deck.deal_card())
        hand1.add_card(deck.deal_card())
        hand2.add_card(deck.deal_card())
        hand1.add_card(deck.deal_card())
        hand2.add_card(deck.deal_card())

        self.assertEqual(3, len(hand1))
        self.assertEqual(3, len(hand2))

        self.assertEqual(111, hand1.score)
        self.assertEqual(135, hand2.score)

        self.assertFalse(hand1.is_winner(hand2))
        self.assertTrue(hand2.is_winner(hand1))

        n, winners = Hand.determine_winner([hand1, hand2])
        self.assertEqual(n, len(winners))
        self.assertEqual(1, len(winners))
        self.assertEqual(135, winners[0].score)
示例#3
0
    def testHandsEqual(self):
        cards = [
            Card(RED, 2),
            Card(YELLOW, 4),
            Card(GREEN, 2),
        ]
        hand1 = Hand()
        hand1.add_cards(cards)

        self.assertEqual(16, hand1.score)
        self.assertEqual(3, len(hand1))

        self.assertNotEqual(99, hand1.score)
        self.assertNotEqual(1, len(hand1))

        cards = [
            Card(RED, 3),
            Card(YELLOW, 3),
            Card(GREEN, 1),
        ]
        hand2 = Hand()
        hand2.add_cards(cards)

        self.assertEqual(16, hand2.score)
        self.assertEqual(3, len(hand2))

        self.assertNotEqual(99, hand2.score)
        self.assertNotEqual(1, len(hand2))

        ##################################################
        self.assertEqual(hand1, hand2)
        self.assertTrue(hand1 == hand2)
        self.assertFalse(hand1 != hand2)
        self.assertTrue(hand1.is_tie(hand2))
        self.assertFalse(hand1.is_winner(hand2))
        self.assertFalse(hand1.is_loser(hand2))
        self.assertTrue(hand1.same_number_of_cards(hand2))
        self.assertTrue(hand2.same_number_of_cards(hand1))

        ## hands are a tie
        hands = [hand1, hand2]
        n, winners = Hand.determine_winner(hands)
        self.assertEqual(2, n)
        self.assertEqual(hands, winners)