Пример #1
0
 def test_card_can_sort_itself_with_another_one(self):
     queen_of_spades = Card(rank="Queen", suit="Spades")
     king_of_spades = Card(rank="King", suit="Spades")
     evaluation = queen_of_spades < king_of_spades
     self.assertEqual(
         evaluation, True,
         "The sort algorithm is not sorting the lower card first")
Пример #2
0
    def test_receive_and_stores_cards(self):
        ace_of_spades = Card(rank="Ace", suit="Spades")
        eight_of_clubs = Card(rank="8", suit="Clubs")
        cards = [ace_of_spades, eight_of_clubs]

        hand = Hand(cards=cards)

        self.assertEqual(hand.cards, [eight_of_clubs, ace_of_spades])
Пример #3
0
    def test_figures_out_high_card_is_best_rank(self):
        cards = [
            Card(rank="Ace", suit="Diamonds"),
            Card(rank="7", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "High Card")
Пример #4
0
    def test_figures_out_pair_is_best_rank(self):
        cards = [
            Card(rank="Ace", suit="Spades"),
            Card(rank="Ace", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Pair")
Пример #5
0
    def test_does_not_deem_two_consecutive_cards_as_straight(self):
        cards = [
            Card(rank="6", suit="Hearts"),
            Card(rank="7", suit="Diamonds")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "High Card")
Пример #6
0
    def test_figures_out_four_of_a_kind_is_best_rank(self):
        cards = [
            Card(rank="9", suit="Clubs"),
            Card(rank="9", suit="Hearts"),
            Card(rank="9", suit="Spades"),
            Card(rank="9", suit="Diamonds"),
            Card(rank="3", suit="Spades")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Four of a kind")
Пример #7
0
    def test_figures_out_full_house_is_best_rank(self):
        cards = [
            Card(rank="9", suit="Clubs"),
            Card(rank="9", suit="Hearts"),
            Card(rank="9", suit="Spades"),
            Card(rank="3", suit="Diamonds"),
            Card(rank="3", suit="Spades")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Full House")
Пример #8
0
    def test_figures_out_straight_is_best_rank(self):
        cards = [
            Card(rank="6", suit="Hearts"),
            Card(rank="7", suit="Diamonds"),
            Card(rank="8", suit="Spades"),
            Card(rank="9", suit="Clubs"),
            Card(rank="10", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Straight")
Пример #9
0
    def test_figures_out_three_of_a_kind_is_best_rank(self):
        cards = [
            Card(rank="King", suit="Clubs"),
            Card(rank="King", suit="Hearts"),
            Card(rank="King", suit="Diamonds"),
            Card(rank="Ace", suit="Spades"),
            Card(rank="5", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Three of a Kind")
Пример #10
0
    def test_figures_out_royal_flush_is_best_rank(self):
        cards = [
            Card(rank="10", suit="Clubs"),
            Card(rank="Jack", suit="Clubs"),
            Card(rank="Queen", suit="Clubs"),
            Card(rank="King", suit="Clubs"),
            Card(rank="Ace", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Royal Flush")
Пример #11
0
    def test_figures_out_two_pair_is_best_rank(self):
        cards = [
            Card(rank="Ace", suit="Spades"),
            Card(rank="5", suit="Clubs"),
            Card(rank="Ace", suit="Clubs"),
            Card(rank="King", suit="Hearts"),
            Card(rank="King", suit="Diamonds")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Two Pair")
Пример #12
0
    def test_figures_out_straight_flush_is_best_rank(self):
        cards = [
            Card(rank="3", suit="Clubs"),
            Card(rank="4", suit="Clubs"),
            Card(rank="5", suit="Clubs"),
            Card(rank="6", suit="Clubs"),
            Card(rank="7", suit="Clubs")
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Straight Flush")
Пример #13
0
    def test_sorts_cards(self):
        two_of_spades = Card(rank="2", suit="Spades")
        five_of_diamonds = Card(rank="5", suit="Diamonds")
        five_of_hearts = Card(rank="5", suit="Hearts")
        eight_of_hearts = Card(rank="8", suit="Hearts")
        ace_of_clubs = Card(rank="Ace", suit="Clubs")

        unsorted_cards = [
            five_of_diamonds, two_of_spades, five_of_hearts, ace_of_clubs,
            eight_of_hearts
        ]

        unsorted_cards.sort()

        self.assertEqual(unsorted_cards, [
            two_of_spades, five_of_diamonds, five_of_hearts, eight_of_hearts,
            ace_of_clubs
        ])
Пример #14
0
    def test_figures_out_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit="Hearts")
            for rank in ["2", "5", "8", "10", "Ace"]
        ]

        hand = Hand(cards=cards)

        self.assertEqual(hand.best_rank(), "Flush")
Пример #15
0
 def test_has_technical_representation(self):
     card = Card("5", "Diamonds")
     self.assertEqual(repr(card), "Card('5', 'Diamonds')")
Пример #16
0
 def test_allows_only_valid_rank(self):
     with self.assertRaises(ValueError):
         Card(rank="Two", suit="Hearts")
Пример #17
0
 def test_allows_only_valid_suit(self):
     with self.assertRaises(ValueError):
         Card(rank="5", suit="Heart")
Пример #18
0
 def test_figures_out_if_two_cards_are_equal(self):
     self.assertEqual(Card(rank="2", suit="Hearts"),
                      Card(rank="2", suit="Hearts"))
Пример #19
0
 def test_has_string_representation_with_rank_and_suit(self):
     card = Card("5", "Diamonds")
     self.assertEqual(str(card), "5 of Diamonds")
Пример #20
0
    def test_adds_cards_to_collection(self):
        card = Card(rank="Ace", suit="Spades")
        deck = Deck()
        deck.add_cards([card])

        self.assertEqual(deck.cards, [card])
Пример #21
0
 def test_has_suit(self):
     card = Card("2", "Clubs")
     self.assertEqual(card.suit, "Clubs")
Пример #22
0
    def test_can_create_standard_52_cards(self):
        cards = Card.create_standard_52_cards()
        self.assertEqual(len(cards), 52)

        self.assertEqual(cards[0], Card(rank="2", suit="Hearts"))
        self.assertEqual(cards[-1], Card(rank="Ace", suit="Diamonds"))
Пример #23
0
 def test_knows_its_rank_index(self):
     card = Card(rank="Jack", suit="Hearts")
     self.assertEqual(card.rank_index, 9)
Пример #24
0
 def test_has_rank(self):
     card = Card(rank="Queen", suit="Hearts")
     self.assertEqual(card.rank, "Queen")