Skip to content

Commit

Permalink
Update allergies test generator to match latest canonical json.
Browse files Browse the repository at this point in the history
This was just an update of the JSON format, and the generator. The actual test cases did not change.

Refs exercism#488
  • Loading branch information
ricemery committed Feb 8, 2018
1 parent b0ab07b commit e5ea36a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exercises/allergies/src/test/scala/AllergiesTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.scalatest.{Matchers, FunSuite}

/** @version 1.0.0 */
/** @version 1.1.0 */
class AllergiesTest extends FunSuite with Matchers {

test("Allergen.Peanuts - no allergies means not allergic") {
Expand Down
13 changes: 8 additions & 5 deletions testgen/src/main/scala/AllergiesTestGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.File

import testgen.TestSuiteBuilder._
import testgen.TestSuiteBuilder.{fromLabeledTestFromInput, _}
import testgen._

object AllergiesTestGenerator {
Expand Down Expand Up @@ -30,10 +30,13 @@ object AllergiesTestGenerator {
def sutArgs(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
argNames map (name => TestSuiteBuilder.toString(parseResult(name))) mkString ", "

def fromLabeledTest(argNames: String*): ToTestCaseDataList =
def getScore(labeledTest: LabeledTest): Int =
labeledTest.result("input").asInstanceOf[Map[String, Any]]("score").asInstanceOf[Int]

def fromLabeledTestFromInput(argNames: String*): ToTestCaseDataList =
withLabeledList { sut =>
labeledTest =>
val score = labeledTest.result("score").asInstanceOf[Int]
val score = getScore(labeledTest)
val property = labeledTest.property
if ("allergicTo".equals(property)) {
val expected: List[(String, Boolean)] = toAllergicToExpected(labeledTest.expected)
Expand All @@ -44,15 +47,15 @@ object AllergiesTestGenerator {
TestCaseData(s"${e._1} - ${labeledTest.description}", sutCall, result)
})
} else {
val args = sutArgs(labeledTest.result, "score")
val args = sutArgsFromInput(labeledTest.result, "score")
val expected = toListExpected(labeledTest.expected)
val sutCall =
s"""$sut.$property($args)"""
List(TestCaseData(labeledTest.description, sutCall, expected))
}
}

val code = TestSuiteBuilder.buildFromList(file, fromLabeledTest("score"))
val code = TestSuiteBuilder.buildFromList(file, fromLabeledTestFromInput("score"))
println(s"-------------")
println(code)
println(s"-------------")
Expand Down

0 comments on commit e5ea36a

Please sign in to comment.