-
Notifications
You must be signed in to change notification settings - Fork 0
/
Original code for assignment.txt
87 lines (72 loc) · 2.74 KB
/
Original code for assignment.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#File 1 (Test.py)
#This file has information about test cases which you need to test.
import unittest
import BowlingGame
class TestBowlingGame(unittest.TestCase):
def setUp(self):
self.game = BowlingGame.BowlingGame()
def testGutterGame(self):
for i in range(0, 20):
self.game.rolls(0)
assert self.game.score()==0
def testAllOnes(self):
self.rollMany(1, 20)
assert self.game.score()==20
def testOneSpare(self):
self.game.rolls(5)
self.game.rolls(5)
self.game.rolls(3)
self.rollMany(0,17)
assert self.game.score()==16
def testOneStrike(self):
self.game.rolls(10)
self.game.rolls(4)
self.game.rolls(3)
self.rollMany(0,16)
assert self.game.score()==24
def testPerfectGame(self):
self.rollMany(10,12)
assert self.game.score()==300
def testOneSpare(self):
self.rollMany(5,21)
assert self.game.score()==150
def rollMany(self, pins,rolls):
for i in range(rolls):
self.game.rolls(pins)
#File 2 (BowlingGame.py)
#This file has information about Bowling Game for which the description is provided in project assessment.
class BowlingGame:
def __init__(self):
self.rolls=[]
def roll(self,pins):
self.rolls.append(pins)
def score(self):
result = 0
rollIndex=0
for frameIndex in range(10):
if frameIndex in range(10):
result += self.StrikeScore(rollIndex)
rollIndex +=1
elif self.isSpare(rollIndex):
result += self.spareScore(rollIndex)
rollIndex +=2
else:
result += self.frameScore(rollIndex)
rollIndex +=2
return result
def isStrike(self, rollIndex):
return self.rolls[rollIndex] == 10
def isSpare(self, rollIndex):
return self.rolls[rollIndex]+ self.rolls[rollIndex+1]==10
def stickeScore(self,rollIndex):
return 10+ self.rolls[rollIndex+1]+ self.rolls[rollIndex+2]
def spareScore(self,rollIndex):
return 10+ self.rolls[rollIndex+2]
def frameScore(self, rollIndex):
return self.rolls[rollIndex] + self.rolls[rollIndex + 1]
#Your tasks for code parts:
#1: If there are any bugs in the code, you have to remove using debugging and run the project and test cases.
#2: Refactor the code (Improve its structure without changing external behaviour).
#3: Report everything using github commits and versioning control.
###### Important #####
# Please complete your project and all tasks according to assessment description provided in CANVAS.