on master help sign in
Merge Memory, Data, SmallArray tests into one module.
333dc66Pranay Sashank
src/Streamly/Internal/Data/SmallArray.hs+3−3
@@ -51,10 +51,10 @@ import Data.Primitive.SmallArray
51
51
52import Streamly.Internal.Data.Unfold.Types (Unfold(..))
52import Streamly.Internal.Data.Unfold.Types (Unfold(..))
53import Streamly.Internal.Data.Fold.Types (Fold(..))
53import Streamly.Internal.Data.Fold.Types (Fold(..))
54−import Streamly.Streams.StreamK.Type (IsStream)
54+import Streamly.Internal.Data.Stream.StreamK.Type (IsStream)
55−import Streamly.Streams.Serial (SerialT)
55+import Streamly.Internal.Data.Stream.Serial (SerialT)
56
56
57−import qualified Streamly.Streams.StreamD as D
57+import qualified Streamly.Internal.Data.Stream.StreamD as D
58
58
59{-# NOINLINE bottomElement #-}
59{-# NOINLINE bottomElement #-}
60bottomElement :: a
60bottomElement :: a
streamly.cabal+6−4
@@ -452,9 +452,10 @@ test-suite properties
452test-suite array-test
452test-suite array-test
453 import: test-options
453 import: test-options
454 type: exitcode-stdio-1.0
454 type: exitcode-stdio-1.0
455− main-is: Arrays.hs
455+ main-is: Streamly/Test/Array.hs
456 js-sources: jsbits/clock.js
456 js-sources: jsbits/clock.js
457 hs-source-dirs: test
457 hs-source-dirs: test
458+ cpp-options: -DTEST_ARRAY
458 build-depends:
459 build-depends:
459 streamly
460 streamly
460 , base >= 4.8 && < 5
461 , base >= 4.8 && < 5
@@ -465,10 +466,10 @@ test-suite array-test
465 transformers >= 0.4 && < 0.6
466 transformers >= 0.4 && < 0.6
466 default-language: Haskell2010
467 default-language: Haskell2010
467
468
468−test-suite unpinned-array-test
469+test-suite data-array-test
469 import: test-options
470 import: test-options
470 type: exitcode-stdio-1.0
471 type: exitcode-stdio-1.0
471− main-is: Streamly/Test/Data/Array.hs
472+ main-is: Streamly/Test/Array.hs
472 js-sources: jsbits/clock.js
473 js-sources: jsbits/clock.js
473 hs-source-dirs: test
474 hs-source-dirs: test
474 build-depends:
475 build-depends:
@@ -484,9 +485,10 @@ test-suite unpinned-array-test
484test-suite smallarray-test
485test-suite smallarray-test
485 import: test-options
486 import: test-options
486 type: exitcode-stdio-1.0
487 type: exitcode-stdio-1.0
487− main-is: Streamly/Test/Data/SmallArray.hs
488+ main-is: Streamly/Test/Array.hs
488 js-sources: jsbits/clock.js
489 js-sources: jsbits/clock.js
489 hs-source-dirs: test
490 hs-source-dirs: test
491+ cpp-options: -DTEST_SMALL_ARRAY
490 build-depends:
492 build-depends:
491 streamly
493 streamly
492 , base >= 4.8 && < 5
494 , base >= 4.8 && < 5
test/Arrays.hsdeleted−115
@@ -1,115 +0,0 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−
4−module Main (main) where
5−
6−import Foreign.Storable (Storable(..))
7−
8−import Test.Hspec.QuickCheck
9−import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
10−import Test.QuickCheck.Monadic (monadicIO, assert)
11−
12−import Test.Hspec as H
13−
14−import qualified Streamly.Internal.Memory.Array as IA
15−import qualified Streamly.Memory.Array as A
16−import qualified Streamly.Prelude as S
17−import qualified Streamly.Internal.Prelude as IP
18−
19−-- Coverage build takes too long with default number of tests
20−maxTestCount :: Int
21−#ifdef DEVBUILD
22−maxTestCount = 100
23−#else
24−maxTestCount = 10
25−#endif
26−
27−allocOverhead :: Int
28−allocOverhead = 2 * sizeOf (undefined :: Int)
29−
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.
33−--
34−defaultChunkSize :: Int
35−defaultChunkSize = 32 * k - allocOverhead
36− where k = 1024
37−
38−maxArrLen :: Int
39−maxArrLen = defaultChunkSize * 8
40−
41−testLength :: Property
42−testLength =
43− forAll (choose (0, maxArrLen)) $ \len ->
44− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
45− monadicIO $ do
46− arr <- S.fold (A.writeN len)
47− $ S.fromList list
48− assert (A.length arr == len)
49−
50−testFromToStreamN :: Property
51−testFromToStreamN =
52− forAll (choose (0, maxArrLen)) $ \len ->
53− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
54− monadicIO $ do
55− arr <- S.fold (A.writeN len)
56− $ S.fromList list
57− xs <- S.toList
58− $ S.unfold A.read arr
59− assert (xs == list)
60−
61−testToStreamRev :: Property
62−testToStreamRev =
63− forAll (choose (0, maxArrLen)) $ \len ->
64− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
65− monadicIO $ do
66− arr <- S.fold (A.writeN len)
67− $ S.fromList list
68− xs <- S.toList
69− $ IA.toStreamRev arr
70− assert (xs == reverse list)
71−
72−testArraysOf :: Property
73−testArraysOf =
74− forAll (choose (0, maxArrLen)) $ \len ->
75− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
76− monadicIO $ do
77− xs <- S.toList
78− $ S.concatUnfold A.read
79− $ IP.arraysOf 240
80− $ S.fromList list
81− assert (xs == list)
82−
83−testFlattenArrays :: Property
84−testFlattenArrays =
85− forAll (choose (0, maxArrLen)) $ \len ->
86− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
87− monadicIO $ do
88− xs <- S.toList
89− $ S.concatUnfold A.read
90− $ IP.arraysOf 240
91− $ S.fromList list
92− assert (xs == list)
93−
94−testFromToStream :: Property
95−testFromToStream =
96− forAll (choose (0, maxArrLen)) $ \len ->
97− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
98− monadicIO $ do
99− arr <- S.fold A.write $ S.fromList list
100− xs <- S.toList
101− $ S.unfold A.read arr
102− assert (xs == list)
103−
104−main :: IO ()
105−main = hspec
106− $ H.parallel
107− $ modifyMaxSuccess (const maxTestCount)
108− $ do
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
test/Streamly/Test/Data/Array.hs → test/Streamly/Test/Array.hsrenamed+36−3
@@ -20,11 +20,22 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
20import Test.Hspec as H
20import Test.Hspec as H
21
21
22import Streamly (SerialT)
22import Streamly (SerialT)
23−import Streamly.Data.Array (Array)
24
23
25−import qualified Streamly.Data.Array as A
26import qualified Streamly.Prelude as S
24import qualified Streamly.Prelude as S
27
25
26+#ifdef TEST_SMALL_ARRAY
27+import qualified Streamly.Data.SmallArray as A
28+type Array = A.SmallArray
29+#elif defined(TEST_ARRAY)
30+import qualified Streamly.Memory.Array as A
31+import qualified Streamly.Internal.Memory.Array as A
32+import qualified Streamly.Internal.Prelude as IP
33+type Array = A.Array
34+#else
35+import qualified Streamly.Data.Array as A
36+type Array = A.Array
37+#endif
38+
28-- Coverage build takes too long with default number of tests
39-- Coverage build takes too long with default number of tests
29maxTestCount :: Int
40maxTestCount :: Int
30#ifdef DEVBUILD
41#ifdef DEVBUILD
@@ -63,8 +74,10 @@ testLength = genericTestFrom (\n -> S.fold (A.writeN n))
63testLengthFromStreamN :: Property
74testLengthFromStreamN :: Property
64testLengthFromStreamN = genericTestFrom A.fromStreamN
75testLengthFromStreamN = genericTestFrom A.fromStreamN
65
76
77+#ifndef TEST_SMALL_ARRAY
66testLengthFromStream :: Property
78testLengthFromStream :: Property
67testLengthFromStream = genericTestFrom (const A.fromStream)
79testLengthFromStream = genericTestFrom (const A.fromStream)
80+#endif
68
81
69genericTestFromTo ::
82genericTestFromTo ::
70 (Int -> SerialT IO Int -> IO (Array Int))
83 (Int -> SerialT IO Int -> IO (Array Int))
@@ -100,11 +113,26 @@ testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
100testFromStreamNToStream :: Property
113testFromStreamNToStream :: Property
101testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
114testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
102
115
116+#ifndef TEST_SMALL_ARRAY
103testFromStreamToStream :: Property
117testFromStreamToStream :: Property
104testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
118testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
105
119
106testFoldUnfold :: Property
120testFoldUnfold :: Property
107testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
121testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
122+#endif
123+
124+#ifdef TEST_ARRAY
125+testArraysOf :: Property
126+testArraysOf =
127+ forAll (choose (0, maxArrLen)) $ \len ->
128+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
129+ monadicIO $ do
130+ xs <- S.toList
131+ $ S.concatUnfold A.read
132+ $ IP.arraysOf 240
133+ $ S.fromList list
134+ assert (xs == list)
135+#endif
108
136
109main :: IO ()
137main :: IO ()
110main =
138main =
@@ -114,11 +142,16 @@ main =
114 describe "Construction" $ do
142 describe "Construction" $ do
115 prop "length . writeN n === n" testLength
143 prop "length . writeN n === n" testLength
116 prop "length . fromStreamN n === n" testLengthFromStreamN
144 prop "length . fromStreamN n === n" testLengthFromStreamN
117− prop "length . fromStream === n" testLengthFromStream
118 prop "read . writeN === id " testFoldNUnfold
145 prop "read . writeN === id " testFoldNUnfold
119 prop "toStream . writeN === id" testFoldNToStream
146 prop "toStream . writeN === id" testFoldNToStream
120 prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
147 prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
121 prop "read . fromStreamN === id" testFromStreamNUnfold
148 prop "read . fromStreamN === id" testFromStreamNUnfold
122 prop "toStream . fromStreamN === id" testFromStreamNToStream
149 prop "toStream . fromStreamN === id" testFromStreamNToStream
150+#ifndef TEST_SMALL_ARRAY
151+ prop "length . fromStream === n" testLengthFromStream
123 prop "toStream . fromStream === id" testFromStreamToStream
152 prop "toStream . fromStream === id" testFromStreamToStream
124 prop "read . write === id" testFoldUnfold
153 prop "read . write === id" testFoldUnfold
154+#endif
155+#ifdef TEST_ARRAY
156+ prop "arraysOf concats to original" testArraysOf
157+#endif
test/Streamly/Test/Data/SmallArray.hsdeleted−113
@@ -1,113 +0,0 @@
1−-- |
2−-- Module : Main
3−-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD-3-Clause
6−-- Maintainer : streamly@composewell.com
7−-- Stability : experimental
8−-- Portability : GHC
9−--
10−
11−{-# LANGUAGE CPP #-}
12−
13−module Main (main) where
14−
15−import Foreign.Storable (Storable(..))
16−
17−import Test.Hspec.QuickCheck
18−import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
19−import Test.QuickCheck.Monadic (monadicIO, assert, run)
20−
21−import Test.Hspec as H
22−
23−import Streamly (SerialT)
24−import Streamly.Data.SmallArray (SmallArray)
25−
26−import qualified Streamly.Data.SmallArray as A
27−import qualified Streamly.Prelude as S
28−
29−-- Coverage build takes too long with default number of tests
30−maxTestCount :: Int
31−#ifdef DEVBUILD
32−maxTestCount = 100
33−#else
34−maxTestCount = 10
35−#endif
36−
37−allocOverhead :: Int
38−allocOverhead = 2 * sizeOf (undefined :: Int)
39−
40−-- XXX this should be in sync with the defaultChunkSize in Array code, or we
41−-- should expose that and use that. For fast testing we could reduce the
42−-- defaultChunkSize under CPP conditionals.
43−--
44−defaultChunkSize :: Int
45−defaultChunkSize = 32 * k - allocOverhead
46− where k = 1024
47−
48−maxArrLen :: Int
49−maxArrLen = defaultChunkSize * 8
50−
51−genericTestFrom ::
52− (Int -> SerialT IO Int -> IO (SmallArray Int))
53− -> Property
54−genericTestFrom arrFold =
55− forAll (choose (0, maxArrLen)) $ \len ->
56− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
57− monadicIO $ do
58− arr <- run $ arrFold len $ S.fromList list
59− assert (A.length arr == len)
60−
61−testLength :: Property
62−testLength = genericTestFrom (\n -> S.fold (A.writeN n))
63−
64−testLengthFromStreamN :: Property
65−testLengthFromStreamN = genericTestFrom A.fromStreamN
66−
67−genericTestFromTo ::
68− (Int -> SerialT IO Int -> IO (SmallArray Int))
69− -> (SmallArray Int -> SerialT IO Int)
70− -> ([Int] -> [Int] -> Bool)
71− -> Property
72−genericTestFromTo arrFold arrUnfold listEq =
73− forAll (choose (0, maxArrLen)) $ \len ->
74− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
75− monadicIO $ do
76− arr <- run $ arrFold len $ S.fromList list
77− xs <- run $ S.toList $ arrUnfold arr
78− assert (listEq xs list)
79−
80−testFoldNUnfold :: Property
81−testFoldNUnfold =
82− genericTestFromTo (\n -> S.fold (A.writeN n)) (S.unfold A.read) (==)
83−
84−testFoldNToStream :: Property
85−testFoldNToStream =
86− genericTestFromTo (\n -> S.fold (A.writeN n)) A.toStream (==)
87−
88−testFoldNToStreamRev :: Property
89−testFoldNToStreamRev =
90− genericTestFromTo
91− (\n -> S.fold (A.writeN n))
92− A.toStreamRev
93− (\xs list -> xs == reverse list)
94−
95−testFromStreamNUnfold :: Property
96−testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
97−
98−testFromStreamNToStream :: Property
99−testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
100−
101−main :: IO ()
102−main =
103− hspec $
104− H.parallel $
105− modifyMaxSuccess (const maxTestCount) $
106− describe "Construction" $ do
107− prop "length . writeN n === n" testLength
108− prop "length . fromStreamN n === n" testLengthFromStreamN
109− prop "read . writeN === id " testFoldNUnfold
110− prop "toStream . writeN === id" testFoldNToStream
111− prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
112− prop "read . fromStreamN === id" testFromStreamNUnfold
113− prop "toStream . fromStreamN === id" testFromStreamNToStream