7ee26930808ab49c0946ee56706c10ff82385591
[packages/containers.git] / tests / bitqueue-properties.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE BangPatterns #-}
3
4 #if !MIN_VERSION_base(4,8,0)
5 import Control.Applicative ((<$>))
6 #endif
7 import qualified Data.List as List
8 import Test.Framework
9 import Test.Framework.Providers.QuickCheck2
10 import Test.QuickCheck
11 import Utils.Containers.Internal.BitUtil (wordSize)
12 import Utils.Containers.Internal.BitQueue
13 ( BitQueue
14 , emptyQB
15 , snocQB
16 , buildQ
17 , toListQ )
18
19 default (Int)
20
21 main :: IO ()
22 main = defaultMain $ map testNum [0..(wordSize - 2)]
23
24 testNum :: Int -> Test
25 testNum n = testProperty ("Size "++show n) (prop_n n)
26
27 prop_n :: Int -> Gen Bool
28 prop_n n = checkList <$> vectorOf n (arbitrary :: Gen Bool)
29 where
30 checkList :: [Bool] -> Bool
31 checkList values = toListQ q == values
32 where
33 q :: BitQueue
34 !q = buildQ $ List.foldl' snocQB emptyQB values