Skip to content

Commit

Permalink
added test to cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelong Cong committed Nov 19, 2014
1 parent 07a7aa4 commit 1ee18c2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
10 changes: 10 additions & 0 deletions enigma-hs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ executable enigma-hs
build-depends: base >=4.6
hs-source-dirs: src
default-language: Haskell2010

test-suite enigma-test
ghc-options: -Wall
type: exitcode-stdio-1.0
main-is: Test.hs
hs-source-dirs: src
build-depends: base >=4.6
default-language: Haskell2010


53 changes: 34 additions & 19 deletions test/Test.hs → src/Test.hs
Original file line number Diff line number Diff line change
@@ -1,73 +1,88 @@

import Helper
import Enigma
import System.Exit (exitFailure, exitSuccess)

-- general tests --------------------------------------------------------------
aaaConf :: Conf
aaaConf = Conf plugs refB [rtypeI,rtypeII,rtypeIII] "AAA"

aaaState :: String
aaaState = "AAA"

-- encoding those letter will cause two rotors to rotate
aaaTest3A :: Bool
aaaTest3A = enigma aaaConf "AAT" "AAA" == "BMU"

aaaTest48A :: Bool
aaaTest48A =
enigma aaaConf aaaState (replicate 48 'A')
== "BDZGOWCXLTKSBTMCDLPBMUQOFXYHCXTGYJFLINHNXSHIUNTH"

aaaTest48ADecode :: Bool
aaaTest48ADecode =
enigma aaaConf aaaState "BDZGOWCXLTKSBTMCDLPBMUQOFXYHCXTGYJFLINHNXSHIUNTH"
== replicate 48 'A'


-- rotor test -----------------------------------------------------------------
rotorTest :: Bool
rotorTest =
((rotateRotor 0 aaaConf) . (rotateRotor 1 aaaConf) . (rotateRotor 2 aaaConf)) "AAU"
== "AAV"


-- detailed tests: encode A at rotor pos AAV using default settings -----------
rotor2FwdTest :: Bool
rotor2FwdTest =
(rotor Fwd ((getType aaaConf) !! 2) ((getRing aaaConf) !! 2) 'V' 'A')
== 'R'

-- carried forward from rotor2FwdTest
rotor1FwdTest :: Bool
rotor1FwdTest =
(rotor Fwd ((getType aaaConf) !! 1) ((getRing aaaConf) !! 1) 'A' 'R')
== 'G'

-- carried forward from rotor1FwdTest
rotor0FwdTest :: Bool
rotor0FwdTest =
(rotor Fwd ((getType aaaConf) !! 0) ((getRing aaaConf) !! 0) 'A' 'G')
== 'D'

-- reflector
reflectorTest :: Bool
reflectorTest = reflector refB 'D' == 'H'

-- backwards now..
rotor0BwdTest :: Bool
rotor0BwdTest =
(rotor Bwd ((getType aaaConf) !! 0) ((getRing aaaConf) !! 0) 'A' 'H')
== 'P'

rotor1BwdTest :: Bool
rotor1BwdTest =
(rotor Bwd ((getType aaaConf) !! 1) ((getRing aaaConf) !! 1) 'A' 'P')
==
'U'
== 'U'

rotor2BwdTest :: Bool
rotor2BwdTest =
(rotor Bwd ((getType aaaConf) !! 2) ((getRing aaaConf) !! 2) 'V' 'U')
==
'M'

main =
print $
aaaTest3A &&
aaaTest48A &&
aaaTest48ADecode &&
rotorTest &&
rotor2FwdTest &&
rotor1FwdTest &&
rotor0FwdTest &&
reflectorTest &&
rotor0BwdTest &&
rotor1BwdTest &&
rotor2BwdTest
== 'M'

runTest :: Bool
runTest =
aaaTest3A &&
aaaTest48A &&
aaaTest48ADecode &&
rotorTest &&
rotor2FwdTest &&
rotor1FwdTest &&
rotor0FwdTest &&
reflectorTest &&
rotor0BwdTest &&
rotor1BwdTest &&
rotor2BwdTest

main = if runTest then exitSuccess else exitFailure


0 comments on commit 1ee18c2

Please sign in to comment.