File: Bitstest.hs

package info (click to toggle)
missingh 1.6.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 688 kB
  • sloc: haskell: 5,472; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,120 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
37
38
39
40
41
42
43
{-
Copyright (C) 2004-2011 John Goerzen <jgoerzen@complete.org>

All rights reserved.

For license and copyright information, see the file LICENSE
-}


module Bitstest(tests) where
import Test.HUnit
import Data.Bits.Utils
import Data.Word

test_fromBytes =
    let f :: [Word32] -> Word32 -> Test
        f inp exp = TestCase $ exp @=? fromBytes inp in
        [
         f [] 0
        ,f [0] 0
        ,f [1] 1
        ,f [0xff, 0] 0xff00
        ,f [0x0, 0xff] 0xff
        ,f [0x12, 0x34, 0x56, 0x78] 0x12345678
        ,f [0xff, 0xff, 0xff, 0xff] 0xffffffff
        ,f [0xff, 0, 0, 0] 0xff000000
        ]

test_getBytes =
    let f :: Word32 -> [Word32] -> Test
        f inp exp = TestCase $ exp @=? getBytes inp in
        [
         f 0 [0, 0, 0, 0]
        ,f 0x1200 [0, 0, 0x12, 0]
        ,f 0x0012 [0, 0, 0, 0x12]
        ,f 0xffffffff [0xff, 0xff, 0xff, 0xff]
        ,f 0x12345678 [0x12, 0x34, 0x56, 0x78]
        ,f 0xf0000000 [0xf0, 0, 0, 0]
        ]

tests = TestList [TestLabel "getBytes" (TestList test_getBytes),
                  TestLabel "fromBytes" (TestList test_fromBytes)
                 ]