def test_score_only_misses(self): """ Own Test 1: Test only misses. """ print("Own Test 1: Test only misses.") test_game = BowlingGame("- - - - - - - - - -") self.assertEqual(test_game.score(), 0)
def test_score_only_splits(self): """ Example Test 3: Test splits. """ print("Example Test 3: Test spare.") test_game = BowlingGame("5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5") self.assertEqual(test_game.score(), 150)
def test_score_following_misses(self): """ Example Test 2: Test nines. """ print("Example Test 2: Test nines.") test_game = BowlingGame("9- 9- 9- 9- 9- 9- 9- 9- 9- 9-") self.assertEqual(test_game.score(), 90)
def test_score_only_strikes(self): """ Example Test 1: Test strikes. """ print("Example Test 1: Test strikes.") test_game = BowlingGame("X X X X X X X X X X X X") self.assertEqual(test_game.score(), 300)
def test_score_single_miss(self): """ Own Test 6: Test a single miss. """ print("Own Test 6: Test a single miss.") # 0 + 9*3 = 27 test_game = BowlingGame("- 12 12 12 12 12 12 12 12 12") self.assertEqual(test_game.score(), 27)
def test_score_single_strike(self): """ Own Test 5: Test a single strike. """ print("Own Test 5: Test a single strike.") # (10 + 3) + 9*3 = 40 test_game = BowlingGame("X 12 12 12 12 12 12 12 12 12") self.assertEqual(test_game.score(), 40)
def test_score_single_spare(self): """ Own Test 4: Test a single spare. """ print("Own Test 4: Test a single spare.") # (10 + 1) + 9*3 = 38 test_game = BowlingGame("1/ 12 12 12 12 12 12 12 12 12") self.assertEqual(test_game.score(), 38)
def test_score_no_special_cases(self): """ Own Test 3: Test no special cases like strikes, spares, misses. """ print("Own Test 3: Test no special cases like strikes, spares, misses.") # 10*3 = 30 test_game = BowlingGame("12 12 12 12 12 12 12 12 12 12") self.assertEqual(test_game.score(), 30)
def test_score_mixed_cases(self): """ Own Test 2: Test mixed cases, i.e. a mix of spares, strikes and misses. """ print("Own Test 2: Test mixed cases, i.e. a mix of spares, strikes and misses.") # 0 + (10+10) + (10+0+0) + 0 + 7 + (10+6) + (10+10) + (10 + 0+0) + (10+0) = 93 test_game = BowlingGame("- 2/ X - 52 4/ 6/ X - 8/ -") self.assertEqual(test_game.score(), 93)
def test_score_preceding_misses(self): """ Own Test 7: Test misses preceding hits. """ print("Own Test 7: Test misses preceding hits.") # 10*2 = 20 test_game = BowlingGame("-2 -2 -2 -2 -2 -2 -2 -2 -2 -2") self.assertEqual(test_game.score(), 20)
def test_score_second_to_last_strike(self): """ Own Test 8: Test with a strike second to last. """ print("Own Test 8: Test with a strike second to last.") # 8*3 + 10 + 2*3 = 40 test_game = BowlingGame("12 12 12 12 12 12 12 12 X 12") self.assertEqual(test_game.score(), 40)
def test_excemption_not_enough_rolls(self): """ let's make sure that the catch if the user didn't input enough rolls """ rolls = [3, 2, 1] game = BowlingGame(log_name=self.log_name) with self.assertRaises(ValueError): game.play_from_list(rolls)
def test_rule_change(self): """ test new rule change implementation (shortgame) """ game = BowlingGame(rules=ShortRules(), log_name=self.log_name) short_list = [10] * 7 # 5 strikes and 2 extra rolls score = game.play_from_list(short_list) self.assertTrue(score == 150)
def test_perfect_game(self): """ test perfect game score 12 rolls of 10 pins """ rolls = [10] * 12 game = BowlingGame(log_name=self.log_name) score = game.play_from_list(rolls) self.assertTrue(score == 300, 'score is %i' % score)
def test_excemption_roll_value(self): """ let's do some basic checking for input like that we don't let people score more frames that pins per frame """ rolls = [20] * 12 game = BowlingGame(log_name=self.log_name) with self.assertRaises(ValueError): game.play_from_list(rolls)
def test_mixed_score(self): """ test mix scores here's just a random list i ran through an online bowling score calculator assuming that the calculator was correct our game logic should be too :D """ rolls = [0, 0, 1, 2, 5, 4, 3, 1, 10, 9, 1, 0, 4, 6, 1, 4, 6, 5, 1] game = BowlingGame(log_name=self.log_name) score = game.play_from_list(rolls) self.assertTrue(score == 78, 'score = %s' % score)
def test_nine_one_split_game(self): """ this test simulates a game full of 9,1 splits with 10 pin score on the last frame (bonus) """ rolls = [] for _ in xrange(10): rolls.extend([9, 1]) # last frame is a strike rolls.append(10) game = BowlingGame(log_name=self.log_name) score = game.play_from_list(rolls) self.assertTrue(score == 191, 'score is %i' % score)
def setUp(self): self.game = BowlingGame()
def setUp(self): self.bowling_game = BowlingGame()
def roll_new_game(self, rolls): game = BowlingGame() for roll in rolls: game.roll(roll) return game
def main(): new_bowling_game = BowlingGame("1- 2- 3- 4- 5- 6- 7- 8- 9- 9-") print(new_bowling_game.score())
def test_score_output_type(self): """ Own Test 9: Test output type. """ test_game = BowlingGame("12 12 12 12 12 12 12 12 X 12") self.assertIsInstance(test_game.score(), int)
def setUp(self): self.game = BowlingGame() try: self.assertRaisesRegex except AttributeError: self.assertRaisesRegex = self.assertRaisesRegexp
def _roll_many(self, rolls): game = BowlingGame() for pins in rolls: game.roll(pins) return game
''' Created on Aug 20, 2018 @author: carlos this is a simple example of rule encapsulation and inheritance to implement the game with new rules ''' from bowling import Rules class ShortRules(Rules): frames = 5 if __name__ == '__main__': from bowling import BowlingGame GAME = BowlingGame(rules=ShortRules()) HALFROLLS = [10] * 7 # 5 strikes and 2 extra rolls GAME.play_from_list(HALFROLLS)