Skip to content

Commit

Permalink
CryptoSquare - use object instead of an instance - refs exercism#242.…
Browse files Browse the repository at this point in the history
… Add CryptoSquare.scala - refs exercism#137. Add topics to config.json - refs exercism#125
  • Loading branch information
ricemery committed Dec 15, 2016
1 parent 29079be commit fe7f3b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
"slug": "crypto-square",
"difficulty": 1,
"topics": [
"Strings",
"Lists",
"Security",
"Transforming"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion exercises/crypto-square/example.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
case class CryptoSquare() {
object CryptoSquare {
def normalizePlaintext(text: String): String =
text.filter(c => c.isLetterOrDigit).toLowerCase

Expand Down
11 changes: 11 additions & 0 deletions exercises/crypto-square/src/main/scala/CryptoSquare.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object CryptoSquare {
def normalizePlaintext(text: String): String = ???

def squareSize(text: String): Int = ???

def plaintextSegments(text: String): List[String] = ???

def ciphertext(text: String): String = ???

def normalizedCiphertext(text: String): String = ???
}
34 changes: 17 additions & 17 deletions exercises/crypto-square/src/test/scala/CryptoSquareTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,71 @@ import org.scalatest.{Matchers, FlatSpec}

class CrytpoSquareTest extends FlatSpec with Matchers {
it should "normalize away special characters" in {
CryptoSquare().normalizePlaintext("s#!@$%pl\t\r\nunk") should equal("splunk")
CryptoSquare.normalizePlaintext("s#!@$%pl\t\r\nunk") should equal("splunk")
}

it should "normalize uppercase to lowercase" in {
pending
CryptoSquare().normalizePlaintext("1, 2, 3 GO!") should equal("123go")
CryptoSquare.normalizePlaintext("1, 2, 3 GO!") should equal("123go")
}


it should "calc a square size for a perfect square" in {
pending
CryptoSquare().squareSize("1234") should equal(2)
CryptoSquare().squareSize("123456789") should equal(3)
CryptoSquare.squareSize("1234") should equal(2)
CryptoSquare.squareSize("123456789") should equal(3)
}

it should "calc a square size when not a perfect square" in {
pending
CryptoSquare().squareSize("123456789abc") should equal(4)
CryptoSquare().squareSize("123456789abcd") should equal(4)
CryptoSquare.squareSize("123456789abc") should equal(4)
CryptoSquare.squareSize("123456789abcd") should equal(4)
}

it should "not generate calc error when empty string" in {
pending
CryptoSquare().squareSize("") should equal(0)
CryptoSquare.squareSize("") should equal(0)
}


it should "build plaintext segments - all equal segment lengths" in {
pending
CryptoSquare().plaintextSegments("Never vex thine heart with idle woes.") should
CryptoSquare.plaintextSegments("Never vex thine heart with idle woes.") should
equal(List("neverv", "exthin", "eheart", "withid", "lewoes"))
}

it should "build plaintext segments - last segment short" in {
pending
CryptoSquare().plaintextSegments("ZOMG! ZOMBIES!!!") should
CryptoSquare.plaintextSegments("ZOMG! ZOMBIES!!!") should
equal(List("zomg", "zomb", "ies"))
}

it should "build cipher text" in {
pending
CryptoSquare().ciphertext("Time is an illusion. Lunchtime doubly so.") should
CryptoSquare.ciphertext("Time is an illusion. Lunchtime doubly so.") should
equal("tasneyinicdsmiohooelntuillibsuuml")
CryptoSquare().ciphertext("We all know interspecies romance is weird.") should
CryptoSquare.ciphertext("We all know interspecies romance is weird.") should
equal("wneiaweoreneawssciliprerlneoidktcms")
}

it should "build normalized cipher text" in {
pending
CryptoSquare().normalizedCiphertext("Madness, and then illumination.") should
CryptoSquare.normalizedCiphertext("Madness, and then illumination.") should
equal("msemo aanin dnin ndla etlt shui")
CryptoSquare().normalizedCiphertext("If man was meant to stay on the ground " +
CryptoSquare.normalizedCiphertext("If man was meant to stay on the ground " +
"god would have given us roots") should
equal("imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau")
}

it should "not error on blank strings" in {
pending
CryptoSquare().ciphertext("") should
CryptoSquare.ciphertext("") should
equal("")
CryptoSquare().ciphertext(" ") should
CryptoSquare.ciphertext(" ") should
equal("")
CryptoSquare().normalizedCiphertext("") should
CryptoSquare.normalizedCiphertext("") should
equal("")
CryptoSquare().normalizedCiphertext(" ") should
CryptoSquare.normalizedCiphertext(" ") should
equal("")
}
}

0 comments on commit fe7f3b9

Please sign in to comment.