@@ -0,0 +1,132 @@
5+-- Copyright : (c) 2019 Composewell Technologies
7+-- License : BSD-3-Clause
8+-- Maintainer : streamly@composewell.com
9+-- Stability : experimental
12+module Main (main) where
14+import Foreign.Storable (Storable(..))
16+import Test.Hspec.QuickCheck
17+import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
18+import Test.QuickCheck.Monadic (monadicIO, assert)
20+import Test.Hspec as H
22+import qualified Streamly.Data.Array as A
23+import qualified Streamly.Prelude as S
25+-- Coverage build takes too long with default number of tests
34+allocOverhead = 2 * sizeOf (undefined :: Int)
36+-- XXX this should be in sync with the defaultChunkSize in Array code, or we
37+-- should expose that and use that. For fast testing we could reduce the
38+-- defaultChunkSize under CPP conditionals.
40+defaultChunkSize :: Int
41+defaultChunkSize = 32 * k - allocOverhead
45+maxArrLen = defaultChunkSize * 8
47+testLength :: Property
49+ forAll (choose (0, maxArrLen)) $ \len ->
50+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
52+ arr <- S.fold (A.writeN len)
54+ assert (A.length arr == len)
56+testLengthFromStreamN :: Property
57+testLengthFromStreamN =
58+ forAll (choose (0, maxArrLen)) $ \len ->
59+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
61+ arr <- A.fromStreamN len
63+ assert (A.length arr == len)
65+testFoldUnfold :: Property
67+ forAll (choose (0, maxArrLen)) $ \len ->
68+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
70+ arr <- S.fold (A.writeN len)
73+ $ S.unfold A.read arr
76+testFoldToStream :: Property
78+ forAll (choose (0, maxArrLen)) $ \len ->
79+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
81+ arr <- S.fold (A.writeN len)
87+testFoldToStreamRev :: Property
89+ forAll (choose (0, maxArrLen)) $ \len ->
90+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
92+ arr <- S.fold (A.writeN len)
96+ assert (xs == reverse list)
98+testFromStreamUnfold :: Property
99+testFromStreamUnfold =
100+ forAll (choose (0, maxArrLen)) $ \len ->
101+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
103+ arr <- A.fromStreamN len
106+ $ S.unfold A.read arr
109+testFromStreamToStream :: Property
110+testFromStreamToStream =
111+ forAll (choose (0, maxArrLen)) $ \len ->
112+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
114+ arr <- A.fromStreamN len
124+ modifyMaxSuccess (const maxTestCount) $
125+ describe "Construction" $ do
126+ prop "length . writeN n === n" testLength
127+ prop "length . fromStreamN n === n" testLengthFromStreamN
128+ prop "read . writeN === id " testFoldUnfold
129+ prop "toStream . writeN === id" testFoldToStream
130+ prop "toStreamRev . writeN === reverse" testFoldToStreamRev
131+ prop "read . fromStreamN === id" testFromStreamUnfold
132+ prop "toStream . fromStreamN === reverse" testFromStreamToStream