本文整理汇总了Python中lib.game.Game.new_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.new_game方法的具体用法?Python Game.new_game怎么用?Python Game.new_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.game.Game
的用法示例。
在下文中一共展示了Game.new_game方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUserStory
# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import new_game [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())
示例2: TestGame
# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import new_game [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())