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.0.5 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.0.4 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.0.3 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.0.2 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.0.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-2.0.0.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.4.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.4.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.3.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.2.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.2.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.1.2 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.1.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.1.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.0.1 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala
trackler-1.0.0 tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala