1
exercism fetch purescript crypto-square

test/Main.purs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit.Assert as Assert
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import CryptoSquare ( normalizedPlaintext
                    , plaintextSegments
                    , encoded
                    , ciphertext
                    )

main :: forall eff
  . Eff ( avar :: AVAR
        , console :: CONSOLE
        , testOutput :: TESTOUTPUT
        | eff                     
        )
        Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
  suite "CryptoSquare.normalizedPlaintext" do

    test "Lowercase" $
      Assert.equal "hello"
                   (normalizedPlaintext "Hello")

    test "Remove spaces" $
      Assert.equal "hithere"
                   (normalizedPlaintext "Hi there")

    test "Remove punctuation" $
      Assert.equal "123go"
                   (normalizedPlaintext "@1, 2%, 3 Go!")

  suite "CryptoSquare.plaintextSegments" do

    test "empty plaintext results in an empty rectangle" $
      Assert.equal
        []
        (plaintextSegments "")

    test "4 character plaintext results in an 2x2 rectangle" $
      Assert.equal
        [ "ab"
        , "cd"
        ]
        (plaintextSegments "Ab Cd")

    test "9 character plaintext results in an 3x3 rectangle" $
      Assert.equal
        [ "thi"
        , "sis"
        , "fun"
        ]
        (plaintextSegments "This is fun!")

    test "54 character plaintext results in an 8x7 rectangle" $
      Assert.equal
        [ "ifmanwas"
        , "meanttos"
        , "tayonthe"
        , "groundgo"
        , "dwouldha"
        , "vegivenu"
        , "sroots"
        ]
        (plaintextSegments "If man was meant to stay on the ground, god would have given us roots.")

  suite "CryptoSquare.encoded" do

    test "empty plaintext results in an empty encode" $
      Assert.equal
        ""
        (encoded "")

    test "Non-empty plaintext results in the combined plaintext segments" $
      Assert.equal
        "imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau"
        (encoded "If man was meant to stay on the ground, god would have given us roots.")

  suite "CryptoSquare.ciphertext" do

    test "empty plaintext results in an empty ciphertext" $
      Assert.equal
        ""
        (ciphertext "")

    test "9 character plaintext results in 3 chunks of 3 characters" $
      Assert.equal
        "tsf hiu isn"
        (ciphertext "This is fun!")

    test "54 character plaintext results in 7 chunks, the last two padded with spaces" $
      Assert.equal
        "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn  sseoau "
        (ciphertext "If man was meant to stay on the ground, god would have given us roots.")