on master help sign in
65 lines 2.0 kB history raw
1{-# OPTIONS_GHC -Wno-deprecations #-}
3-- |
4-- Module : Streamly.Test.Data.Array.Generic
5-- Copyright : (c) 2019 Composewell Technologies
6-- License : BSD-3-Clause
7-- Maintainer : streamly@composewell.com
8-- Stability : experimental
9-- Portability : GHC
11module Streamly.Test.Data.Array.Generic (main) where
13#include "Streamly/Test/Data/Array/CommonImports.hs"
15import qualified Streamly.Internal.Data.Array.Generic as A
17type Array = A.Array
19moduleName :: String
20moduleName = "Data.Array"
22#include "Streamly/Test/Data/Array/Common.hs"
24testFromStreamToStream :: Property
25testFromStreamToStream =
26 genericTestFromTo (const A.fromStream) A.read (==)
28testFoldUnfold :: Property
29testFoldUnfold =
30 genericTestFromTo (const (S.fold A.write)) (S.unfold A.reader) (==)
32testFromList :: Property
33testFromList =
34 forAll (choose (0, maxArrLen)) $ \len ->
35 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
36 monadicIO $ do
37 let arr = A.fromList list
38 xs <- run $ S.fold Fold.toList $ S.unfold A.reader arr
39 assert (xs == list)
41testLengthFromStream :: Property
42testLengthFromStream = genericTestFrom (const A.fromStream)
44testReadShowInstance :: Property
45testReadShowInstance =
46 forAll (choose (0, maxArrLen)) $ \len ->
47 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
48 monadicIO $ do
49 let arr = A.fromList list
50 assert (A.toList (read (show arr)) == list)
53main :: IO ()
54main =
55 hspec $
56 H.parallel $
57 modifyMaxSuccess (const maxTestCount) $ do
58 describe moduleName $ do
59 commonMain
60 describe "Construction" $ do
61 prop "length . fromStream === n" testLengthFromStream
62 prop "toStream . fromStream === id" testFromStreamToStream
63 prop "read . write === id" testFoldUnfold
64 prop "fromList" testFromList
65 prop "testReadShowInstance" testReadShowInstance