def test_deck_deal_cards(self): deck = Deck() while len(deck.get_cards())>0: last_card = deck.get_cards()[-1] proper_output = last_card submitted_output = deck.deal_card() self.assertEqual(proper_output, submitted_output, "Checking deck.deal_card() method returns the last card in the deck.\nExpected:"+str(proper_output)+"\nSubmitted:"+str(submitted_output))
def test_high_low_three_players_four_card_round(self): bruce = Player("Bruce") clark = Player("Clark") lex = Player("Lex") two_of_hearts = Card("Heart", 2) three_of_hearts = Card("Heart", 3) four_of_hearts = Card("Heart", 4) five_of_hearts = Card("Heart", 5) deck = Deck() deck.set_cards( [two_of_hearts, three_of_hearts, four_of_hearts, five_of_hearts]) game = HighLow([bruce, clark, lex]) game.set_deck(deck) game.deal_cards() game.play_round() self.assertEqual( len(game.get_deck().get_cards()), 1, "With four cards in the deck, after dealing to three players, one card should remain in the deck." ) self.assertFalse( bruce.has_cards(), "After playing a round with one card, there should be no card remaining." ) self.assertFalse( clark.has_cards(), "After playing a round with one card, there should be no card remaining." ) self.assertFalse( lex.has_cards(), "After playing a round with one card, there should be no card remaining." ) self.assertEqual(bruce.get_points(), 1, "Testing game result.") self.assertEqual(clark.get_points(), 0, "Testing game result.") self.assertEqual(lex.get_points(), 0, "Testing game result.")
def test_high_low_two_players_two_cards_same_value_round(self): bruce = Player("Bruce") clark = Player("Clark") two_of_hearts = Card("Heart", 2) three_of_hearts = Card("Spade", 2) deck = Deck() deck.set_cards([two_of_hearts, three_of_hearts]) game = HighLow([bruce, clark]) game.set_deck(deck) game.deal_cards() game.play_round() self.assertFalse( bruce.has_cards(), "After playing a round with one card, there should be no card remaining.\nSubmitted:" + str(bruce.get_cards())) self.assertFalse( clark.has_cards(), "After playing a round with one card, there should be no card remaining.\nSubmitted:" + str(clark.get_cards())) self.assertEqual( bruce.get_points(), 1, "Checking the result of game with 'Heart-2' and 'Spade-2' cards. The player with 'Heart-2' wins 1 point.\nSubmitted:" + str(bruce.get_points())) self.assertEqual( clark.get_points(), 0, "Checking the result of game with 'Heart-2' and 'Spade-2' cards. The player with 'Spade-2' wins 0 point.\nSubmitted:" + str(clark.get_points()))
def test_high_low_get_and_set_deck(self): ted = Player("Ted") bob = Player("Bob") game = HighLow([ted, bob]) deck = Deck() deck.set_cards([Card("Heart", 4)]) game.set_deck(deck) self.assertEqual( game.get_deck(), deck, "Checks set_deck() method replaces the prior deck.\nExpected:" + str(deck) + "\nSubmitted:" + str(game.get_deck()))
def test_deal_cards_two_players_two_cards(self): bruce = Player("Bruce") clark = Player("Clark") two_of_hearts = Card("Heart", 2) three_of_hearts = Card("Heart", 3) deck = Deck() deck.set_cards([two_of_hearts, three_of_hearts]) game = HighLow([bruce, clark]) game.set_deck(deck) game.deal_cards() self.assertEqual( len(game.get_deck().get_cards()), 0, "Starting with two cards in the deck, after dealing them to two players, there should be no cards in the deck.\nSubmitted:" + str(game.get_deck().get_cards())) self.assertEqual( bruce.play_card(), three_of_hearts, "Make sure game.deal_cards() gives the correct card to the player, and play_card() returns the card." ) self.assertEqual( clark.play_card(), two_of_hearts, "Make suregame.deal_cards() gives the correct card to the player, and play_card() returns the card." )
def test_deck_str(self): deck = Deck() deck_string = str(deck) self.assertEqual(len(deck_string), 685, "Checking str(deck) works properly.\nSubmitted:"+str(deck_string))
def test_deck_no_duplicates(self): deck = Deck() cards = deck.get_cards() for card_num in range(1, 53): card = cards.pop() self.assertTrue(card not in deck.get_cards(), "\nChecking pop() method must remove the popped card from the deck.\nCard: " + str(card) + " should not be in deck: " + str(deck.get_cards()))
def test_correct_suits_and_values(self): deck = Deck() for card in deck.get_cards(): self.assertTrue(card.get_suit() in ["Heart", "Club", "Spade", "Diamond"], "Checking Deck() works properly. A card "+str(card)+" is out of four suits.") self.assertTrue(card.get_value() in range(1, 14), "Checking Deck() works properly. A card "+str(card)+" is out of range(1,14)")
def test_deck_setter_no_cards(self): deck = Deck() deck.set_cards([]) self.assertEqual(deck.get_cards(), [], "Checking deck.set_deck() works properly when the deck is empty.\nExpected: deck.get_deck() == []")
def test_deck_setter_single_card(self): deck = Deck() new_deck = [Card("Heart", 4)] deck.set_cards(new_deck) self.assertEqual(deck.get_cards(), new_deck, "Checking set_deck() works properly for setting a single card deck. \nExpected:"+str(new_deck)+"\nSubmitted:"+str(deck.get_cards()))
def test_deck_getter(self): deck = Deck() self.assertTrue(len(deck.get_cards()) == 52, "Checking deck.get_deck() works properly.\nSubmitted:"+str(deck.get_cards()))