コード例 #1
0
 def test_get_trick_mod(self):
     """
     We should not be able to modify the trick once returned.
     """
     round = HeartsRound(example_hands)
     trick = round.get_trick()
     trick.append("foo")
     self.assertNotEqual(len(trick), len(round.get_trick()))
コード例 #2
0
    def test_play_move(self):
        """
        The leading player should be able to play a card,
        which should get put onto the trick.
        """
        round = HeartsRound(example_hands)

        round.play_card("c2")

        expected = [{"player": 0, "card": "c2"}]

        self.assertEquals(expected, round.get_trick())
コード例 #3
0
    def test_play_move_2(self):
        """
        Same as before, but no passing and different leading player
        """
        new_hands = [example_hands[1], example_hands[0], example_hands[2], example_hands[3]]
        round = HeartsRound(new_hands)

        round.play_card("c2")

        expected = [{"player": 1, "card": "c2"}]

        self.assertEquals(expected, round.get_trick())
コード例 #4
0
    def test_play_second_move(self):
        """
        After the first move, the second player can play any club
        """
        round = HeartsRound(example_hands)

        round.play_card("c2")
        round.play_card("c10")

        expected = [
            {"player": 0, "card": "c2"},
            {"player": 1, "card": "c10"}
        ]

        self.assertEqual(expected, round.get_trick())
コード例 #5
0
    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())
コード例 #6
0
    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())