on master help sign in
Move applicative and functor ops from test/Main to Prelude.
f1b0795Pranay Sashank
test/Main.hs−37
@@ -205,43 +205,6 @@ parallelTests = H.parallel $ do
205 -- it "MonadPlus - mzero" $
205 -- it "MonadPlus - mzero" $
206 -- (toListSerial mzero) `shouldReturn` ([] :: [Int])
206 -- (toListSerial mzero) `shouldReturn` ([] :: [Int])
207
207
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)])
245
208
246 ---------------------------------------------------------------------------
209 ---------------------------------------------------------------------------
247 -- Monoidal Compositions, multiset equality checks
210 -- Monoidal Compositions, multiset equality checks
test/Streamly/Test/Prelude.hs+20−6
@@ -235,7 +235,7 @@ constructWithFromIndicesM op len =
235-------------------------------------------------------------------------------
235-------------------------------------------------------------------------------
236
236
237applicativeOps
237applicativeOps
238− :: Applicative (t IO)
238+ :: (Applicative (t IO), Semigroup (t IO Int))
239 => ([Int] -> t IO Int)
239 => ([Int] -> t IO Int)
240 -> String
240 -> String
241 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
241 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
@@ -250,6 +250,14 @@ applicativeOps constr desc eq t = do
250 (\a b -> t ((,) <$> a <*> b))
250 (\a b -> t ((,) <$> a <*> b))
251 prop (desc <> " liftA2") $
251 prop (desc <> " liftA2") $
252 transformFromList2 constr eq (liftA2 (,)) (\a b -> t $ liftA2 (,) a b)
252 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)]
253
261
254-- XXX we can combine this with applicativeOps by making the type sufficiently
262-- XXX we can combine this with applicativeOps by making the type sufficiently
255-- polymorphic.
263-- polymorphic.
@@ -452,11 +460,12 @@ functorOps
452 -> Spec
460 -> Spec
453functorOps constr desc eq t = do
461functorOps constr desc eq t = do
454 prop (desc <> " id") $ transformFromList constr eq id t
462 prop (desc <> " id") $ transformFromList constr eq id t
463+ prop (desc <> " fmap (+1)") $
455− prop (desc <> " fmap (+1)") $ transformFromList constr eq (fmap (+1)) $ t . fmap (+1)
464+ transformFromList constr eq (fmap (+ 1)) $ t . fmap (+ 1)
456−
465+ prop (desc <> " fmap on composed (<>)") $
457−-------------------------------------------------------------------------------
466+ sort <$>
458−-- Semigroup operations
467+ (S.toList . t) (fmap (+ 1) (constr [1] <> constr [2])) `shouldReturn`
459−-------------------------------------------------------------------------------
468+ ([2, 3] :: [Int])
460
469
461transformFromList
470transformFromList
462 :: (Eq b, Show b) =>
471 :: (Eq b, Show b) =>
@@ -472,6 +481,11 @@ transformFromList constr eq listOp op a =
472 let list = listOp a
481 let list = listOp a
473 listEquals eq stream list
482 listEquals eq stream list
474
483
484+
485+-------------------------------------------------------------------------------
486+-- Semigroup operations
487+-------------------------------------------------------------------------------
488+
475foldFromList
489foldFromList
476 :: ([Int] -> t IO Int)
490 :: ([Int] -> t IO Int)
477 -> (t IO Int -> SerialT IO Int)
491 -> (t IO Int -> SerialT IO Int)
test/Streamly/Test/Prelude/Serial.hs+4−4
@@ -184,10 +184,10 @@ main = hspec
184 -- The tests using sorted equality are weaker tests
184 -- The tests using sorted equality are weaker tests
185 -- We need to have stronger unit tests for all those
185 -- We need to have stronger unit tests for all those
186 -- XXX applicative with three arguments
186 -- XXX applicative with three arguments
187− serialOps $ applicativeOps S.fromFoldable "serially applicative" (==)
187+ serialOps $ applicativeOps S.fromFoldable "serially" (==)
188− serialOps $ applicativeOps folded "serially applicative folded" (==)
188+ serialOps $ applicativeOps folded "serially folded" (==)
189− serialOps $
189+ serialOps $ applicativeOps1 S.fromFoldable "serially" (==)
190− applicativeOps1 S.fromFoldable "serially applicative discard" (==)
190+ serialOps $ applicativeOps1 S.fromFoldable "serially folded" (==)
191
191
192 -- XXX add tests for indexed/indexedR
192 -- XXX add tests for indexed/indexedR
193 describe "Zip operations" $ do
193 describe "Zip operations" $ do