Sha256: 209eed3e147ccf667fffbcc2307e53c2081ef0695a56c379385d6cdd08ba7725
Contents?: true
Size: 1.24 KB
Versions: 136
Compression:
Stored size: 1.24 KB
Contents
import play.api.libs.json.Json import scala.io.Source // Generates test suite from json definition for the Panframs exercise. class PangramsTestGenerator { implicit val pangramTestCaseReader = Json.reads[PangramTestCase] private val filename = "pangram.json" private val fileContents = Source.fromFile(filename).getLines.mkString private val json = Json.parse(fileContents) def write { print("import org.scalatest.{FunSuite, Matchers}" + System.lineSeparator()) print(System.lineSeparator()) print("class PangramsTest extends FunSuite with Matchers {" + System.lineSeparator()) writeTestCases() print("}" + System.lineSeparator()) } private def writeTestCases(): Unit = { val testCases = (json \ "cases").get.as[List[PangramTestCase]] testCases.foreach(tc => { print("\ttest(\"" + tc.description + "\") {" + System.lineSeparator()) println("Pangrams.isPangram(\"" + tc.input + "\") should be (" + tc.expected + ")") print("\t}" + System.lineSeparator()) print(System.lineSeparator()) }) } } case class PangramTestCase(description: String, input: String, expected: Boolean) object PangramsTestGenerator { def main(args: Array[String]): Unit = { new PangramsTestGenerator().write } }
Version data entries
136 entries across 136 versions & 1 rubygems