def test_play_cannot_follow_suit(self): """ Tests that a player can play a card of a different suit if they cannot follow suit. """ hands = [ ['d4', 'dj', 's9', 'h5', 'c2', 'h1', 'd2', 'h8', 'd3', 's2', 'd9', 'd8', 'dq'], ['s7', 'c5', 'c4', 'c10', 'h6', 'c3', 'h10', 'hk', 'd7', 'dk', 'h4', 'sj', 'hq'], ['hj', 's5', 'd5', 's6', 's10', 'd1', 'sk', 's4', 'h7', 'd10', 'c9', 'cq', 'cj'], ['d6', 'h2', 'sq', 'c8', 'h9', 'ck', 'h3', 'c6', 's1', 'c1', 's3', 'c7', 's8'] ] round = HeartsRound(hands) # get the first trick out of the way round.play_card("c2") round.play_card("c10") round.play_card("c9") round.play_card("c8") # player 1 to start now self.assertEqual(1, round.get_current_player()) round.play_card("c3") round.play_card("cj") round.play_card("c7") round.play_card("dq") # player 0 has no clubs # player 2 wins due to cj self.assertEqual(2, round.get_current_player())
def test_play_move_current_player_rollover(self): """ The current player should roll over to player 0 after player 3 plays a card. """ hands = [example_hands[1], example_hands[2], example_hands[3], example_hands[0]] round = HeartsRound(hands) self.assertEqual(3, round.get_current_player()) round.play_card("c2") self.assertEqual(0, round.get_current_player())
def test_play_move_current_player(self): """ When a move has been played, the current player should update. """ round = HeartsRound(example_hands) self.assertEqual(0, round.get_current_player()) round.play_card("c2") self.assertEqual(1, round.get_current_player())
def test_initial_player(self): """ The person with the two of clubs should be the first to play. """ round = HeartsRound(example_hands) self.assertEqual(0, round.get_current_player())
def test_add_to_score(self): """ Tests that when a player wins a heart, their score is incremented. """ hands = [ ["d4", "dj", "s9", 'h5', 'c2', 'h1', 'd2', 'h8', 'd3', 's2', 'd9', 'd8', 'dq'], ["s7", "c5", "c4", 'c10', 'h6', 'c3', 'h10', 'hk', 'd7', 'dk', 'h4', 'sj', 'hq'], ["hj", "s5", "d5", 's6', 's10', 'd1', 'sk', 's4', 'h7', 'd10', 'c9', 'cq', 'cj'], ["d6", "h2", "sq", 'c8', 'h9', 'ck', 'h3', 'c6', 's1', 'c1', 's3', 'c7', 's8'] ] round = HeartsRound(hands) # get the first trick out of the way round.play_card("c2") round.play_card("c10") round.play_card("c9") round.play_card("c8") # player 1 to start now self.assertEqual(1, round.get_current_player()) round.play_card("c3") round.play_card("cj") round.play_card("c7") round.play_card("h5") # player 0 has no clubs # player 2 wins due to cj, # so their score should update. self.assertEqual(1, round.get_score(2))
def test_initial_player_2(self): """ Same as previous test but with different player. """ new_hands = [ example_hands[1], example_hands[3], example_hands[0], example_hands[2]] round = HeartsRound(new_hands) self.assertEqual(2, round.get_current_player())
def test_play_break_hearts(self): """ Tests that once hearts is broken, it is possible to lead with a heart. """ hands = [ ["d4", "dj", "s9", 'h5', 'c2', 'h1', 'd2', 'h8', 'd3', 's2', 'd9', 'd8', 'dq'], ["s7", "c5", "c4", 'c10', 'h6', 'c3', 'h10', 'hk', 'd7', 'dk', 'h4', 'sj', 'hq'], ["hj", "s5", "d5", 's6', 's10', 'd1', 'sk', 's4', 'h7', 'd10', 'c9', 'cq', 'cj'], ["d6", "h2", "sq", 'c8', 'h9', 'ck', 'h3', 'c6', 's1', 'c1', 's3', 'c7', 's8'] ] round = HeartsRound(hands) # get the first trick out of the way round.play_card("c2") round.play_card("c10") round.play_card("c9") round.play_card("c8") # player 1 to start now self.assertEqual(1, round.get_current_player()) round.play_card("c3") round.play_card("cj") round.play_card("c7") round.play_card("h5") # player 0 has no clubs # player 2 wins due to cj self.assertEqual(2, round.get_current_player()) # check that hearts is broken self.assertTrue(round.is_hearts_broken()) # player 2 can lead with a heart now round.play_card("h7") self.assertEqual([{"player": 2, "card": "h7"}], round.get_trick())
def test_finish_trick_winner(self): """ Tests that the winner of the trick is properly set. """ round = HeartsRound(example_hands) # play the trick round.play_card("c2") round.play_card("c10") round.play_card("cq") round.play_card("c8") # player 2 was the winner, # so we expect them to be the current player self.assertEqual(2, round.get_current_player())
def test_finish_trick(self): """ Tests that the next trick is set up properly when a trick is finished. """ round = HeartsRound(example_hands) # play the trick round.play_card("c2") round.play_card("c10") round.play_card("c9") round.play_card("c8") # player 1 was the winner, # so we expect them to be the current player self.assertEqual(1, round.get_current_player()) # the trick should be empty now self.assertEqual([], round.get_trick())