]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/test/HUnit/Credential.hs
protocol: Fix Arith
[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 "RDfIgdmiCkU46pK"
19 , testCase "BeleniosParams" $
20 S.evalState randomCredential (Random.mkStdGen 0) @?=
21 Credential @BeleniosParams "RDfIgdmiCkU46pr"
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 , "RDfIgdmiCkU462" ==> Left CredentialError_Length
30 , "RDfIgdmiCkU46pKE" ==> Left CredentialError_Length
31 , "RDfIgdmiCkU46pJ" ==> Left CredentialError_Checksum
32 , "RDfIgdmiCkU46pK" ==> Right (Credential "RDfIgdmiCkU46pK")
33 ]
34 , testGroup "BeleniosParams" $
35 let (==>) inp (exp::Either CredentialError (Credential BeleniosParams)) =
36 testCase (show inp) $ readCredential inp @?= exp in
37 [ "RDfIgdmiCkU46R" ==> Left CredentialError_Length
38 , "RDfIgdmiCkU46pKR" ==> Left CredentialError_Length
39 , "RDfIgdmiCkU46ps" ==> Left CredentialError_Checksum
40 , "RDfIgdmiCkU46pr" ==> Right (Credential "RDfIgdmiCkU46pr")
41 ]
42 ]
43 ]