コード例 #1
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    def testDeckCreateMockShuffled1(self):
        """
        Create a default deck, do modified shuffle (repeatable), and validate the number of cards
        and point total.  Then redo and compare the resulting order of cards from both excercises.

        The above is executed for a list of shuffle modification factors to insure the modified
        shuffle operation is indeed repeatable over a wide range of values.
        """

        for factor_value in (
            0.0638,
            0.1,
            0.148,
            0.2,
            0.23,
            0.314,
            0.4374,
            0.5,
            0.627,
            0.873,
            0.9177,
        ):
            with self.subTest(factor=factor_value):
                deck = Deck.initialize_deck()
                deck.shuffler = Shuffler(factor_value)
                deck.shuffle()
                self.assertEqual(39, len(deck))
                self.assertEqual(624, sum([card.point_value for card in deck]))
                self.assertEqual(deck, deck)

                cards_from_prev_shuffle = [c for c in deck]

                deck = Deck.initialize_deck()
                deck.shuffler = Shuffler(factor_value)
                deck.shuffle()
                self.assertEqual(deck.cards, cards_from_prev_shuffle)

                deck = Deck.initialize_deck()
                deck.shuffler = Shuffler(factor_value)
                deck.shuffle()
                self.assertEqual(deck.cards, cards_from_prev_shuffle)
コード例 #2
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    def testDeckCreateUnshuffled(self):
        """
        Create a default deck, validate the number of cards and point total.
        """

        deck = Deck.initialize_deck()
        self.assertEqual(39, len(deck))
        self.assertEqual(624, sum([card.point_value for card in deck]))

        hand = Hand()
        for _ in range(len(deck)):
            hand.add_card(deck.deal_card())

        self.assertEqual(0, len(deck))
        self.assertEqual(624, hand.score)
コード例 #3
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    def testDeckOneHandMockDeal1(self):
        """
        Create a new deck, shuffle, deal all cards, validate
        number of cards and point total.
        """

        deck = Deck.initialize_deck()
        deck.shuffler = self.shuffler
        deck.shuffle()

        self.assertEqual(39, len(deck))
        self.assertEqual(624, sum([card.point_value for card in deck]))

        hand = Hand()
        for _ in range(len(deck)):
            hand.add_card(deck.deal_card())

        self.assertEqual(0, len(deck))
        self.assertEqual(624, hand.score)
コード例 #4
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    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)
コード例 #5
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    def testDeckTwoHandsMockDeal1(self):
        """
        Shuffle a clean deck twice, deal 3 hands,
        validate number of cards, score, and winner.

        Tests run with a mocked random number generator
        """

        deck = Deck.initialize_deck()
        deck.shuffler = self.shuffler
        deck.shuffle()

        ## regular deck
        self.assertEqual(39, len(deck))

        ## Deal 2 hands, 3 cards each
        hand1 = Hand("Player 1")
        hand2 = Hand("Player 2")

        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(33, len(deck))

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

        self.assertEqual(27, hand1.score)
        self.assertEqual(57, hand2.score)

        n, hands = Hand.determine_winner([hand1, hand2])
        self.assertEqual(1, n)
        self.assertEqual(1, len(hands))
        self.assertEqual(57, hands[0].score)
コード例 #6
0
ファイル: test_deck.py プロジェクト: ccoulter/card_game
    def testDeckOneHandMockDeal2(self):
        """
        Create a new deck, shuffle, deal 5 cards to a single hand.
        Validate number of cards and point total.
        Deal 2 more cards from same deck into same hand.
        Validate new number of cards and point total.
        Deal 15 more cards from same deck into same hand.
        Validate new number of cards and point total.
        """

        deck = Deck.initialize_deck()
        deck.shuffler = self.shuffler
        deck.shuffle()

        hand = Hand()
        for _ in range(5):
            hand.add_card(deck.deal_card())

        self.assertEqual(34, len(deck))

        self.assertEqual(5, len(hand))
        self.assertEqual(64, hand.score)

        for _ in range(2):
            hand.add_card(deck.deal_card())

        self.assertEqual(32, len(deck))

        self.assertEqual(7, len(hand))
        self.assertEqual(99, hand.score)

        for _ in range(15):
            hand.add_card(deck.deal_card())

        self.assertEqual(17, len(deck))

        self.assertEqual(22, len(hand))
        self.assertEqual(391, hand.score)