当前位置: 首页>>代码示例>>Python>>正文


Python Game.is_winner方法代码示例

本文整理汇总了Python中lib.game.Game.is_winner方法的典型用法代码示例。如果您正苦于以下问题:Python Game.is_winner方法的具体用法?Python Game.is_winner怎么用?Python Game.is_winner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.game.Game的用法示例。


在下文中一共展示了Game.is_winner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestUserStory

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import is_winner [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 is_winner [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.is_winner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。