Sha256: d5301ed6fb795c22630c4ae3b69ef382061976e1b4d1f4041707da29fb85e66b

Contents?: true

Size: 1.66 KB

Versions: 96

Compression:

Stored size: 1.66 KB

Contents

import play.api.libs.json.Json

import scala.io.Source

class AllYourBaseTestGenerator {
  implicit val testCaseReader = Json.reads[TestCase]

  private val filename = "all-your-base.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 AllYourBaseTest extends FunSuite with Matchers {" + System.lineSeparator())

    writeTestCases()

    print("}" + System.lineSeparator())
  }

  private def writeTestCases(): Unit = {
    val testCases = (json \ "cases").get.as[List[TestCase]]

    testCases.foreach(tc => {
      print("\ttest(\"" + tc.description + "\") {" + System.lineSeparator())
      println("pending")
      println("AllYourBase.rebase(" + tc.input_base  + ", " + toListString(tc.input_digits) +
        "," + System.lineSeparator() + tc.output_base + ") should be (" + toListString(tc.output_digits) + ")")

      print("\t}" + System.lineSeparator())
      print(System.lineSeparator())
    })
  }

  private def toListString(a: Array[Int]): String =
      "List(" + a.mkString(", ") + ")"

  private def toListString(o: Option[Array[Int]]): String = {
    o match {
      case Some(a) => "Some(List(" + a.mkString(" ,") + "))"
      case None => "None"
    }
  }
}

case class TestCase(description: String,
                    input_base: Int, input_digits: Array[Int],
                    output_base: Int, output_digits: Option[Array[Int]])

object AllYourBaseTestGenerator {
  def main(args: Array[String]): Unit = {
    new AllYourBaseTestGenerator().write
  }
}

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
trackler-2.0.6.40 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.39 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.38 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.37 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.36 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.35 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.34 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.33 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.32 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.31 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.30 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.29 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.28 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.27 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.26 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.25 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.24 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.23 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.22 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala
trackler-2.0.6.21 tracks/scala/testgen/src/main/scala/AllYourBaseTestGenerator.scala