Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update allergies test generator to match latest canonical json. #492

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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