on master help sign in
Refactor applicativeOps.
d78cc53Pranay Sashank
test/Streamly/Test/Prelude.hs+32−20
@@ -237,38 +237,50 @@ constructWithFromIndicesM op len =
237applicativeOps
237applicativeOps
238 :: Applicative (t IO)
238 :: Applicative (t IO)
239 => ([Int] -> t IO Int)
239 => ([Int] -> t IO Int)
240+ -> String
240 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
241 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
241 -> (t IO (Int, Int) -> SerialT IO (Int, Int))
242 -> (t IO (Int, Int) -> SerialT IO (Int, Int))
242− -> ([Int], [Int])
243+ -> Spec
243− -> Property
244−applicativeOps constr eq t (a, b) = withMaxSuccess maxTestCount $
244+applicativeOps constr desc eq t = do
245− monadicIO $ do
245+ prop (desc <> " <*>") $
246− stream <- run ((S.toList . t) ((,) <$> constr a <*> constr b))
246+ transformFromList2
247− let list = (,) <$> a <*> b
247+ constr
248− listEquals eq stream list
248+ eq
249−
249+ (\a b -> (,) <$> a <*> b)
250− stream1 <- run ((S.toList . t) (liftA2 (,) (constr a) (constr b)))
250+ (\a b -> t ((,) <$> a <*> b))
251− listEquals eq stream1 list
251+ prop (desc <> " liftA2") $
252+ transformFromList2 constr eq (liftA2 (,)) (\a b -> t $ liftA2 (,) a b)
252
253
253-- XXX we can combine this with applicativeOps by making the type sufficiently
254-- XXX we can combine this with applicativeOps by making the type sufficiently
254-- polymorphic.
255-- polymorphic.
255applicativeOps1
256applicativeOps1
256 :: Applicative (t IO)
257 :: Applicative (t IO)
257 => ([Int] -> t IO Int)
258 => ([Int] -> t IO Int)
259+ -> String
258 -> ([Int] -> [Int] -> Bool)
260 -> ([Int] -> [Int] -> Bool)
259 -> (t IO Int -> SerialT IO Int)
261 -> (t IO Int -> SerialT IO Int)
260− -> ([Int], [Int])
262+ -> Spec
261− -> Property
263+applicativeOps1 constr desc eq t = do
264+ prop (desc <> " *>") $
265+ transformFromList2 constr eq (*>) (\a b -> t (a *> b))
266+ prop (desc <> " <*") $
267+ transformFromList2 constr eq (<*) (\a b -> t (a <* b))
268+
269+transformFromList2
270+ :: (Eq c, Show c)
271+ => ([a] -> t IO a)
272+ -> ([c] -> [c] -> Bool)
273+ -> ([a] -> [a] -> [c])
274+ -> (t IO a -> t IO a -> SerialT IO c)
275+ -> ([a], [a])
276+ -> Property
277+transformFromList2 constr eq listOp op (a, b) =
262−applicativeOps1 constr eq t (a, b) = withMaxSuccess maxTestCount $
278+ withMaxSuccess maxTestCount $
263 monadicIO $ do
279 monadicIO $ do
264− stream <- run ((S.toList . t) (constr a *> constr b))
280+ stream <- run (S.toList $ op (constr a) (constr b))
265− let list = a *> b
281+ let list = listOp a b
266 listEquals eq stream list
282 listEquals eq stream list
267
283
268− stream1 <- run ((S.toList . t) (constr a <* constr b))
269− let list1 = a <* b
270− listEquals eq stream1 list1
271−
272-------------------------------------------------------------------------------
284-------------------------------------------------------------------------------
273-- Elimination operations
285-- Elimination operations
274-------------------------------------------------------------------------------
286-------------------------------------------------------------------------------
@@ -432,7 +444,7 @@ eliminationOpsWord8 constr desc t = do
432-------------------------------------------------------------------------------
444-------------------------------------------------------------------------------
433
445
434functorOps
446functorOps
435− :: Functor (t IO)
447+ :: (Functor (t IO), Semigroup (t IO Int))
436 => ([Int] -> t IO Int)
448 => ([Int] -> t IO Int)
437 -> String
449 -> String
438 -> ([Int] -> [Int] -> Bool)
450 -> ([Int] -> [Int] -> Bool)
test/Streamly/Test/Prelude/Ahead.hs+2−2
@@ -44,8 +44,8 @@ main = hspec
44 aheadOps $ semigroupOps "aheadly" (==)
44 aheadOps $ semigroupOps "aheadly" (==)
45
45
46 describe "Applicative operations" $ do
46 describe "Applicative operations" $ do
47− aheadOps $ prop "aheadly applicative" . applicativeOps S.fromFoldable (==)
47+ aheadOps $ applicativeOps S.fromFoldable "aheadly applicative" (==)
48− aheadOps $ prop "aheadly applicative folded" . applicativeOps folded (==)
48+ aheadOps $ applicativeOps folded "aheadly applicative folded" (==)
49
49
50 -- XXX add tests for indexed/indexedR
50 -- XXX add tests for indexed/indexedR
51 describe "Zip operations" $ do
51 describe "Zip operations" $ do
test/Streamly/Test/Prelude/Async.hs+2−2
@@ -44,8 +44,8 @@ main = hspec
44 asyncOps $ semigroupOps "asyncly" sortEq
44 asyncOps $ semigroupOps "asyncly" sortEq
45
45
46 describe "Applicative operations" $ do
46 describe "Applicative operations" $ do
47− asyncOps $ prop "asyncly applicative" . applicativeOps S.fromFoldable sortEq
47+ asyncOps $ applicativeOps S.fromFoldable "asyncly applicative" sortEq
48− asyncOps $ prop "asyncly applicative folded" . applicativeOps folded sortEq
48+ asyncOps $ applicativeOps folded "asyncly applicative folded" sortEq
49
49
50 -- XXX add tests for indexed/indexedR
50 -- XXX add tests for indexed/indexedR
51 describe "Zip operations" $ do
51 describe "Zip operations" $ do
test/Streamly/Test/Prelude/Parallel.hs+1−2
@@ -48,8 +48,7 @@ main = hspec
48 parallelOps $ semigroupOps "parallely" sortEq
48 parallelOps $ semigroupOps "parallely" sortEq
49
49
50 describe "Applicative operations" $ do
50 describe "Applicative operations" $ do
51− parallelOps $
52− prop "parallely applicative folded" . applicativeOps folded sortEq
51+ parallelOps $ applicativeOps folded "parallely applicative folded" sortEq
53
52
54 -- XXX add tests for indexed/indexedR
53 -- XXX add tests for indexed/indexedR
55 describe "Zip operations" $ do
54 describe "Zip operations" $ do
test/Streamly/Test/Prelude/Serial.hs+4−3
@@ -184,9 +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 $ prop "serially applicative" . applicativeOps S.fromFoldable (==)
187+ serialOps $ applicativeOps S.fromFoldable "serially applicative" (==)
188− serialOps $ prop "serially applicative folded" . applicativeOps folded (==)
188+ serialOps $ applicativeOps folded "serially applicative folded" (==)
189+ serialOps $
189− serialOps $ prop "serially applicative discard" . applicativeOps1 S.fromFoldable (==)
190+ applicativeOps1 S.fromFoldable "serially applicative discard" (==)
190
191
191 -- XXX add tests for indexed/indexedR
192 -- XXX add tests for indexed/indexedR
192 describe "Zip operations" $ do
193 describe "Zip operations" $ do
test/Streamly/Test/Prelude/WAsync.hs+2−4
@@ -45,10 +45,8 @@ main = hspec
45 wAsyncOps $ semigroupOps "wAsyncly" sortEq
45 wAsyncOps $ semigroupOps "wAsyncly" sortEq
46
46
47 describe "Applicative operations" $ do
47 describe "Applicative operations" $ do
48− wAsyncOps $
49− prop "wAsyncly applicative" . applicativeOps S.fromFoldable sortEq
48+ wAsyncOps $ applicativeOps S.fromFoldable "wAsyncly applicative" sortEq
50− wAsyncOps $
51− prop "wAsyncly applicative folded" . applicativeOps folded sortEq
49+ wAsyncOps $ applicativeOps folded "wAsyncly applicative folded" sortEq
52
50
53 -- XXX add tests for indexed/indexedR
51 -- XXX add tests for indexed/indexedR
54 describe "Zip operations" $
52 describe "Zip operations" $
test/Streamly/Test/Prelude/WSerial.hs+2−2
@@ -45,8 +45,8 @@ main = hspec
45 wSerialOps $ semigroupOps "wSerially" (==)
45 wSerialOps $ semigroupOps "wSerially" (==)
46
46
47 describe "Applicative operations" $ do
47 describe "Applicative operations" $ do
48− wSerialOps $ prop "wSerially applicative" . applicativeOps S.fromFoldable sortEq
48+ wSerialOps $ applicativeOps S.fromFoldable "wSerially applicative" sortEq
49− wSerialOps $ prop "wSerially applicative folded" . applicativeOps folded sortEq
49+ wSerialOps $ applicativeOps folded "wSerially applicative folded" sortEq
50
50
51 -- XXX add tests for indexed/indexedR
51 -- XXX add tests for indexed/indexedR
52 describe "Zip operations" $ do
52 describe "Zip operations" $ do