]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/test/HUnit/Credential.hs
protocol: Fix Election
[majurity.git] / hjugement-protocol / test / HUnit / Credential.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE TypeApplications #-}
4 module HUnit.Credential where
5
6 import qualified Control.Monad.Trans.State.Strict as S
7 import qualified System.Random as Random
8
9 import Protocol.Arith
10 import Protocol.Credential
11 import HUnit.Utils
12
13 hunit :: TestTree
14 hunit = testGroup "Credential"
15 [ testGroup "randomCredential"
16 [ testCase "WeakParams" $
17 S.evalState randomCredential (Random.mkStdGen 0) @?=
18 Credential @WeakParams "RDfIgdmiCkU46pD"
19 , testCase "BeleniosParams" $
20 S.evalState randomCredential (Random.mkStdGen 0) @?=
21 Credential @BeleniosParams "RDfIgdmiCkU46pD"
22 ]
23 , testGroup "readCredential"
24 [ testGroup "WeakParams" $
25 let (==>) inp (exp::Either CredentialError (Credential WeakParams)) =
26 testCase (show inp) $ readCredential inp @?= exp in
27 [ "" ==> Left CredentialError_Length
28 , "RDfIgdmiCkU46_K" ==> Left (CredentialError_BadChar '_')
29 , "RDfIgdmiCkU46f" ==> Left CredentialError_Length
30 , "RDfIgdmiCkU46pK7" ==> Left CredentialError_Length
31 , "RDfIgdmiCkU46pE" ==> Left CredentialError_Checksum
32 , "RDfIgdmiCkU46pD" ==> Right (Credential "RDfIgdmiCkU46pD")
33 ]
34 , testGroup "BeleniosParams" $
35 let (==>) inp (exp::Either CredentialError (Credential BeleniosParams)) =
36 testCase (show inp) $ readCredential inp @?= exp in
37 [ "RDfIgdmiCkU46f" ==> Left CredentialError_Length
38 , "RDfIgdmiCkU46pK7" ==> Left CredentialError_Length
39 , "RDfIgdmiCkU46pE" ==> Left CredentialError_Checksum
40 , "RDfIgdmiCkU46pD" ==> Right (Credential "RDfIgdmiCkU46pD")
41 ]
42 ]
43 ]