Created
February 27, 2011 04:43
-
-
Save jbrechtel/845909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.Spec | |
import org.scalatest.matchers.ShouldMatchers | |
class BowlingGameSpecs extends Spec with ShouldMatchers { | |
describe("Playing a game") { | |
it("should have a score of zero for a game with all zero rolls") { | |
val game = new BowlingGame() | |
(1 to 20).map(i => 0).foreach(game.roll) | |
game.score should equal(0) | |
} | |
it("should have a score equal to the number of pins for each roll when there are no strikes") { | |
val game = new BowlingGame() | |
(1 to 20).map(i => 1).foreach(game.roll) | |
game.score should equal(20) | |
} | |
it("should count the first roll of a frame following a spare twice") { | |
val game = new BowlingGame() | |
(List(5,5,3) ::: (1 to 17).map(num => 0).toList).foreach(game.roll) | |
game.score should equal(16) | |
} | |
it("should count the entire frame following a strike twice") { | |
val game = new BowlingGame() | |
(List(10,3,4) ::: (1 to 16).map(num => 0).toList).foreach(game.roll) | |
game.score should equal(24) | |
} | |
it("should score a perfect game as 300") { | |
val game = new BowlingGame() | |
(1 to 12).map(num => 10).foreach(game.roll) | |
game.score should equal(300) | |
} | |
it("should score a spare on the tenth frame") { | |
val game = new BowlingGame() | |
((1 to 19).map(i => 0).toList ::: List(10,5)).foreach(game.roll) | |
game.score should equal(15) | |
} | |
it("should score spares and strikes") { | |
val game = new BowlingGame() | |
((1 to 16).map(i => 0).toList ::: List(10,1, 0)).foreach(game.roll) | |
game.score should equal(12) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment