on master help sign in
Add unfold tests for operations on input
3c5d2f8adithyaov
test/Streamly/Test/Data/Unfold.hs+62−1
@@ -57,6 +57,45 @@ testUnfold unf seed lst = runIdentity action
57testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
57testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
58testUnfoldD = testUnfold
58testUnfoldD = testUnfold
59
59
60+-------------------------------------------------------------------------------
61+-- Operations on input
62+-------------------------------------------------------------------------------
63+
64+lmapM :: Bool
65+lmapM =
66+ let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.singleton id)
67+ in testUnfoldAD unf 0 1 1 [1]
68+
69+supply :: Bool
70+supply =
71+ let unf = UF.supply (UF.singleton id) 1
72+ in testUnfold unf undefined ([1] :: [Int])
73+
74+supplyFirst :: Bool
75+supplyFirst =
76+ let unf = UF.supplyFirst (UF.singleton id) 1
77+ in testUnfold unf 2 ([(1, 2)] :: [(Int, Int)])
78+
79+supplySecond :: Bool
80+supplySecond =
81+ let unf = UF.supplySecond (UF.singleton id) 1
82+ in testUnfold unf 2 ([(2, 1)] :: [(Int, Int)])
83+
84+discardFirst :: Bool
85+discardFirst =
86+ let unf = UF.discardFirst (UF.singleton id)
87+ in testUnfold unf ((1, 2) :: (Int, Int)) [2]
88+
89+discardSecond :: Bool
90+discardSecond =
91+ let unf = UF.discardSecond (UF.singleton id)
92+ in testUnfold unf ((1, 2) :: (Int, Int)) [1]
93+
94+swap :: Bool
95+swap =
96+ let unf = UF.swap (UF.singleton id)
97+ in testUnfold unf ((1, 2) :: (Int, Int)) [(2, 1)]
98+
60-------------------------------------------------------------------------------
99-------------------------------------------------------------------------------
61-- Stream generation
100-- Stream generation
62-------------------------------------------------------------------------------
101-------------------------------------------------------------------------------
@@ -211,8 +250,30 @@ outerProduct =
211 lst = [(a, b) :: (Int, Int) | a <- [0 .. 10], b <- [0 .. 20]]
250 lst = [(a, b) :: (Int, Int) | a <- [0 .. 10], b <- [0 .. 20]]
212 in testUnfold unf ((0, 0) :: (Int, Int)) lst
251 in testUnfold unf ((0, 0) :: (Int, Int)) lst
213
252
253+-------------------------------------------------------------------------------
254+-- Test groups
255+-------------------------------------------------------------------------------
256+
257+testInputOps :: Spec
258+testInputOps =
259+ describe "Input"
260+ $ do
261+ -- prop "lmap" lmap
262+ prop "lmapM" lmapM
263+ prop "supply" supply
264+ prop "supplyFirst" supplyFirst
265+ prop "supplySecond" supplySecond
266+ prop "discardFirst" discardFirst
267+ prop "discardSecond" discardSecond
268+ prop "swap" swap
269+
270+-------------------------------------------------------------------------------
271+-- Main
272+-------------------------------------------------------------------------------
273+
214main :: IO ()
274main :: IO ()
215−main = hspec $
275+main = hspec $ do
276+ testInputOps
216 describe "Unfold tests" $ do
277 describe "Unfold tests" $ do
217 prop "fromStream" fromStream
278 prop "fromStream" fromStream
218 prop "nilM" nilM
279 prop "nilM" nilM