File: main.hs

package info (click to toggle)
haskell-puremd5 2.1.4-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 72 kB
  • sloc: haskell: 303; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Main where

import Test.Framework
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.MD5
import Data.Digest.Pure.MD5
import Data.Char (isSpace)
import Data.ByteString.Lazy (toStrict, ByteString)
import qualified Data.Binary as B
import qualified Data.Serialize as S
import Hexdump

main :: IO ()
main = defaultMain
  [ testGroup "MD5 functional correctness tests" base_tests
  , testGroup "Serialization order correctness tests" serialization_tests
  ]

-- | Use the crypto-api-tests, piddly as they are, to give evidence of
-- functional correctness.
base_tests :: [Test]
base_tests = makeMD5Tests (undefined :: MD5Digest)

-- | Ensure the output of `show`, `Serialize`, `Binary`, and `md5DigestBytes`
-- are all consistent.
serialization_tests :: [Test]
serialization_tests =
  [ testProperty "show == simple_hex . Serialize.encode"
      (\bs -> let d = hsh bs in show d == filter (not . isSpace) (simpleHex (S.encode d)))
  , testProperty "Serialize.encode == toStrict . Binary.encode"
      (\bs -> let d = hsh bs in toStrict (B.encode d) == S.encode d)
  , testProperty "Serialize.encode == md5DigestBytes"
      (\bs -> let d = hsh bs in S.encode d == md5DigestBytes d)
  ]
 where
 hsh = hash :: ByteString -> MD5Digest