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")
Esempio n. 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])
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 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
        ])
Esempio n. 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")
Esempio n. 15
0
 def test_has_technical_representation(self):
     card = Card("5", "Diamonds")
     self.assertEqual(repr(card), "Card('5', 'Diamonds')")
Esempio n. 16
0
 def test_allows_only_valid_rank(self):
     with self.assertRaises(ValueError):
         Card(rank="Two", suit="Hearts")
Esempio n. 17
0
 def test_allows_only_valid_suit(self):
     with self.assertRaises(ValueError):
         Card(rank="5", suit="Heart")
Esempio n. 18
0
 def test_figures_out_if_two_cards_are_equal(self):
     self.assertEqual(Card(rank="2", suit="Hearts"),
                      Card(rank="2", suit="Hearts"))
Esempio n. 19
0
 def test_has_string_representation_with_rank_and_suit(self):
     card = Card("5", "Diamonds")
     self.assertEqual(str(card), "5 of Diamonds")
Esempio n. 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])
Esempio n. 21
0
 def test_has_suit(self):
     card = Card("2", "Clubs")
     self.assertEqual(card.suit, "Clubs")
Esempio n. 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"))
Esempio n. 23
0
 def test_knows_its_rank_index(self):
     card = Card(rank="Jack", suit="Hearts")
     self.assertEqual(card.rank_index, 9)
Esempio n. 24
0
 def test_has_rank(self):
     card = Card(rank="Queen", suit="Hearts")
     self.assertEqual(card.rank, "Queen")