2{-# LANGUAGE FlexibleContexts #-}
4module Main (main) where
6import Foreign.Storable (Storable(..))
8import Test.Hspec.QuickCheck
9import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
10import Test.QuickCheck.Monadic (monadicIO, assert)
14import qualified Streamly.Internal.Memory.Array as IA
15import qualified Streamly.Memory.Array as A
16import qualified Streamly.Prelude as S
17import qualified Streamly.Internal.Prelude as IP
19-- Coverage build takes too long with default number of tests
28allocOverhead = 2 * sizeOf (undefined :: Int)
30-- XXX this should be in sync with the defaultChunkSize in Array code, or we
31-- should expose that and use that. For fast testing we could reduce the
32-- defaultChunkSize under CPP conditionals.
34defaultChunkSize :: Int
35defaultChunkSize = 32 * k - allocOverhead
39maxArrLen = defaultChunkSize * 8
43 forAll (choose (0, maxArrLen)) $ \len ->
44 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
46 arr <- S.fold (A.writeN len)
48 assert (A.length arr == len)
50testFromToStreamN :: Property
52 forAll (choose (0, maxArrLen)) $ \len ->
53 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
55 arr <- S.fold (A.writeN len)
61testToStreamRev :: Property
63 forAll (choose (0, maxArrLen)) $ \len ->
64 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
66 arr <- S.fold (A.writeN len)
70 assert (xs == reverse list)
72testArraysOf :: Property
74 forAll (choose (0, maxArrLen)) $ \len ->
75 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
78 $ S.concatUnfold A.read
83testFlattenArrays :: Property
85 forAll (choose (0, maxArrLen)) $ \len ->
86 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
89 $ S.concatUnfold A.read
94testFromToStream :: Property
96 forAll (choose (0, maxArrLen)) $ \len ->
97 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
99 arr <- S.fold A.write $ S.fromList list
101 $ S.unfold A.read arr
107 $ modifyMaxSuccess (const maxTestCount)
109 describe "Construction" $ do
110 prop "length . writeN n === n" $ testLength
111 prop "read . writeN n === id" $ testFromToStreamN
112 prop "toStreamRev . write === reverse" $ testToStreamRev
113 prop "arraysOf concats to original" $ testArraysOf
114 prop "concats to original" $ testFlattenArrays
115 prop "read . write === id" $ testFromToStream
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list