Sha256: 9e35b71d71caa488726fdfbb8c67a72a4d73ae30cf07552f08a640e1ca4eb67e

Contents?: true

Size: 1.69 KB

Versions: 148

Compression:

Stored size: 1.69 KB

Contents

import org.scalatest.{Matchers, FunSuite}

/** @version created manually **/
class CipherTest extends FunSuite with Matchers {

  test("Random key cipher - can encode/decode") {
    // Here we take advantage of the fact that plaintext of "aaa..."
    // outputs the key. This is a critical problem with shift ciphers, some
    // characters will always output the key verbatim.

    val cipher = Cipher(None)
    cipher.encode("aaaaaaaaaa") should be (cipher.key.substring(0, 10))
    cipher.decode(cipher.key.substring(0, 10)) should be ("aaaaaaaaaa")
  }

  test("Invalid key - contains caps") { 
    pending
    intercept[IllegalArgumentException] { 
      Cipher(Some("ABCD"))
    }
  }

  test("Invalid key - contains numerics") { 
    pending
    intercept[IllegalArgumentException] {
      Cipher(Some("123"))
    }
  }

  test("Invalid key - is empty") { 
    pending
    intercept[IllegalArgumentException] {
      Cipher(Some(""))
    }
  }

  test("Substitution cipher - can encode") { 
    pending
    Cipher(Some("abcdefghij")).encode("aaaaaaaaaa") should be ("abcdefghij")
  }

  test("Substitution cipher - can decode") { 
    pending
    Cipher(Some("abcdefghij")).decode("abcdefghij") should be ("aaaaaaaaaa")
  }

  test("Substitution cipher - is reversible") { 
    pending
    val cipher = Cipher(Some("abcdefghij"))
    cipher.decode(cipher.encode("abcdefghij")) should be ("abcdefghij")
  }

  test("Substitution cipher - can double shift") { 
    pending
    val cipher = Cipher(Some("iamapandabear"))
    cipher.encode("iamapandabear") should be ("qayaeaagaciai")
  }

  test("Substitution cipher - can wrap") { 
    pending
    Cipher(Some("abcdefghij")).encode("zzzzzzzzzz") should be ("zabcdefghi")
  }
}

Version data entries

148 entries across 148 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.179 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.178 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.177 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.176 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.175 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.174 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.173 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.172 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.171 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.170 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.169 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.167 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.166 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.165 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.164 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.163 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.162 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.161 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala
trackler-2.2.1.160 tracks/scala/exercises/simple-cipher/src/test/scala/CipherTest.scala