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

Version Path
trackler-2.0.6.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.18 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.17 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.16 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.15 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.14 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.13 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.12 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.11 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.10 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.9 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.8 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.7 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.6 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.5 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.4 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.3 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.2 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.5.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala