Sha256: 65fcded8dd919bd3d3b3145d9f09bdac29ca3f8128f557f6b44c2d134226d4ff
Contents?: true
Size: 1.51 KB
Versions: 40
Compression:
Stored size: 1.51 KB
Contents
import play.api.libs.json.Json import scala.io.Source class BowlingTestGenerator { implicit val testCaseReader = Json.reads[BowlingTestCase] private val filename = "bowling.json" private val fileContents = Source.fromFile(filename).getLines.mkString private val json = Json.parse(fileContents) def write { val testCases = (json \ "score" \ "cases").get.as[List[BowlingTestCase]] val description = (json \ "score" \ "description").get.as[List[String]].mkString(" ") implicit def testCaseToGen(tc: BowlingTestCase): TestCaseGen = { val callSUT = s"${tc.rolls}.foldLeft(Bowling())((acc, roll) => acc.roll(roll)).score()" val expected = "" val result = s"val score = $callSUT" val (matchRight, matchLeft) = if (tc.expected == -1) ("""fail("Unexpected score returned. Failure expected")""", "") else (s"assert(n == ${tc.expected})", s"""fail("${tc.description}")""") val checkResult = s"""score match { case Right(n) => $matchRight case Left(_) => $matchLeft }""" TestCaseGen(tc.description, callSUT, expected, result, checkResult) } val testBuilder = new TestBuilder("BowlingTest") testBuilder.addTestCases(testCases, Some(description)) testBuilder.toFile } } case class BowlingTestCase(description: String, rolls: List[Int], expected: Int) object BowlingTestGenerator { def main(args: Array[String]): Unit = { new BowlingTestGenerator().write } }
Version data entries
40 entries across 40 versions & 1 rubygems