def test_card_equals(self): aos1 = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"]) aos2 = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"]) self.assertEqual(aos1, aos2) self.assertNotEqual( aos1, solution.Card(solution.RANKS["Ace"], solution.SUITS["Hearts"]))
def random_cards(count=1): if count == 1: return solution.Card(random.choice(list(solution.RANKS.values())), random.choice(list(solution.SUITS.values()))) cards = set() while len(cards) < count: cards.add( solution.Card(random.choice(list(solution.RANKS.values())), random.choice(list(solution.SUITS.values())))) return cards
def test_all_suits_ranks_equal(self): for rank in solution.RANKS.values(): for suit in solution.SUITS.values(): card = solution.Card(rank, suit) self.assertEqual(card.rank, rank()) self.assertEqual(card.suit, suit())
def test_suit_rank_equals(self): aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"]) self.assertEqual(aos.rank, solution.RANKS["Ace"]()) self.assertEqual(aos.suit, solution.SUITS["Spades"]())
def test_all_cards_equal(self): for rank in solution.RANKS.values(): for suit in solution.SUITS.values(): card1 = solution.Card(rank, suit) card2 = solution.Card(rank, suit) self.assertEqual(card1, card2)
def test_all_card_instances(self): for rank in solution.RANKS.values(): for suit in solution.SUITS.values(): card = solution.Card(rank, suit) self.assertIsInstance(card.rank, rank) self.assertIsInstance(card.suit, suit)
def test_card_instance(self): aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"]) self.assertIsInstance(aos.rank, solution.RANKS["Ace"]) self.assertIsInstance(aos.suit, solution.SUITS["Spades"])
def setUp(self): self.deck = [ solution.Card(rank, suit) for rank in solution.RANKS.values() for suit in solution.SUITS.values() ]
def test_all_to_string(self): for rank in solution.RANKS.values(): for suit in solution.SUITS.values(): card = solution.Card(rank, suit) self.assertEqual(str(card), str(card.rank) + " of " + str(card.suit))
def test_to_string(self): aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"]) self.assertEqual(str(aos), "Ace of Spades")