Skip to content

Commit

Permalink
Add tests! 🧪 (property testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
kutyel committed May 21, 2019
1 parent db964b4 commit 3c7f99f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion morse.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ executable morse

test-suite tests
hs-source-dirs: tests
main-is: test.hs
main-is: Spec.hs
ghc-options: -Wall -fno-warn-orphans
type: exitcode-stdio-1.0
default-language: Haskell2010
Expand Down
24 changes: 24 additions & 0 deletions tests/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Main where

import qualified Data.Map as M
import Morse
import Test.QuickCheck

allowedChars :: [Char]
allowedChars = M.keys letterToMorse

allowedMorse :: [Morse]
allowedMorse = M.elems letterToMorse

charGen :: Gen Char
charGen = elements allowedChars

morseGen :: Gen Morse
morseGen = elements allowedMorse

prop_thereAndBackAgain :: Property
prop_thereAndBackAgain =
forAll charGen (\c -> ((charToMorse c) >>= morseToChar) == Just c)

main :: IO ()
main = quickCheck prop_thereAndBackAgain

0 comments on commit 3c7f99f

Please sign in to comment.