Skip to content

Commit

Permalink
Atbash - use object instead of an instance - refs exercism#242. Add A…
Browse files Browse the repository at this point in the history
…tbash.scala - refs exercism#137. Add topics to config.json - refs exercism#125
  • Loading branch information
ricemery committed Dec 15, 2016
1 parent 29079be commit 39c35b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
"slug": "atbash-cipher",
"difficulty": 1,
"topics": [
"Strings",
"Transforming",
"Security"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions exercises/atbash-cipher/example.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
case class Atbash() {
def encode(s: String): String =
s.foldLeft("")((acc, c) => acc + substitute(c)).grouped(5).mkString(" ")

object Atbash {
private def substitute(c: Char) =
if (c.isDigit) c.toString
else if (c.isLetter) ('a' + ('z' - c.toLower)).toChar.toString
else ""

def encode(s: String): String =
s.foldLeft("")((acc, c) => acc + substitute(c)).grouped(5).mkString(" ")
}
3 changes: 3 additions & 0 deletions exercises/atbash-cipher/src/main/scala/Atbash.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Atbash {
def encode(s: String): String = ???
}
18 changes: 9 additions & 9 deletions exercises/atbash-cipher/src/test/scala/atbash_test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@ import org.scalatest.{Matchers, FlatSpec}

class AtbashTest extends FlatSpec with Matchers {
it should "encode no" in {
Atbash().encode("no") should equal("ml")
Atbash.encode("no") should equal("ml")
}

it should "encode yes" in {
pending
Atbash().encode("yes") should equal("bvh")
Atbash.encode("yes") should equal("bvh")
}

it should "encode OMG" in {
pending
Atbash().encode("OMG") should equal("lnt")
Atbash.encode("OMG") should equal("lnt")
}

it should "encode lowercase omg" in {
pending
Atbash().encode("omg") should equal("lnt")
Atbash.encode("omg") should equal("lnt")
}

it should "encode O M G" in {
pending
Atbash().encode("O M G ") should equal("lnt")
Atbash.encode("O M G ") should equal("lnt")
}

it should "encode and group string " in {
pending
Atbash().encode("mindblowingly") should equal("nrmwy oldrm tob")
Atbash.encode("mindblowingly") should equal("nrmwy oldrm tob")
}

it should "encode string with digits and punctuation" in {
pending
Atbash().encode("Testing, 1 2 3, testing. ") should equal("gvhgr mt123 gvhgr mt")
Atbash.encode("Testing, 1 2 3, testing. ") should equal("gvhgr mt123 gvhgr mt")
}

it should "encode \"Truth is fiction.\"" in {
pending
Atbash().encode("Truth is fiction.") should equal("gifgs rhurx grlm")
Atbash.encode("Truth is fiction.") should equal("gifgs rhurx grlm")
}

it should "encode a long string" in {
pending
Atbash().encode("The quick brown fox jumps over the lazy dog.") should
Atbash.encode("The quick brown fox jumps over the lazy dog.") should
equal("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")
}
}

0 comments on commit 39c35b3

Please sign in to comment.