on bd5b6fc help sign in
55 lines 1.8 kB history raw
1-- |
2-- Module : Streamly.Test.Data.Array.Prim
3-- Copyright : (c) 2020 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
7-- Portability : GHC
9module Streamly.Test.Data.Array.Prim where
11#include "Streamly/Test/Data/Array/CommonImports.hs"
13import qualified Streamly.Internal.Data.Fold as Fold
14import qualified Streamly.Internal.Data.Array.Prim as A
15import qualified Streamly.Internal.Data.Array.Prim.Type as A
16type Array = A.Array
18moduleName :: String
19moduleName = "Data.Array.Prim"
21#include "Streamly/Test/Data/Array/Common.hs"
23testFromStreamToStream :: Property
24testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
26testFoldUnfold :: Property
27testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
29testFromList :: Property
30testFromList =
31 forAll (choose (0, maxArrLen)) $ \len ->
32 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
33 monadicIO $ do
34 let arr = A.fromList list
35 xs <- run $ S.toList $ (S.unfold A.read) arr
36 assert (xs == list)
38testLengthFromStream :: Property
39testLengthFromStream = genericTestFrom (const A.fromStream)
42main :: IO ()
43main =
44 hspec $
45 H.parallel $
46 modifyMaxSuccess (const maxTestCount) $ do
47 describe moduleName $ do
48 commonMain
49 describe "Construction" $ do
50 prop "length . fromStream === n" testLengthFromStream
51 prop "toStream . fromStream === id" testFromStreamToStream
52 prop "read . write === id" testFoldUnfold
53 prop "fromList" testFromList
54 prop "foldMany with writeNUnsafe concats to original"
55 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))