def input_valid(self): b = Bowling() print('input = 5,2 8,1 6,4 10 0,5 2,6 8,1 5,3 6,1 10,2,6') self.assertTrue( b.input_roll([ '5,2', '8,1', '6,4', '10', '0,5', '2,6', '8,1', '5,3', '6,1', '10,2,6' ])) print('input = 5,2 8,1 6,4 10 0,5 2,6 8,1 5,3 6,1 10,2,6,4') self.assertFalse( b.input_roll([ '5,2', '8,1', '6,4', '10', '0,5', '2,6', '8,1', '5,3', '6,1', '10,2,6,4' ])) print('input = "5,2"') self.assertFalse(b.input_roll('5,2')) print('Tests success')
class BowlingTest(unittest.TestCase): def setUp(self): self.bowling = Bowling() def testOnePinPerThrow(self): self.assertEqual(20,self.bowling.calculateRoll("11111111111111111111")) def testRollWithMiss(self): self.assertEqual(18,self.bowling.calculateRoll("111111-111-111111111")) # def testRollWithSpareNotAccumulative(self): # self.assertEqual(26,self.bowling.calculateRoll("1/1111-111-111111111")) # def testRollWithSpareNotAccumulativeBadPreviousThrow(self): # self.assertEqual(34,self.bowling.calculateRoll("1//11-111-111111111")) def testRollWithSpare(self): self.assertEqual(46,self.bowling.calculateRoll("1//11-111-111111111")) def testRollWithSpareAndStrike(self): self.assertEqual(58,self.bowling.calculateRoll("1//11X11-111111111")) def testRollWithSpareAndTwoStrike(self): self.assertEqual(79,self.bowling.calculateRoll("1//11XX1111-11111")) def test9AndMiss(self): self.assertEqual(90,self.bowling.calculateRoll("9-9-9-9-9-9-9-9-9-9-")) def test5AndSpareAnd5(self): self.assertEqual(150,self.bowling.calculateRoll("5/5/5/5/5/5/5/5/5/5/5")) def testAllStrikes(self): self.assertEqual(300,self.bowling.calculateRoll("XXXXXXXXXXXX")) def tearDown(self): pass
class MyTestCase(unittest.TestCase): def setUp(self): self.bowling_class = Bowling() @unittest.skip def test_environment(self): self.assertEqual(True, False) def _roll_number_balls(self, number_balls): self.bowling_class.roll_balls(number_balls) def test_bowling_initialization(self): self.assertEqual(10, self.bowling_class.get_number_frames_left()) self.assertEqual(0, self.bowling_class.get_current_score()) def test_bowl_one_frame_zeros(self): self._roll_number_balls(0) self._roll_number_balls(0) self.assertEqual(9, self.bowling_class.get_number_frames_left()) def test_bowl_one_frame_strike(self): self._roll_number_balls(10) self.assertEqual(9, self.bowling_class.get_number_frames_left()) def test_score_one(self): self._roll_number_balls(1) self.assertEqual(1, self.bowling_class.get_current_score()) @unittest.skip def test_score_twenty_two(self): self._roll_number_balls(10) self._roll_number_balls(0) self._roll_number_balls(1) self._roll_number_balls(2) self._roll_number_balls(3) self.assertEqual(22, self.bowling_class.get_current_score())
def testMixture(self): self.assertEqual(120, Bowling("X--X-/X--X-5XX-/").score())
def testAllSpare(self): self.assertEqual(150, Bowling("5/5/5/5/5/5/5/5/5/5/5").score())
def setUp(self): self.bowling = Bowling()
def setUp(self) -> None: self.bowling_game = Bowling()
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.bowling_game = Bowling() @unittest.skip def test_environment(self): self.assertEqual(True, False) def test_score_zero(self): self.assertEqual(0, self.bowling_game.get_score()) def test_score_one(self): self.bowling_game.num_balls_hit(1) self.bowling_game.num_balls_hit(0) self.assertEqual(1, self.bowling_game.get_score()) def test_score_strike(self): self.bowling_game.num_balls_hit(10) # Frame 1 strike = 10 + 1 + 2 = 13 self.bowling_game.num_balls_hit(0) # Frame 1 strike self.bowling_game.num_balls_hit( 1) # Frame 2 normal 1 + 2 = 3 + 13 = 16 self.bowling_game.num_balls_hit(2) self.assertEqual(16, self.bowling_game.get_score()) def test_score_spare(self): self.bowling_game.num_balls_hit(9) # Frame 1 = 9 self.bowling_game.num_balls_hit( 1) # Frame 1 spare = 9 + 1 = 10 + 2 = 12 self.bowling_game.num_balls_hit(2) # Frame 2 = 12 + 2 = 14 self.bowling_game.num_balls_hit(0) # Frame 2 = 14 + 0 = 14 self.assertEqual(14, self.bowling_game.get_score())
def test_can_bowl_a_strike(self): game = Bowling() game.roll(10) game.roll(4) game.roll(4) self.assertEquals(26, game.score())
def test_valid(self): b = Bowling() b.roll = [[5, 2], [8, 1], [6, 4], [10], [0, 5], [2, 6], [8, 1], [5, 3], [6, 1], [10, 2, 6]] b.findsum()
def setUp(self): self.bowling_class = Bowling()
def test_can_bowl_2_times_4_equals_8(self): game = Bowling() game.roll(4) game.roll(4) self.assertEquals(8, game.score())
def test_can_bowl_a_spare(self): game = Bowling() game.roll(6) game.roll(4) game.roll(1) self.assertEquals(12, game.score())
def testAllStrike(self): self.assertEqual(300, Bowling("XXXXXXXXXXXX").score())
objBatting.name= str(t.find_next('td').find_next('td').a.string) tempBat["team"] = secondBatTeam tempBat["batsman"] = str(t.find_next('td').find_next('td').a.string) objBatting.runs=str(t.find_next('td').find_next('td').find_next('td').find_next('td').string) tempBat["runs"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').string) objBatting.balls=str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) tempBat["balls"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) objBatting.sr=str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) tempBat["sr"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) count=count+2; bat2.append(tempBat) count=1; while count<len(urlSoup.findAll('table',{'class':'bowling-table'})[0].findAll('tr')): tempBowl = {} objBowling=Bowling() t= urlSoup.findAll('table',{'class':'bowling-table'})[0].findAll('tr')[count] tempBowl["team"] = secondBatTeam if not t.find_next('td').find_next('td').a: count=count+2; break objBowling.name= str(t.find_next('td').find_next('td').a.string) tempBowl["bowler"] = str(t.find_next('td').find_next('td').a.string) objBowling.overs=str(t.find_next('td').find_next('td').find_next('td').string) tempBowl["overs"] = str(t.find_next('td').find_next('td').find_next('td').string) objBowling.maidens=str(t.find_next('td').find_next('td').find_next('td').find_next('td').string) tempBowl["maidens"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').string) objBowling.runs=str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) tempBowl["runsGiven"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) objBowling.wickets=str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string) tempBowl["wickets"] = str(t.find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').find_next('td').string)
def testAllZero(self): self.assertEqual(0, Bowling("--------------------").score())
#!/usr/bin/python from Bowling import Bowling game = Bowling() for i in range(game.TURNS * game.TRIES + 1): game.play()