Пример #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_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"))
Пример #3
0
    def test_figures_out_high_card_is_best_rank(self):
        cards = [Card(rank="Ace", suit="Spades"), Card(rank="6", suit="Clubs")]

        hand = Hand()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "High Card")
Пример #4
0
 def test_removes_specified_number_of_cards_from_deck(self):
     ace = Card(rank="Ace", suit="Spades")
     eight = Card(rank="8", suit="Diamonds")
     cards = [ace, eight]
     deck = Deck()
     deck.add_cards(cards)
     self.assertEqual(deck.remove_cards(1), [ace])
     self.assertEqual(deck.cards, [eight])
Пример #5
0
 def test_shuffles_card_in_random_order(self, mock_shuffle):
     deck = Deck()
     cards = [
         Card(rank="Ace", suit="Spades"),
         Card(rank="8", suit="Diamonds")
     ]
     deck.add_cards(cards)
     deck.shuffle()
     mock_shuffle.assert_called_once_with(cards)
 def test_passes_new_cards_to_hands(self):
     mock_hand = MagicMock()
     player = Player(name="Ron", hand=mock_hand)
     cards = [
         Card(rank="Ace", suit="Spades"),
         Card(rank="Queen", suit="Diamonds")
     ]
     player.add_cards(cards)
     mock_hand.add_cards.assert_called_once_with(cards)
Пример #7
0
    def test_validates_that_cards_have_a_high_card(self):
        cards = [
            Card(rank="7", suit="Clubs"),
            Card(rank="Ace", suit="Diamonds")
        ]

        validator = HighCardValidator(cards=cards)

        self.assertEqual(validator.is_valid(), True)
Пример #8
0
    def test_recieves_and_stores_cards(self):
        ace_of_spades = Card(rank="Ace", suit="Spades")
        six_of_spades = Card(rank="6", suit="Clubs")

        cards = [ace_of_spades, six_of_spades]

        hand = Hand()
        hand.add_cards(cards)

        self.assertEqual(hand.cards, [six_of_spades, ace_of_spades])
Пример #9
0
    def test_does_not_return_two_consecutive_cards_as_straight(self):
        cards = [
            Card(rank="6", suit="Hearts"),
            Card(rank="7", suit="Diamonds")
        ]

        hand = Hand()
        hand.add_cards(cards)

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

        hand = Hand()
        hand.add_cards(cards)

        self.assertEqual(repr(hand), "7 of Clubs, Ace of Diamonds")
Пример #11
0
    def setUp(self):
        five = Card(rank="5", suit="Clubs")
        self.king_of_clubs = Card(rank="King", suit="Clubs")
        self.king_of_diamonds = Card(rank="King", suit="Diamonds")
        self.king_of_hearts = Card(rank="King", suit="Hearts")
        ace = Card(rank="Ace", suit="Spades")

        self.cards = [
            five, self.king_of_clubs, self.king_of_diamonds,
            self.king_of_hearts, ace
        ]
    def setUp(self):
        self.five_of_clubs = Card(rank="5", suit="Clubs")
        self.king_of_diamonds = Card(rank="King", suit="Diamonds")
        self.king_of_hearts = Card(rank="King", suit="Hearts")
        self.ace_of_clubs = Card(rank="Ace", suit="Clubs")
        self.ace_of_spades = Card(rank="Ace", suit="Spades")

        self.cards = [
            self.five_of_clubs, self.king_of_diamonds, self.king_of_hearts,
            self.ace_of_clubs, self.ace_of_spades
        ]
Пример #13
0
    def test_returns_high_card_from_card_collection(self):
        ace_of_diamonds = Card(rank="Ace", suit="Diamonds")
        cards = [
            Card(rank="5", suit="Spades"),
            Card(rank="8", suit="Diamonds"),
            Card(rank="10", suit="Clubs"),
            Card(rank="Queen", suit="Spades"), ace_of_diamonds
        ]

        validator = HighCardValidator(cards=cards)

        self.assertEqual(validator.valid_cards(), [ace_of_diamonds])
Пример #14
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()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Straight")
Пример #15
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()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Royal Flush")
Пример #16
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()
        hand.add_cards(cards)

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

        hand = Hand()
        hand.add_cards(cards)

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

        hand = Hand()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Full House")
Пример #19
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()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Three of a Kind")
Пример #20
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()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Straight Flush")
Пример #21
0
    def test_interacts_with_validator_to_get_winning_hand(self):
        class HandWithOneValidator(Hand):
            VALIDATORS = (PairValidator,)
        
        ace_of_hearts = Card(rank = "Ace", suit = "Hearts")
        ace_of_spades = Card(rank = "Ace", suit = "Spades")

        cards = [ace_of_hearts, ace_of_spades]

        hand = HandWithOneValidator()
        hand.add_cards(cards = cards)

        self.assertEqual(
            hand.best_rank(),
            (0, "Pair", [ace_of_hearts, ace_of_spades])
        )
