Skip to content

Commit

Permalink
Update atbash-cipher to match latest canonical json.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricemery committed Feb 8, 2018
1 parent b0ab07b commit 567e689
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
32 changes: 18 additions & 14 deletions exercises/atbash-cipher/src/test/scala/AtbashCipherTest.scala
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
import org.scalatest.{Matchers, FunSuite}

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

test("encode yes") {
AtbashCipher.encode("yes") should be ("bvh")
AtbashCipher.encode("yes") should be("bvh")
}

test("encode no") {
pending
AtbashCipher.encode("no") should be ("ml")
AtbashCipher.encode("no") should be("ml")
}

test("encode OMG") {
pending
AtbashCipher.encode("OMG") should be ("lnt")
AtbashCipher.encode("OMG") should be("lnt")
}

test("encode spaces") {
pending
AtbashCipher.encode("O M G") should be ("lnt")
AtbashCipher.encode("O M G") should be("lnt")
}

test("encode mindblowingly") {
pending
AtbashCipher.encode("mindblowingly") should be ("nrmwy oldrm tob")
AtbashCipher.encode("mindblowingly") should be("nrmwy oldrm tob")
}

test("encode numbers") {
pending
AtbashCipher.encode("Testing,1 2 3, testing.") should be ("gvhgr mt123 gvhgr mt")
AtbashCipher.encode("Testing,1 2 3, testing.") should be(
"gvhgr mt123 gvhgr mt")
}

test("encode deep thought") {
pending
AtbashCipher.encode("Truth is fiction.") should be ("gifgs rhurx grlm")
AtbashCipher.encode("Truth is fiction.") should be("gifgs rhurx grlm")
}

test("encode all the letters") {
pending
AtbashCipher.encode("The quick brown fox jumps over the lazy dog.") should be ("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")
AtbashCipher.encode("The quick brown fox jumps over the lazy dog.") should be(
"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")
}

test("decode exercism") {
pending
AtbashCipher.decode("vcvix rhn") should be ("exercism")
AtbashCipher.decode("vcvix rhn") should be("exercism")
}

test("decode a sentence") {
pending
AtbashCipher.decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") should be ("anobstacleisoftenasteppingstone")
AtbashCipher.decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") should be(
"anobstacleisoftenasteppingstone")
}

test("decode numbers") {
pending
AtbashCipher.decode("gvhgr mt123 gvhgr mt") should be ("testing123testing")
AtbashCipher.decode("gvhgr mt123 gvhgr mt") should be("testing123testing")
}

test("decode all the letters") {
pending
AtbashCipher.decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") should be ("thequickbrownfoxjumpsoverthelazydog")
AtbashCipher.decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") should be(
"thequickbrownfoxjumpsoverthelazydog")
}
}
}
2 changes: 1 addition & 1 deletion testgen/src/main/scala/AtbashCipherTestGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object AtbashCipherTestGenerator {
val file = new File("src/main/resources/atbash-cipher.json")

val code = TestSuiteBuilder.build(file,
fromLabeledTestAlt("encode" -> Seq("phrase"), "decode" -> Seq("phrase")))
fromLabeledTestAltFromInput("encode" -> Seq("phrase"), "decode" -> Seq("phrase")))
println(s"-------------")
println(code)
println(s"-------------")
Expand Down
19 changes: 19 additions & 0 deletions testgen/src/main/scala/testgen/TestSuiteBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ object TestSuiteBuilder {
TestCaseData(labeledTest.description, sutCall, expected)
}

// Use when arguments are layered under "input" json element
def fromLabeledTestAltFromInput(propArgs: (String, Seq[String])*): ToTestCaseData =
withLabeledTest { sut => labeledTest =>
val sutFunction = labeledTest.property
val args = sutArgsAltFromInput(labeledTest.result, propArgs:_*)
val sutCall = s"$sut.$sutFunction(${args})"
val expected = toString(labeledTest.expected)

TestCaseData(labeledTest.description, sutCall, expected)
}

def main(args: Array[String]): Unit = {
val path = "src/main/resources"
val input: Map[String, ToTestCaseData] =
Expand Down Expand Up @@ -138,6 +149,14 @@ object TestSuiteBuilder {
sutArgs(parseResult, argNames:_*)
} head

// Use when arguments are layered under "input" json element
def sutArgsAltFromInput(parseResult: CanonicalDataParser.ParseResult, propArgs: (String, Seq[String])*): String =
propArgs collect {
case ((property, argNames)) if parseResult("property") == property =>
sutArgsFromInput(parseResult, argNames:_*)
} head


private def toString(expected: CanonicalDataParser.Expected): String =
expected.fold(error => s"Left(${toString(error)})", toString)

Expand Down

0 comments on commit 567e689

Please sign in to comment.