Sha256: 625593c03da0f46de932a2757a812cba7fc1fbf7c024f511449e997ff74b800f

Contents?: true

Size: 1.72 KB

Versions: 68

Compression:

Stored size: 1.72 KB

Contents

import java.io.File

import testgen.TestSuiteBuilder.{toString, _}
import testgen.{CanonicalDataParser, TestCaseData, TestSuiteBuilder}

object PrimeFactorsTestGenerator {
  def main(args: Array[String]): Unit = {
    val file = new File("src/main/resources/prime-factors.json")

    val code = TestSuiteBuilder.build(file, fromLabeledTestFromInput("value"))
    println(s"-------------")
    println(code)
    println(s"-------------")
  }

  private def fromLabeledTestFromInput(argNames: String*): ToTestCaseData =
    withLabeledTest { sut =>
      labeledTest =>
        val sutFunction = labeledTest.property
        val args = sutArgsFromInput(labeledTest.result, argNames: _*)
        val sutCall = s"$sut.$sutFunction($args)"
        val expected = toString(labeledTest.expected)

        TestCaseData(labeledTest.description, sutCall, expected)
    }

  def sutArgsFromInput(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
    argNames map (name => toString(parseResult("input").asInstanceOf[Map[String, Any]](name))) mkString ", "

  def toString(expected: CanonicalDataParser.Expected): String = {
    expected match {
      case Left(_) => throw new IllegalStateException("Unexpected Left")
      case Right(exp) => s"${toString(exp)}"
    }
  }

  private def toString(any: Any): String = {
    def quote(str: String): String =
      if ("\"\n" exists (str.contains(_:Char))) "\"\"\"" else "\""

    any match {
      case list: List[_] =>
        val vals = list.map(s => toString(s)).mkString(", ")
        s"List($vals)"
      case str: String =>
        val quot = quote(str)
        s"$quot$str$quot"
      case dbl: Double =>
        dbl.asInstanceOf[Long].toString + "l"
      case _ => any.toString
    }
  }
}

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.179 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.178 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.177 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.176 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.175 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.174 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.173 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.172 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.171 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.170 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.169 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.167 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.166 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.165 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.164 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.163 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.162 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.161 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.160 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala