on master help sign in
Add test for S.groups.
bee479epranaysashank
test/Streamly/Test/Prelude/Common.hs+14−5
@@ -10,7 +10,9 @@
10module Streamly.Test.Prelude.Common
10module Streamly.Test.Prelude.Common
11 (
11 (
12 -- * Construction operations
12 -- * Construction operations
13+ constructWithRepeat
14+ , constructWithRepeatM
13− constructWithReplicate
15+ , constructWithReplicate
14 , constructWithReplicateM
16 , constructWithReplicateM
15 , constructWithIntFromThenTo
17 , constructWithIntFromThenTo
16#if __GLASGOW_HASKELL__ >= 806
18#if __GLASGOW_HASKELL__ >= 806
@@ -18,10 +20,18 @@ module Streamly.Test.Prelude.Common
18#endif
20#endif
19 , constructWithIterate
21 , constructWithIterate
20 , constructWithIterateM
22 , constructWithIterateM
23+ , constructWithEnumerate
24+ , constructWithEnumerateTo
21 , constructWithFromIndices
25 , constructWithFromIndices
22 , constructWithFromIndicesM
26 , constructWithFromIndicesM
27+ , constructWithFromList
28+ , constructWithFromListM
29+ , constructWithUnfoldr
23 , constructWithCons
30 , constructWithCons
24 , constructWithConsM
31 , constructWithConsM
32+ , constructWithYield
33+ , constructWithYieldM
34+ , simpleOps
25 -- * Applicative operations
35 -- * Applicative operations
26 , applicativeOps
36 , applicativeOps
27 , applicativeOps1
37 , applicativeOps1
@@ -196,12 +206,12 @@ constructWithRepeat, constructWithRepeatM
196constructWithRepeat = constructWithLenM stream list
206constructWithRepeat = constructWithLenM stream list
197 where
207 where
198 stream n = S.take n $ S.repeat 1
208 stream n = S.take n $ S.repeat 1
199− list n = return $ take n $ repeat 1
209+ list n = return $ replicate n 1
200
210
201constructWithRepeatM = constructWithLenM stream list
211constructWithRepeatM = constructWithLenM stream list
202 where
212 where
203 stream n = S.take n $ S.repeatM (return 1)
213 stream n = S.take n $ S.repeatM (return 1)
204− list n = return $ take n $ repeat 1
214+ list n = return $ replicate n 1
205
215
206#if __GLASGOW_HASKELL__ >= 806
216#if __GLASGOW_HASKELL__ >= 806
207-- XXX try very small steps close to 0
217-- XXX try very small steps close to 0
@@ -408,8 +418,7 @@ constructWithYieldM listT op len =
408 listEquals (==) (listT strm) list
418 listEquals (==) (listT strm) list
409
419
410simpleProps ::
420simpleProps ::
411− IsStream t
412− => (Int -> t IO Int)
421+ (Int -> t IO Int)
413 -> (t IO Int -> SerialT IO Int)
422 -> (t IO Int -> SerialT IO Int)
414 -> Int
423 -> Int
415 -> Property
424 -> Property
test/Streamly/Test/Prelude/Serial.hs+10−2
@@ -14,7 +14,7 @@ import Control.Monad ( when, forM_ )
14import Data.Function ( (&) )
14import Data.Function ( (&) )
15import Data.IORef ( newIORef, readIORef, writeIORef )
15import Data.IORef ( newIORef, readIORef, writeIORef )
16import Data.Int (Int64)
16import Data.Int (Int64)
17−import Data.List (intercalate)
17+import Data.List (group, intercalate)
18import Data.Maybe ( isJust, fromJust )
18import Data.Maybe ( isJust, fromJust )
19import Foreign.Storable (Storable)
19import Foreign.Storable (Storable)
20#if __GLASGOW_HASKELL__ < 808
20#if __GLASGOW_HASKELL__ < 808
@@ -287,7 +287,14 @@ testGroupsBy =
287 (x:_) -> x == minimum ls)
287 (x:_) -> x == minimum ls)
288 $ S.groupsBy (>) FL.toList
288 $ S.groupsBy (>) FL.toList
289 $ S.fromList vec
289 $ S.fromList vec
290− assert $ r == True
290+ assert r
291+
292+testGroups :: Property
293+testGroups =
294+ forAll (choose (0, maxStreamLen)) $ \len ->
295+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
296+ r <- run $ S.toList $ S.groups FL.toList $ S.fromList vec
297+ assert $ r == group vec
291
298
292-- |
299-- |
293-- If the list is empty, returns Nothing,
300-- If the list is empty, returns Nothing,
@@ -562,6 +569,7 @@ main = hspec
562
569
563 describe "Tests for S.groupsBy" $ do
570 describe "Tests for S.groupsBy" $ do
564 prop "testGroupsBy" testGroupsBy
571 prop "testGroupsBy" testGroupsBy
572+ prop "S.groups = groups" testGroups
565 prop "testGroupsBySep" testGroupsBySep
573 prop "testGroupsBySep" testGroupsBySep
566
574
567 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
575 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially