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")
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])
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")
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")
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")
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")
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")
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")
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")
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")
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")
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")
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 ])
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")
def test_has_technical_representation(self): card = Card("5", "Diamonds") self.assertEqual(repr(card), "Card('5', 'Diamonds')")
def test_allows_only_valid_rank(self): with self.assertRaises(ValueError): Card(rank="Two", suit="Hearts")
def test_allows_only_valid_suit(self): with self.assertRaises(ValueError): Card(rank="5", suit="Heart")
def test_figures_out_if_two_cards_are_equal(self): self.assertEqual(Card(rank="2", suit="Hearts"), Card(rank="2", suit="Hearts"))
def test_has_string_representation_with_rank_and_suit(self): card = Card("5", "Diamonds") self.assertEqual(str(card), "5 of Diamonds")
def test_adds_cards_to_collection(self): card = Card(rank="Ace", suit="Spades") deck = Deck() deck.add_cards([card]) self.assertEqual(deck.cards, [card])
def test_has_suit(self): card = Card("2", "Clubs") self.assertEqual(card.suit, "Clubs")
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"))
def test_knows_its_rank_index(self): card = Card(rank="Jack", suit="Hearts") self.assertEqual(card.rank_index, 9)
def test_has_rank(self): card = Card(rank="Queen", suit="Hearts") self.assertEqual(card.rank, "Queen")