on master help sign in
Move applicative and functor ops from test/Main to Prelude.
commitf1b0795e5d487f6cbf2e0752ddad70e2dba5de25 authorPranay Sashank <pranaysashank@composewell.com> dateWed 29 Jul 2020, 12:26 (6 years ago) parentd78cc53
3 files changed+24−47
test/Main.hs−37 test/Streamly/Test/Prelude.hs+20−6 test/Streamly/Test/Prelude/Serial.hs+4−4
test/Main.hs−37
@@ -205,43 +205,6 @@ parallelTests = H.parallel $ do
205205 -- it "MonadPlus - mzero" $
206206 -- (toListSerial mzero) `shouldReturn` ([] :: [Int])
207207
208− ---------------------------------------------------------------------------
209− -- Functor
210− ---------------------------------------------------------------------------
211−
212− describe "Functor (fmap)" $ do
213− -- XXX we should do these through property tests by using a
214− -- construction via list fold construction method.
215− it "fmap on composed (<>)" $
216− toListSerial (fmap (+1) (return 1 <> return 2))
217− `shouldReturn` ([2,3] :: [Int])
218−
219− it "fmap on composed (<>)" $
220− sort <$> toListParallel (fmap (+1) (return 1 <> return 2))
221− `shouldReturn` ([2,3] :: [Int])
222−
223− ---------------------------------------------------------------------------
224− -- Applicative
225− ---------------------------------------------------------------------------
226−
227− describe "Applicative" $ do
228− -- XXX we should do these through property tests by using a
229− -- construction via list fold construction method.
230− it "Apply - serial composed first argument" $
231− toListSerial ((,) <$> (return 1 <> return 2) <*> return 3)
232− `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
233−
234− it "Apply - serial composed second argument" $
235− toListSerial ((,) <$> return 1 <*> (return 2 <> return 3))
236− `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
237−
238− it "Apply - parallel composed first argument" $
239− sort <$> toListParallel ((,) <$> (return 1 <> return 2) <*> return 3)
240− `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
241−
242− it "Apply - parallel composed second argument" $
243− sort <$> toListParallel ((,) <$> return 1 <*> (return 2 <> return 3))
244− `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
245208
246209 ---------------------------------------------------------------------------
247210 -- Monoidal Compositions, multiset equality checks
test/Streamly/Test/Prelude.hs+20−6
@@ -235,7 +235,7 @@ constructWithFromIndicesM op len =
235235-------------------------------------------------------------------------------
236236
237237applicativeOps
238− :: Applicative (t IO)
238+ :: (Applicative (t IO), Semigroup (t IO Int))
239239 => ([Int] -> t IO Int)
240240 -> String
241241 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
@@ -250,6 +250,14 @@ applicativeOps constr desc eq t = do
250250 (\a b -> t ((,) <$> a <*> b))
251251 prop (desc <> " liftA2") $
252252 transformFromList2 constr eq (liftA2 (,)) (\a b -> t $ liftA2 (,) a b)
253+ prop (desc <> " Apply - composed first argument") $
254+ sort <$>
255+ (S.toList . t) ((,) <$> (pure 1 <> pure 2) <*> pure 3) `shouldReturn`
256+ [(1, 3), (2, 3)]
257+ prop (desc <> " Apply - composed second argument") $
258+ sort <$>
259+ (S.toList . t) ((,) <$> pure 1 <*> (pure 2 <> pure 3)) `shouldReturn`
260+ [(1, 2), (1, 3)]
253261
254262-- XXX we can combine this with applicativeOps by making the type sufficiently
255263-- polymorphic.
@@ -452,11 +460,12 @@ functorOps
452460 -> Spec
453461functorOps constr desc eq t = do
454462 prop (desc <> " id") $ transformFromList constr eq id t
455− prop (desc <> " fmap (+1)") $ transformFromList constr eq (fmap (+1)) $ t . fmap (+1)
456−
457−-------------------------------------------------------------------------------
458−-- Semigroup operations
459−-------------------------------------------------------------------------------
463+ prop (desc <> " fmap (+1)") $
464+ transformFromList constr eq (fmap (+ 1)) $ t . fmap (+ 1)
465+ prop (desc <> " fmap on composed (<>)") $
466+ sort <$>
467+ (S.toList . t) (fmap (+ 1) (constr [1] <> constr [2])) `shouldReturn`
468+ ([2, 3] :: [Int])
460469
461470transformFromList
462471 :: (Eq b, Show b) =>
@@ -472,6 +481,11 @@ transformFromList constr eq listOp op a =
472481 let list = listOp a
473482 listEquals eq stream list
474483
484+
485+-------------------------------------------------------------------------------
486+-- Semigroup operations
487+-------------------------------------------------------------------------------
488+
475489foldFromList
476490 :: ([Int] -> t IO Int)
477491 -> (t IO Int -> SerialT IO Int)
test/Streamly/Test/Prelude/Serial.hs+4−4
@@ -184,10 +184,10 @@ main = hspec
184184 -- The tests using sorted equality are weaker tests
185185 -- We need to have stronger unit tests for all those
186186 -- XXX applicative with three arguments
187− serialOps $ applicativeOps S.fromFoldable "serially applicative" (==)
188− serialOps $ applicativeOps folded "serially applicative folded" (==)
189− serialOps $
190− applicativeOps1 S.fromFoldable "serially applicative discard" (==)
187+ serialOps $ applicativeOps S.fromFoldable "serially" (==)
188+ serialOps $ applicativeOps folded "serially folded" (==)
189+ serialOps $ applicativeOps1 S.fromFoldable "serially" (==)
190+ serialOps $ applicativeOps1 S.fromFoldable "serially folded" (==)
191191
192192 -- XXX add tests for indexed/indexedR
193193 describe "Zip operations" $ do