Пример #22
0
    def test_returns_five_straight_cards_with_same_rank_ending_in_ace(self):
        ten   = Card(rank = "10", suit = "Clubs")
        jack  = Card(rank = "Jack", suit = "Clubs")
        queen = Card(rank = "Queen", suit = "Clubs")
        king  = Card(rank = "King", suit = "Clubs")
        ace   = Card(rank = "Ace", suit = "Clubs")

        cards = [
            Card(rank = "2", suit = "Spades"),
            ten,
            jack,
            queen,
            king,
            ace,
            Card(rank = "Ace", suit = "Diamonds")
        ]

        validator = RoyalFlushValidator(cards = cards)

        self.assertEqual(
            validator.valid_cards(),
            [
                ten,
                jack,
                queen,
                king,
                ace
            ]
        )
Пример #23
0
    def test_figures_out_best_rank_when_flush(self):
        cards = [
            Card(rank=rank, suit="Hearts")
            for rank in ["2", "5", "8", "10", "Ace"]
        ]
        hand = Hand()
        hand.add_cards(cards)

        self.assertEqual(hand.best_rank(), "Flush")
Пример #24
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
        ])
Пример #25
0
    def setUp(self):
        two = Card(rank="2", suit="Spades")
        six = Card(rank="6", suit="Hearts")
        self.seven = Card(rank="7", suit="Diamonds")
        self.eight = Card(rank="8", suit="Spades")
        self.nine = Card(rank="9", suit="Clubs")
        self.ten = Card(rank="10", suit="Clubs")
        self.jack = Card(rank="Jack", suit="Hearts")

        self.cards = [
            two, six, self.seven, self.eight, self.nine, self.ten, self.jack
        ]
    def setUp(self):
        self.three_of_clubs = Card(rank="3", suit="Clubs")
        self.three_of_diamonds = Card(rank="3", suit="Diamonds")
        self.three_of_hearts = Card(rank="3", suit="Hearts")
        self.three_of_spades = Card(rank="3", suit="Spades")

        self.cards = [
            Card(rank="2", suit="Clubs"), self.three_of_clubs,
            self.three_of_diamonds, self.three_of_hearts, self.three_of_spades,
            Card(rank="7", suit="Hearts"),
            Card(rank="9", suit="Spades")
        ]
Пример #27
0
    def setUp(self):
        self.two_of_hearts = Card(rank="2", suit="Hearts")
        self.five_of_hearts = Card(rank="5", suit="Hearts")
        self.seven_of_hearts = Card(rank="7", suit="Hearts")
        self.eight_of_hearts = Card(rank="8", suit="Hearts")
        self.ten_of_hearts = Card(rank="10", suit="Hearts")
        self.ace_of_hearts = Card(rank="Ace", suit="Hearts")

        self.cards = [
            self.two_of_hearts, self.five_of_hearts, self.seven_of_hearts,
            self.eight_of_hearts, self.ten_of_hearts,
            Card(rank="Jack", suit="Clubs"), self.ace_of_hearts
        ]
Пример #28
0
    def setUp(self):
        self.first_two_cards = [
            Card(rank="2", suit="Hearts"),
            Card(rank="6", suit="Clubs")
        ]

        self.next_two_cards = [
            Card(rank="9", suit="Diamonds"),
            Card(rank="4", suit="Spades")
        ]

        self.flop_cards = [
            Card(rank="2", suit="Diamonds"),
            Card(rank="4", suit="Hearts"),
            Card(rank="10", suit="Spades")
        ]

        self.turn_card = [Card(rank="9", suit="Hearts")]

        self.river_card = [Card(rank="Queen", suit="Clubs")]
    def test_determines_that_there_are_not_five_consecutive_cards_with_same_suit(
            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="Diamonds"),
            Card(rank="King", suit="Clubs"),
            Card(rank="Ace", suit="Diamonds")
        ]

        validator = StraightFlushValidator(cards=cards)

        self.assertEqual(validator.is_valid(), False)
Пример #30
0
    def test_validates_that_cards_do_not_have_straight_flush_ending_in_ace(self):
        cards = [
            Card(rank = "2", suit = "Spades"),
            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"),
            Card(rank = "Ace", suit = "Diamonds")
        ]

        validator = RoyalFlushValidator(cards = cards)

        self.assertEqual(
            validator.is_valid(),
            True
        )