class TestBowlingClass(unittest.TestCase): def setUp(self): self.game = Game() def test_gutter_game(self): self.roll_many(pins=0, times=20) self.assertEqual(self.game.score, 0) def test_all_ones(self): self.roll_many(pins=1, times=20) self.assertEqual(self.game.score, 20) def test_one_spare(self): self.roll_many(pins=5, times=2) self.game.roll(3) self.roll_many(pins=0, times=17) self.assertEqual(self.game.score, 16) def test_one_strike(self): self.game.roll(10) self.game.roll(3) self.game.roll(4) self.assertEqual(self.game.score, 24) def test_perfect_game(self): self.roll_many(pins=10, times=12) assert self.game.score == 300 def roll_many(self, pins, times): for i in range(times): self.game.roll(pins)
# Trevor Waite # Week 11 Assignment # Collaboration with Nicole Ignasiak and Devin Simoneaux from BowlingGame import Game # Open textscores.txt for reading inFile = open("testscores.txt", "r") for line in inFile: line = line.strip() # take out punctuation from text file scoreList = line.split(",") # split the lines into a list separated by commas scoreList = [int(i) for i in scoreList] # makes it into a list of integers finalScore = scoreList.pop() # takes off the final number from each line of the textscores.txt file and makes it the final score g = Game() for roll in scoreList: g.roll(roll) score = g.score() print("The calculated score was {} and the score in the testscores.txt file was {}.".format(score, finalScore)) if score == finalScore: print("The score was correct.") else: print("The scores do not match. The final score is actually equal to", score) inFile.close()
def setUp(self): self.g = Game()
class BowlingGameTest(unittest.TestCase): def setUp(self): self.g = Game() def test_gutter_game(self): self.roll_many(20, 0) self.assertEquals(0, self.g.score()) def test_all_ones(self): self.roll_many(20, 1) self.assertEquals(20, self.g.score()) def test_one_spare(self): self.roll_spare() self.g.roll(3) self.roll_many(17, 0) self.assertEquals(16, self.g.score()) def test_roll_strike(self): self.roll_strike() self.g.roll(3) self.g.roll(4) self.assertEquals(24, self.g.score()) def test_perfect_game(self): self.roll_many(12, 10) self.assertEquals(300, self.g.score()) def roll_many(self, n, pins): for i in range(n): self.g.roll(pins) def roll_spare(self): self.g.roll(5) self.g.roll(5) def roll_strike(self): self.g.roll(10)
def setUp(self): self.game = Game()
class BowlingGameTests(unittest.TestCase): def setUp(self): self.game = Game() def rollManyBalls(self, ballsToRoll, pinsHit): for i in range(0, ballsToRoll): self.game.roll(pinsHit) def rollASpare(self): self.game.roll(6) self.game.roll(4) def rollAStrike(self): self.game.roll(10) def testAllZeroRollsScoresZero(self): self.rollManyBalls(20, 0) self.assertEqual(0, self.game.score()) def testAllOneRollsScoresTwenty(self): self.rollManyBalls(20, 1) self.assertEquals(20, self.game.score()) def testGameWithASpare(self): self.rollASpare() self.game.roll(3) self.rollManyBalls(17, 0) self.assertEquals(16, self.game.score()) def testGameWithAStrike(self): self.rollAStrike() self.game.roll(3) self.game.roll(2) self.rollManyBalls(16, 0) self.assertEqual(20, self.game.score()) def testPerfectGame(self): self.rollManyBalls(12, 10) self.assertEqual(300, self.game.score())
# Read the File newFile = open("testscores.txt", "r") scoresList = [] # Bulk of the coding to analyze the file for line in newFile: # Strip each line and split the numbers using a comma line = line.strip() scoresList = line.split (",") scoresList = [int(e) for e in scoresList] totalScore = scoresList.pop() # Note g is from the BowlingGame.py file g = Game() # Number of Pins for pins in scoresList: g.roll(pins) score = g.score() # Give the User the scores print ("Your score is {}, and the original given score is {}" .format(score, totalScore)) if score == totalScore: print ("Correct! The scores are the same.") else: print ("Incorrect! The score is supposed to be", score) # Close the file newFile.close()
#Alicia Williams #CIS-125 #11/18/15 #Week 11 Assignment: FileReadBowling.py #Collaborated with Ethan Richards import string #imports the game to play from BowlingGame import Game #opens testscores.txt as read only filename = open("testscores.txt", "r") gameList = [] #for loop to strip any bad characters in testscores and adds it to the list for line in filename: lineScores = line.strip() gameList = line.split(",") gameList = [int(element) for element in gameList] #print(gameList) #separate the last element in each list FinalScore = gameList.pop() #create game newGame = Game() #rolls each roll and adds it to the score for pins in gameList: newGame.roll(pins) print("Given Final Score: ",FinalScore,"Actual Score: ",newGame.score(), "Score is Correct: ", FinalScore == newGame.score())
from BowlingGame import Game # open file scores = open("testscores.txt", "r") # loop through scores for line in scores: # strip scores to take out punctuation line = line.strip() # split scores into a list listScore = line.split(",") # makes the scores integers listScore = [int(i) for i in listScore] # makes the final score the last value on list finalScore = listScore.pop() game = Game() # loops through listScore for roll in listScore: game.roll(roll) # gets the score score = game.score() print("Calculated score is {}, and the score in the file is {}".format(score, finalScore)) # sees if scores are the same if score == finalScore: print("The score was right!") # if the scores aren't the same else: print("The score was wrong and should be", score) # close file scores.close()
def setUp(self): self.game = Game() self.longMessage = True
class BowlingGameTest(unittest.TestCase): def setUp(self): self.game = Game() self.longMessage = True def rollMany(self, n, pins): for i in range(n): self.game.roll(pins) def test_guttergame(self): for i in range(20): self.game.roll(0) expectedScore = 0 self.assertEqual(expectedScore, self.game.getScore(), 'incorrect score') def test_all_ones(self): self.rollMany(20, 1) expectedScore = 20 self.assertEqual(expectedScore, self.game.getScore(), 'incorrect score') # # def test_roll_many(self): # # self.rollMany(19, 1) # # expectedScore = 20 # # self.assertEqual(expectedScore, self.game.getScore(), 'incorrect score') def test_one_spare(self): self.game.roll(5) self.game.roll(5) self.game.roll(3) self.rollMany(17, 0) expectedScore = 16 self.assertEqual(expectedScore, self.game.getScore(), 'incorrect score')
# Devin Simoneaux # Week 11 Assignment #CIS-125 # Run a file with scores through the Bowling program that attains scores from BowlingGame import Game file = open("testscores.txt","r") for line in file: line = line.strip() #take out punctuation scoreList = line.split(",") #splits into a list by commas scoreList = [int(i) for i in scoreList] #turns list of strings into a list of integers finalScore = scoreList.pop() #finalScore is equal to the last value on the list g = Game() #reference to BowlingGame.py for roll in scoreList: #throws the frames into BowlingGame g.roll(roll) score = g.score() #gets the score from BowlingGame print("Calculated score is {}, and the given score is {}".format(score, finalScore)) if score == finalScore: #compares the scores to see if they are right print("The score was correct!") else: print("You were wrong. The score should be", score)
import string from BowlingGame import Game FileName = open("testscores.txt", "r") gameList = [] for line in FileName: lineScores = line.strip() gameList = line.split(",") gameList = [int(element) for element in gameList] #print(gameList) FinalScore = gameList.pop() Round = Game() for pins in gameList: Round.roll(pins) print("Final Score given is: ", FinalScore, "Actual Score is: ", Round.score(), "score is correct", FinalScore == Round.score())