Ejemplo n.º 1
0
class BowlingTest(unittest.TestCase):
    def setUp(self):
        self.game = Game()

    def test_all_gutterballs(self):
        self.helper_test_roll(20, 0)
        self.assertEqual(0, self.game.score())

    def helper_test_roll(self, rolls, pins):
        for roll in range(rolls):
            self.game.roll(pins)

    def test_perfect_game(self):
        self.helper_test_roll(12, 10)
        self.assertEqual(300, self.game.score())
Ejemplo n.º 2
0
class BowlingTest(unittest.TestCase):
   
   def rollMany(self, n, pins):
      for i in range(n):
         self.g.roll(pins)

   def rollSpare(self):
      self.g.roll(5)
      self.g.roll(5)

   def rollStrike(self):
      self.g.roll(10)

   def setUp(self):
      self.g = Game()

   def test_gutterGame(self):
      self.rollMany(20,0)
      self.assertEqual(0, self.g.score())

   def test_allOnes(self):
      self.rollMany(20,1)
      self.assertEqual(20, self.g.score())

   def test_oneSpare(self):
      self.rollSpare()
      self.g.roll(3)
      self.rollMany(17, 0)
      self.assertEqual(16, self.g.score())

   def test_oneStrike(self):
      self.rollStrike()
      self.g.roll(3)
      self.g.roll(4)
      self.rollMany(17, 0)
      self.assertEqual(24, self.g.score())

   def test_perfectGame(self):
      self.rollMany(12, 10)
      self.assertEqual(300, self.g.score())
Ejemplo n.º 3
0
class PythonBowlingGame(unittest.TestCase):
    # initialise game in setup, exit in tear town
    def setUp(self):
        self.game = Game(1)

    def test_gutter_game(self):
        self.roll_many(20, 0)
        self.assertEqual(0, self.game.score()[0])

    def test_all_ones(self):
        self.roll_many(20, 1)
        self.assertEqual(20, self.game.score()[0])

    def test_one_spare(self):
        self.game.roll(5)
        self.game.roll(5)
        self.game.roll(3)
        self.roll_many(17,0)
        self.assertEqual(16, self.game.score()[0])

    def test_one_strike(self):
        self.game.roll(10)
        self.game.roll(3)
        self.game.roll(4)
        self.roll_many(16, 0)
        self.assertEqual(24, self.game.score()[0])

    def test_perfect_game(self):
        self.roll_many(12,10)
        self.assertEqual(300, self.game.score()[0])

    # may also be worth testing that the maximum number of rolls on last turn is 3

    def roll_many(self, n, pins):
        for i in range(n):
            self.game.roll(pins)
class GameTest(unittest.TestCase):

    def setUp(self):
        self.g = Game()

    def roll_many(self, n, pins):
        for i in range(n):
            self.g.roll(pins)

    def spare(self):
        self.roll_many(2, 5)

    def test_gutter_game(self):
        self.roll_many(20, 0)
        self.assertEqual(0, self.g.score())

    def test_all_ones(self):
        self.roll_many(20, 1)
        self.assertEqual(20, self.g.score())

    def test_spare(self):
        self.spare()
        self.g.roll(3)
        self.roll_many(17, 0)
        self.assertEqual(16, self.g.score())

    def test_no_spare(self):
        self.g.roll(2)
        self.g.roll(6)
        self.g.roll(4)
        self.roll_many(17, 0)
        self.assertEqual(12, self.g.score())

    def test_strike(self):
        self.g.roll(10)
        self.g.roll(6)
        self.g.roll(3)
        self.assertEqual(28, self.g.score())

    def test_perfect_game(self):
        self.roll_many(12, 10)
        self.assertEqual(300, self.g.score())
Ejemplo n.º 5
0
class GameTestCase(TestCase):
    def setUp(self):
        super(GameTestCase, self).setUp()
        self.game = Game()

    def tearDown(self):
        super(GameTestCase, self).tearDown()

    def testAllGutter(self):
        self.rollMany(20, 0)
        self.assertEqual(0, self.game.score())

    def testAllOne(self):
        self.rollMany(20, 1)
        self.assertEqual(20, self.game.score())

    def testOneSpare(self):
        self.rollSpare()
        self.game.roll(3)
        self.rollMany(17, 0)
        self.assertEqual(16, self.game.score())

    def testAllStrikeButLastFrame(self):
        self.rollMany(9, 10)
        self.rollMany(2, 0)
        self.assertEquals(240, self.game.score())

    def testAllStrikeButLastThrow(self):
        self.rollMany(11, 10)
        self.game.roll(9)
        self.assertEquals(299, self.game.score())

    def testAllStrikeButFirstFrameIsSpare(self):
        self.rollSpare()
        self.rollMany(11, 10)
        self.assertEquals(290, self.game.score())

    def testAllStrikeButFirstFrameIsNotSpare(self):
        self.game.roll(5)
        self.game.roll(4)
        self.rollMany(11, 10)
        self.assertEquals(279, self.game.score())

    def testTwoSpares(self):
        self.rollSpare()
        self.rollSpare()
        self.game.roll(3)
        self.game.roll(3)
        self.rollMany(14, 0)
        self.assertEqual(15 + 13 + 6, self.game.score())

    def testOneStrike(self):
        self.rollStrike()
        self.game.roll(3)
        self.game.roll(4)
        self.rollMany(16, 0)
        self.assertEqual(24, self.game.score())

    def testPerfectGame(self):
        self.rollMany(12, 10)
        self.assertEqual(300, self.game.score())

    def rollStrike(self):
        self.game.roll(10)

    def rollSpare(self):
        self.game.roll(5)
        self.game.roll(5) #spare

    def rollMany(self, n, pins):
        map(lambda x: self.game.roll(pins=pins), range(0, n))
Ejemplo n.º 6
0
 def test_gutter_game(self):
     game = Game(roll_many("-", 20))
     self.assertEqual(game.score(), 0)
Ejemplo n.º 7
0
 def test_spare_game(self):
     game = Game("5/5/5/5/5/5/5/5/5/5/5")
     self.assertEqual(game.score(), 150)
Ejemplo n.º 8
0
 def test_all_ones(self):
     game = Game(roll_many("1", 20))
     self.assertEqual(game.score(), 20)
Ejemplo n.º 9
0
 def test_heartbreak_game(self):
     game = Game("9-9-9-9-9-9-9-9-9-9-")
     self.assertEqual(game.score(), 90)
Ejemplo n.º 10
0
 def test_perfect_game(self):
     game = Game("XXXXXXXXXXXX")
     self.assertEqual(game.score(), 300)
Ejemplo n.º 11
0
 def test_always_normal(self):
     game = Game("12345123451234512345")
     self.assertEqual(game.score(), 60)
Ejemplo n.º 12
0
 def test_strike(self):
     game = Game("X34" + roll_many("-", 16))
     self.assertEqual(game.score(), 24)
Ejemplo n.º 13
0
 def test_spare(self):
     game = Game("4/34" + roll_many("-", 16))
     self.assertEqual(game.score(), 20)