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_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_high_low_two_players_two_card_round(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() game.play_round() self.assertFalse(bruce.has_cards(), "After playing a round with one card, there should be no card remaining in the player's hand.\nSubmitted:"+str(bruce.get_cards())) self.assertFalse(clark.has_cards(), "After playing a round with one card, there should be no card remaining in the player's hand.\nSubmitted:"+str(clark.get_cards())) self.assertEqual(bruce.get_points(), 1, "Checking the result of game with 'Heart-2' and 'Heart-3' cards. The player with 'Heart-3' wins 1 point.\nSubmitted:"+str(bruce.get_points())) self.assertEqual(clark.get_points(), 0, "Checking the result of game with 'Heart-2' and 'Heart-3' cards. The player with 'Heart-2' wins 0 point.\nSubmitted:"+str(clark.get_points()))
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_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_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()))