on master help sign in
Add unfold tests for operations on input
commit3c5d2f875e53ae0293582613d09f11ebcceac5b2 authoradithyaov <adithya@composewell.com> dateTue 20 Oct 2020, 05:20 (6 years ago) parent5fb439a
1 file changed+62−1
test/Streamly/Test/Data/Unfold.hs+62−1
test/Streamly/Test/Data/Unfold.hs+62−1
@@ -57,6 +57,45 @@ testUnfold unf seed lst = runIdentity action
5757testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
5858testUnfoldD = testUnfold
5959
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+
6099-------------------------------------------------------------------------------
61100-- Stream generation
62101-------------------------------------------------------------------------------
@@ -211,8 +250,30 @@ outerProduct =
211250 lst = [(a, b) :: (Int, Int) | a <- [0 .. 10], b <- [0 .. 20]]
212251 in testUnfold unf ((0, 0) :: (Int, Int)) lst
213252
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+
214274main :: IO ()
215−main = hspec $
275+main = hspec $ do
276+ testInputOps
216277 describe "Unfold tests" $ do
217278 prop "fromStream" fromStream
218279 prop "nilM" nilM