Source

snappy / tests / Properties.hs

Diff from to

tests/Properties.hs

 {-# LANGUAGE FlexibleInstances #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
 
-import Control.Applicative
+import Control.Applicative ((<$>), (<*>))
+import Functions (rechunk)
+import Test.Framework (defaultMain)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Test.QuickCheck (Arbitrary(..))
 import qualified Codec.Compression.Snappy as B
 import qualified Codec.Compression.Snappy.Lazy as L
-import Test.Framework (defaultMain, testGroup)
-import Test.Framework.Providers.QuickCheck2 (testProperty)
-import Test.QuickCheck (Arbitrary(..))
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as L
 
     arbitrary = B.pack <$> arbitrary
 
 instance Arbitrary L.ByteString where
-    arbitrary = rechunk <$> arbitrary <*> arbitrary
+    arbitrary = smallChunk <$> arbitrary <*> arbitrary
 
 s_roundtrip bs = B.decompress (B.compress bs) == bs
 
 instance Arbitrary (Compressed B.ByteString) where
     arbitrary = (Compressed . B.compress) <$> arbitrary
 
-compress_eq n bs = L.fromChunks [B.compress bs] == L.compress (rechunk n bs)
+compress_eq n bs = L.fromChunks [B.compress bs] == L.compress (smallChunk n bs)
 decompress_eq n (Compressed bs) =
-    L.fromChunks [B.decompress bs] == L.decompress (rechunk n bs)
+    L.fromChunks [B.decompress bs] == L.decompress (smallChunk n bs)
 
-rechunk :: Int -> B.ByteString -> L.ByteString
-rechunk n = L.fromChunks . go
-  where go bs | B.null bs = []
-              | otherwise = case B.splitAt ((n `mod` 63) + 1) bs of
-                              (x,y) -> x : go y
-
-t_rechunk n bs = L.fromChunks [bs] == rechunk n bs
+t_rechunk n bs = L.fromChunks [bs] == smallChunk n bs
 
 l_roundtrip bs = L.decompress (L.compress bs) == bs
 
+smallChunk n = rechunk ((n `mod` 63) + 1)
+
 main = defaultMain tests
 
 tests = [