Sha256: 2de12043a6832cf83e71be76ad49f549eb0b2b40bd146f3e55ed6d359e3d5517

Contents?: true

Size: 1.68 KB

Versions: 108

Compression:

Stored size: 1.68 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, fromLabeledTest("input"))
    println(s"-------------")
    println(code)
    println(s"-------------")
  }

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

        TestCaseData(labeledTest.description, sutCall, expected)
    }

  def sutArgs(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
    argNames map (name => toString(parseResult(name))) mkString ", "

  def toString(expected: CanonicalDataParser.Expected): String = {
    expected match {
      case Left(error) => 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 "\""

    System.out.println(any.getClass)

    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

108 entries across 108 versions & 1 rubygems

Version Path
trackler-2.2.1.110 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.109 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.108 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.107 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.106 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.105 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.104 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.103 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.102 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.101 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.100 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.99 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.98 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.97 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.96 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.95 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.94 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.93 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.92 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala
trackler-2.2.1.91 tracks/scala/testgen/src/main/scala/PrimeFactorsTestGenerator.scala