本文整理汇总了Python中hand.Hand.sort_hand方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.sort_hand方法的具体用法?Python Hand.sort_hand怎么用?Python Hand.sort_hand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hand.Hand
的用法示例。
在下文中一共展示了Hand.sort_hand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import sort_hand [as 别名]
def main():
""" Reads the input from stdin. Outputs to stdout. """
trump = sys.stdin.readline().strip()
my_hand = Hand(trump[0].lower())
line = 0
while line < 5:
card = sys.stdin.readline()
my_hand.add_card(card[0], card[1])
line += 1
my_hand.sort_hand()
print(trump)
print(my_hand)
示例2: TestHand
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import sort_hand [as 别名]
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")