From 1ee18c2bf5e00c1d3ebeff85c891709b2889b504 Mon Sep 17 00:00:00 2001 From: Kelong Cong Date: Wed, 19 Nov 2014 22:41:58 +0000 Subject: [PATCH] added test to cabal --- enigma-hs.cabal | 10 ++++++++ {test => src}/Test.hs | 53 +++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 19 deletions(-) rename {test => src}/Test.hs (70%) diff --git a/enigma-hs.cabal b/enigma-hs.cabal index 18fd085..89796e8 100644 --- a/enigma-hs.cabal +++ b/enigma-hs.cabal @@ -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 + + diff --git a/test/Test.hs b/src/Test.hs similarity index 70% rename from test/Test.hs rename to src/Test.hs index 6dd9874..2b451ac 100644 --- a/test/Test.hs +++ b/src/Test.hs @@ -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 +