예제 #1
0
class TestHand(unittest.TestCase):
    """
        Tests the functionality of the Hand class.
        //TODO combine this with current functional tests, rewrite functional tests.
    """

    def setUp(self):
        self.hand = Hand("Diamonds")

    def tearDown(self):
        self.hand = None

    def test_can_set_trump(self):
        """ Tests the ability to set the trump of a hand. """
        self.assertEqual(self.hand.get_trump(), "Diamonds")

    def test_can_sort_normal_hand(self):
        """ Tests the ability to sort a hand that has no trumps or bowers. """
        self.hand.add_card("T", "s")
        self.hand.add_card("Q", "s")
        self.hand.add_card("J", "s")
        self.hand.add_card("K", "s")
        self.hand.add_card("A", "s")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "As\nKs\nQs\nJs\nTs")

    def test_can_sort_trump_hand(self):
        """ Tests the ability to sort a hand that has all trumps (and high bower). """
        self.hand.add_card("T", "d")
        self.hand.add_card("Q", "d")
        self.hand.add_card("J", "d")
        self.hand.add_card("K", "d")
        self.hand.add_card("A", "d")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "Jd\nAd\nKd\nQd\nTd")

    def test_can_sort_mixed_hand(self):
        """ Tests the ability to sort a hand that is mixed and includes both bowers. """
        self.hand.add_card("T", "d")
        self.hand.add_card("Q", "c")
        self.hand.add_card("J", "h")
        self.hand.add_card("J", "d")
        self.hand.add_card("A", "d")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "Jd\nJh\nAd\nTd\nQc")