on master help sign in
Completely remove the unclean common array test code
commit9c04f4099999977466dfc49d129b4735e3cf06e4 authoradithyaov <adithya@composewell.com> dateSat 27 Nov 2021, 02:51 (5 years ago) parent6f65e4a
3 files changed−185
.hlint.ignore−1 streamly.cabal−1 test/Streamly/Test/Common/Array.hs−183
.hlint.ignore−1
@@ -12,7 +12,6 @@ src/Streamly/Internal/Data/Array/Prim/MutTypesInclude.hs
1212src/Streamly/Internal/Data/Array/Prim/Pinned/Mut/Type.hs
1313src/Streamly/Internal/Data/Array/Prim/Pinned/Type.hs
1414src/Streamly/Internal/Data/Array/Prim/TypesInclude.hs
15−test/Streamly/Test/Common/Array.hs
1615test/Streamly/Test/Data/Array.hs
1716test/Streamly/Test/Data/Array/Prim.hs
1817test/Streamly/Test/Data/Array/Prim/Pinned.hs
streamly.cabal−1
@@ -86,7 +86,6 @@ extra-source-files:
8686 src/Streamly/Internal/FileSystem/Event/Darwin.h
8787 src/config.h.in
8888 src/inline.hs
89− test/Streamly/Test/Common/Array.hs
9089 test/Streamly/Test/Data/*.hs
9190 test/Streamly/Test/Data/Array/CommonImports.hs
9291 test/Streamly/Test/Data/Array/Common.hs
test/Streamly/Test/Common/Array.hsdeleted−183
@@ -1,183 +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−-- This is a common array test module that gets included in different
12−-- Array test modules with the corresponding macro defined.
13−--
14−-- Meanings of CPP macros:
15−-- Default => Data.Array
16−-- TEST_ARRAY => Data.Array.Foreign
17−-- TEST_SMALL_ARRAY => Data.SmallArray
18−-- DATA_ARRAY_PRIM => Data.Array.Prim
19−-- DATA_ARRAY_PRIM_PINNED => Data.Array.Prim.Pinned
20−
21−import Foreign.Storable (Storable(..))
22−
23−import Test.Hspec.QuickCheck
24−import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
25−import Test.QuickCheck.Monadic (monadicIO, assert, run)
26−import Test.Hspec as H
27−
28−import Streamly.Data.Fold (Fold)
29−import Streamly.Prelude (SerialT)
30−import Streamly.Test.Common (listEquals)
31−
32−import qualified Streamly.Prelude as S
33−
34−#ifdef TEST_SMALL_ARRAY
35−import qualified Streamly.Internal.Data.SmallArray as A
36−type Array = A.SmallArray
37−#endif
38−
39−moduleName :: String
40−#ifdef TEST_SMALL_ARRAY
41−moduleName = "Data.SmallArray"
42−#endif
43−
44−-- Coverage build takes too long with default number of tests
45−maxTestCount :: Int
46−#ifdef DEVBUILD
47−maxTestCount = 100
48−#else
49−maxTestCount = 10
50−#endif
51−
52−allocOverhead :: Int
53−allocOverhead = 2 * sizeOf (undefined :: Int)
54−
55−-- XXX this should be in sync with the defaultChunkSize in Array code, or we
56−-- should expose that and use that. For fast testing we could reduce the
57−-- defaultChunkSize under CPP conditionals.
58−--
59−defaultChunkSize :: Int
60−defaultChunkSize = 32 * k - allocOverhead
61− where k = 1024
62−
63−maxArrLen :: Int
64−maxArrLen = defaultChunkSize * 8
65−
66−genericTestFrom ::
67− (Int -> SerialT IO Int -> IO (Array Int))
68− -> Property
69−genericTestFrom arrFold =
70− forAll (choose (0, maxArrLen)) $ \len ->
71− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
72− monadicIO $ do
73− arr <- run $ arrFold len $ S.fromList list
74− assert (A.length arr == len)
75−
76−testLength :: Property
77−testLength = genericTestFrom (\n -> S.fold (A.writeN n))
78−
79−testLengthFromStreamN :: Property
80−testLengthFromStreamN = genericTestFrom A.fromStreamN
81−
82−#ifndef TEST_SMALL_ARRAY
83−testLengthFromStream :: Property
84−testLengthFromStream = genericTestFrom (const A.fromStream)
85−#endif
86−
87−genericTestFromTo ::
88− (Int -> SerialT IO Int -> IO (Array Int))
89− -> (Array Int -> SerialT IO Int)
90− -> ([Int] -> [Int] -> Bool)
91− -> Property
92−genericTestFromTo arrFold arrUnfold listEq =
93− forAll (choose (0, maxArrLen)) $ \len ->
94− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
95− monadicIO $ do
96− arr <- run $ arrFold len $ S.fromList list
97− xs <- run $ S.toList $ arrUnfold arr
98− assert (listEq xs list)
99−
100−testFoldNUnfold :: Property
101−testFoldNUnfold =
102− genericTestFromTo (\n -> S.fold (A.writeN n)) (S.unfold A.read) (==)
103−
104−testFoldNToStream :: Property
105−testFoldNToStream =
106− genericTestFromTo (\n -> S.fold (A.writeN n)) A.toStream (==)
107−
108−testFoldNToStreamRev :: Property
109−testFoldNToStreamRev =
110− genericTestFromTo
111− (\n -> S.fold (A.writeN n))
112− A.toStreamRev
113− (\xs list -> xs == reverse list)
114−
115−testFromStreamNUnfold :: Property
116−testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
117−
118−testFromStreamNToStream :: Property
119−testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
120−
121−testFromListN :: Property
122−testFromListN =
123− forAll (choose (0, maxArrLen)) $ \len ->
124− forAll (choose (0, len)) $ \n ->
125− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
126− monadicIO $ do
127− let arr = A.fromListN n list
128− xs <- run $ S.toList $ (S.unfold A.read) arr
129− listEquals (==) xs (take n list)
130−
131−#ifndef TEST_SMALL_ARRAY
132−testFromStreamToStream :: Property
133−testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
134−
135−testFoldUnfold :: Property
136−testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
137−
138−testFromList :: Property
139−testFromList =
140− forAll (choose (0, maxArrLen)) $ \len ->
141− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
142− monadicIO $ do
143− let arr = A.fromList list
144− xs <- run $ S.toList $ (S.unfold A.read) arr
145− assert (xs == list)
146−#endif
147−
148−foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
149−foldManyWith f =
150− forAll (choose (0, maxArrLen)) $ \len ->
151− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
152− monadicIO $ do
153− xs <- run
154− $ S.toList
155− $ S.unfoldMany A.read
156− $ S.foldMany (f 240)
157− $ S.fromList list
158− assert (xs == list)
159−
160−main :: IO ()
161−main =
162− hspec $
163− H.parallel $
164− modifyMaxSuccess (const maxTestCount) $ do
165− describe moduleName $ do
166− describe "Construction" $ do
167− prop "length . writeN n === n" testLength
168− prop "length . fromStreamN n === n" testLengthFromStreamN
169− prop "read . writeN === id " testFoldNUnfold
170− prop "toStream . writeN === id" testFoldNToStream
171− prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
172− prop "read . fromStreamN === id" testFromStreamNUnfold
173− prop "toStream . fromStreamN === id" testFromStreamNToStream
174− prop "fromListN" testFromListN
175−
176−#ifndef TEST_SMALL_ARRAY
177− prop "length . fromStream === n" testLengthFromStream
178− prop "toStream . fromStream === id" testFromStreamToStream
179− prop "read . write === id" testFoldUnfold
180− prop "fromList" testFromList
181−#endif
182− prop "foldMany with writeN concats to original"
183− (foldManyWith A.writeN)