當前位置: 首頁>>代碼示例>>Python>>正文


Python Game.points方法代碼示例

本文整理匯總了Python中lib.game.Game.points方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.points方法的具體用法?Python Game.points怎麽用?Python Game.points使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lib.game.Game的用法示例。


在下文中一共展示了Game.points方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestUserStory

# 需要導入模塊: from lib.game import Game [as 別名]
# 或者: from lib.game.Game import points [as 別名]
class TestUserStory(unittest.TestCase):
    def setUp(self):
        self.blackjack = Game()

    def test_user_story_0a(self):
        """_One player two cards number closest to 20 wins"""
        self.blackjack.pick_cards = MagicMock(return_value=[10,9])
        self.blackjack.deal()
        self.assertEqual(self.blackjack.points(), 19)

    def test_user_story_0b(self):
        """_restarts game with new deck and cleared hand"""
        self.blackjack.pick_cards = MagicMock(return_value=[10,'Q'])
        self.blackjack.deal()
        self.blackjack.points()
        self.blackjack.new_game()

        self.assertListEqual(self.blackjack.cards, [2,3,4,5,6,7,8,9,10, 'J', 'Q', 'K','A'])
        self.assertListEqual(self.blackjack.hand, [])

    def test_user_story_0c(self):
        """_Play game with face card"""
        self.blackjack.pick_cards = MagicMock(return_value=[10,'Q'])
        self.blackjack.deal()

        self.assertEqual(self.blackjack.points(), 20)

    def test_user_story_0d(self):
        """_Play game with ace card"""
        self.blackjack.pick_cards = MagicMock(return_value=['A','Q'])
        self.blackjack.deal()

        self.assertTrue(self.blackjack.is_winner())
開發者ID:hanfak,項目名稱:blackjack-python-CLI,代碼行數:35,代碼來源:feature_tests.py

示例2: TestGame

# 需要導入模塊: from lib.game import Game [as 別名]
# 或者: from lib.game.Game import points [as 別名]
class TestGame(unittest.TestCase):
    def setUp(self):
        self.blackjack = Game()

    def test_0(self):
        """Only cards from 1 to 10 exist"""
        self.assertListEqual(self.blackjack.cards, [2,3,4,5,6,7,8,9,10, 'J', 'Q', 'K', 'A'])

    def test_1a(self):
        """Player dealt winning cards"""
        self.blackjack.pick_cards = MagicMock(return_value=[10,8])
        self.blackjack.deal()

        self.assertEqual(self.blackjack.points(), 18)

    def test_1b(self):
        """Player dealt losing hand"""
        self.blackjack.pick_cards = MagicMock(return_value=[2,7])
        self.blackjack.deal()

        self.assertFalse(self.blackjack.deal())

    def test_1c(self):
        """Player dealt cards from deck"""
        self.blackjack.pick_cards = MagicMock(return_value=[2,7])
        self.blackjack.deal()

        self.assertTrue(self.blackjack.hand[0] in self.blackjack.cards)
        self.assertTrue(self.blackjack.hand[1] in self.blackjack.cards)

    def test_2a(self):
        """When card is dealt, removed from pack"""
        self.blackjack.deal()

        self.assertEqual(len(self.blackjack.cards), 12)
        self.assertFalse(self.blackjack.hand[0] in self.blackjack.cards)

    def test_3a(self):
        """Can start new game, resets hand"""
        self.blackjack.deal()
        self.blackjack.new_game()

        self.assertEqual(self.blackjack.hand,[])

    def test_3b(self):
        """Can start new game, resets deck"""
        self.blackjack.deal()
        self.blackjack.new_game()

        self.assertEqual(self.blackjack.cards,[2,3,4,5,6,7,8,9,10, 'J', 'Q', 'K', 'A'])

    def test_4a(self):
        """Include points for one face cards"""
        self.blackjack.pick_cards = MagicMock(return_value=['K',7])
        self.blackjack.deal()

        self.assertEqual(self.blackjack.points(),17)

    def test_4b(self):
        """Include points for two face cards"""
        self.blackjack.pick_cards = MagicMock(return_value=['K','J'])
        self.blackjack.deal()

        self.assertEqual(self.blackjack.points(),20)

    def test_5a(self):
        """include points where one card is an ace"""
        self.blackjack.pick_cards = MagicMock(return_value=['A',7])
        self.blackjack.deal()

        self.assertEqual(self.blackjack.points(), 18)

    def test_5b(self):
        """include points win with black jack"""
        self.blackjack.pick_cards = MagicMock(return_value=['K','A'])
        self.blackjack.deal()

        self.assertTrue(self.blackjack.is_winner())
開發者ID:hanfak,項目名稱:blackjack-python-CLI,代碼行數:80,代碼來源:game_test.py


注:本文中的lib.game.Game.points方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。