diff --git a/config.json b/config.json index 08addedd..3a62b60a 100644 --- a/config.json +++ b/config.json @@ -197,6 +197,10 @@ "slug": "crypto-square", "difficulty": 1, "topics": [ + "Strings", + "Lists", + "Security", + "Transforming" ] }, { diff --git a/exercises/crypto-square/example.scala b/exercises/crypto-square/example.scala index 6b69b3c2..3977ca6b 100644 --- a/exercises/crypto-square/example.scala +++ b/exercises/crypto-square/example.scala @@ -1,4 +1,4 @@ -case class CryptoSquare() { +object CryptoSquare { def normalizePlaintext(text: String): String = text.filter(c => c.isLetterOrDigit).toLowerCase diff --git a/exercises/crypto-square/src/main/scala/CryptoSquare.scala b/exercises/crypto-square/src/main/scala/CryptoSquare.scala new file mode 100644 index 00000000..5645d3c0 --- /dev/null +++ b/exercises/crypto-square/src/main/scala/CryptoSquare.scala @@ -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 = ??? +} diff --git a/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala b/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala index e122bd43..82107cb9 100644 --- a/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala +++ b/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala @@ -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("") } }