Sha256: a933f454631dc354a620882ce2045c12fa6d252ff437708dc140476932179e56

Contents?: true

Size: 1.77 KB

Versions: 96

Compression:

Stored size: 1.77 KB

Contents

{-# LANGUAGE RecordWildCards #-}

import Data.Char         (isSpace)
import Data.Foldable     (for_)
import Data.Function     (on)
import Test.Hspec        (Spec, describe, it, shouldBe, shouldMatchList)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import CryptoSquare (encode)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = describe "encode" $ for_ cases test
  where

    test Case{..} = describe description $ do

      let shouldMatchWords  = shouldBe        `on` words
          shouldMatchString = shouldBe        `on` filter (not . isSpace)
          shouldMatchChars  = shouldMatchList `on` filter (not . isSpace)

      it "normalizes the input"    $ encode input `shouldMatchChars`  expected
      it "reorders the characters" $ encode input `shouldMatchString` expected
      it "groups the output"       $ encode input `shouldMatchWords`  expected

data Case = Case { description :: String
                 , input       :: String
                 , expected    :: String
                 }

cases :: [Case]
cases = [ Case { description = "perfect square, all lowercase with space"
               , input       = "a dog"
               , expected    = "ao dg"
               }
        , Case { description = "perfect rectangle, mixed case"
               , input       = "A camel"
               , expected    = "am ce al"
               }
        , Case { description = "incomplete square with punctuation"
               , input       = "Wait, fox!"
               , expected    = "wtx af io"
               }
        , Case { description = "incomplete rectangle with symbols"
               , input       = "cat | cut -d@ -f1 | sort | uniq"
               , expected    = "ctoi adrq tft c1u usn"
               }
        ]

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
trackler-2.2.1.45 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.44 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.43 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.42 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.41 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.40 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.39 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.38 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.37 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.36 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.35 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.34 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.33 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.32 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.31 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.30 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.29 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.28 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.27 tracks/haskell/exercises/crypto-square/test/Tests.hs
trackler-2.2.1.26 tracks/haskell/exercises/crypto-square/test/Tests.hs