on master help sign in
tests: remove unused imports, fix some lints
7763587Lennart Kolmodin
BitsQC.hs+7−12
@@ -1,14 +1,11 @@
1{-# LANGUAGE CPP, FlexibleInstances, FlexibleContexts, TupleSections #-}
1{-# LANGUAGE CPP, FlexibleInstances, FlexibleContexts, TupleSections #-}
2
2
3−module Main where
3+module Main ( main ) where
4
4
5−import Data.Binary ( encode, Binary(..) )
5+import Data.Binary ( Binary(..) )
6import Data.Binary.Get ( runGet, runGetIncremental, pushChunks, Decoder(..) )
6import Data.Binary.Get ( runGet, runGetIncremental, pushChunks, Decoder(..) )
7import Data.Binary.Put ( runPut )
7import Data.Binary.Put ( runPut )
8
8
9−import qualified Data.Binary.Get as BG ( getWord8, getWord16be, getWord32be, getWord64be )
10−import qualified Data.Binary.Put as BP ( putWord8, putWord16be, putWord32be, putWord64be )
11−
12import Data.Binary.Bits
9import Data.Binary.Bits
13import Data.Binary.Bits.Get
10import Data.Binary.Bits.Get
14import Data.Binary.Bits.Put
11import Data.Binary.Bits.Put
@@ -18,18 +15,16 @@ import qualified Data.ByteString.Lazy as L
18
15
19import Control.Applicative
16import Control.Applicative
20import Data.Bits
17import Data.Bits
21−import Data.Monoid
22import Data.Word
18import Data.Word
23import Foreign.Storable
19import Foreign.Storable
24import System.Random
20import System.Random
25
21
26−import Test.Framework.Options ( TestOptions'(..) )
27import Test.Framework.Providers.QuickCheck2 ( testProperty )
22import Test.Framework.Providers.QuickCheck2 ( testProperty )
28import Test.Framework.Runners.Console ( defaultMain )
23import Test.Framework.Runners.Console ( defaultMain )
29−import Test.Framework.Runners.Options ( RunnerOptions'(..) )
30import Test.Framework ( Test, testGroup )
24import Test.Framework ( Test, testGroup )
31import Test.QuickCheck
25import Test.QuickCheck
32
26
27+main :: IO ()
33main = defaultMain tests
28main = defaultMain tests
34
29
35tests :: [Test]
30tests :: [Test]
@@ -130,7 +125,7 @@ prop_putget_with_bitreq (W w) = property $
130prop_putget_list_simple :: (BinaryBit a, Eq a, Storable a) => W [a] -> Property
125prop_putget_list_simple :: (BinaryBit a, Eq a, Storable a) => W [a] -> Property
131prop_putget_list_simple (W ws) = property $
126prop_putget_list_simple (W ws) = property $
132 let s = sizeOf (head ws) * 8
127 let s = sizeOf (head ws) * 8
133− p = mapM_ (\v -> putBits s v) ws
128+ p = mapM_ (putBits s) ws
134 g = mapM (const (getBits s)) ws
129 g = mapM (const (getBits s)) ws
135 lbs = runPut (runBitPut p)
130 lbs = runPut (runBitPut p)
136 ws' = runGet (runBitGet g) lbs
131 ws' = runGet (runBitGet g) lbs
@@ -187,7 +182,7 @@ prop_bitget_with_put_from_binary (W ws) = property $
187prop_bitget_bytestring_interspersed :: (BinaryBit a, Binary a, Num a, Ord a, Bits a) => W a -> [B.ByteString] -> Property
182prop_bitget_bytestring_interspersed :: (BinaryBit a, Binary a, Num a, Ord a, Bits a) => W a -> [B.ByteString] -> Property
188prop_bitget_bytestring_interspersed (W ws) bss = property $
183prop_bitget_bytestring_interspersed (W ws) bss = property $
189 let p = mapM_ (\bs -> putBits (bitreq ws) ws >> putByteString bs) bss
184 let p = mapM_ (\bs -> putBits (bitreq ws) ws >> putByteString bs) bss
190− g = mapM (\bs -> (,) <$> (getBits (bitreq ws)) <*> (getByteString (B.length bs))) bss
185+ g = mapM (\bs -> (,) <$> getBits (bitreq ws) <*> getByteString (B.length bs)) bss
191 lbs = runPut (runBitPut p)
186 lbs = runPut (runBitPut p)
192 r = runGet (runBitGet g) lbs
187 r = runGet (runBitGet g) lbs
193 in map (ws,) bss == r
188 in map (ws,) bss == r
@@ -221,7 +216,7 @@ bittable = [ (fromIntegral x, (1 `shiftL` x) - 1) | x <- [1..64] ]
221prop_bitreq :: W Word64 -> Property
216prop_bitreq :: W Word64 -> Property
222prop_bitreq (W w) = property $
217prop_bitreq (W w) = property $
223 ( w == 0 && bitreq w == 1 )
218 ( w == 0 && bitreq w == 1 )
224− || bitreq w == (bitreq (w `shiftR` 1)) + 1
219+ || bitreq w == bitreq (w `shiftR` 1) + 1
225
220
226prop_composite_case :: Bool -> W Word16 -> Property
221prop_composite_case :: Bool -> W Word16 -> Property
227prop_composite_case b (W w) = w < 0x8000 ==>
222prop_composite_case b (W w) = w < 0x8000 ==>
@@ -255,7 +250,7 @@ prop_compare_get_with_naive (W ws) = property $
255 rn = runGet (runBitGet gn) lbs
250 rn = runGet (runBitGet gn) lbs
256 r = runGet (runBitGet g ) lbs
251 r = runGet (runBitGet g ) lbs
257 -- we must help our compiler to resolve the types of 'gn' and 'g'
252 -- we must help our compiler to resolve the types of 'gn' and 'g'
258− types = rn == ws && r == ws
253+ _types = rn == ws && r == ws
259 in rn == r
254 in rn == r
260
255
261-- | Write one bit at a time until the full word has been written
256-- | Write one bit at a time until the full word has been written