Skip to content

Commit 133059d

Browse files
Replace withMaxSuccess by withNumTests
1 parent eefe9d1 commit 133059d

9 files changed

Lines changed: 72 additions & 72 deletions

File tree

test/Streamly/Test/Data/Fold.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Main (main) where
55
import Data.List (sort, sortBy)
66
import Data.Ord (comparing, Down(..))
77
import Data.Semigroup (Sum(..), getSum)
8-
import Streamly.Test.Common (checkListEqual, listEquals)
98
import Test.QuickCheck
109
( Gen
1110
, Property
@@ -16,7 +15,6 @@ import Test.QuickCheck
1615
, listOf1
1716
, property
1817
, vectorOf
19-
, withMaxSuccess
2018
, generate
2119
)
2220
import Control.Monad.IO.Class (liftIO)
@@ -30,6 +28,7 @@ import qualified Streamly.Internal.Data.Stream as Stream
3028

3129
import Prelude hiding
3230
(maximum, minimum, elem, notElem, null, product, sum, head, last, take)
31+
import Streamly.Test.Common
3332
import Test.Hspec as H
3433
import Test.Hspec.QuickCheck
3534

@@ -48,9 +47,6 @@ min_value = 0
4847
max_value :: Int
4948
max_value = 10000
5049

51-
chooseInt :: (Int, Int) -> Gen Int
52-
chooseInt = choose
53-
5450
{-# INLINE maxStreamLen #-}
5551
{-# INLINE intMin #-}
5652
{-# INLINE intMax #-}
@@ -272,7 +268,7 @@ drainBy ls = Stream.fold (Fold.drainBy return) (Stream.fromList ls) `shouldRetu
272268
mean :: Property
273269
mean =
274270
forAll (listOf1 (chooseFloat (-100.0, 100.0)))
275-
$ \ls0 -> withMaxSuccess 1000 $ monadicIO $ action ls0
271+
$ \ls0 -> withNumTests 1000 $ monadicIO $ action ls0
276272

277273
where
278274

@@ -284,7 +280,7 @@ mean =
284280
stdDev :: Property
285281
stdDev =
286282
forAll (listOf1 (chooseFloat (-100.0, 100.0)))
287-
$ \ls0 -> withMaxSuccess 1000 $ monadicIO $ action ls0
283+
$ \ls0 -> withNumTests 1000 $ monadicIO $ action ls0
288284

289285
where
290286

@@ -298,7 +294,7 @@ stdDev =
298294
variance :: Property
299295
variance =
300296
forAll (listOf1 (chooseFloat (-100.0, 100.0)))
301-
$ \ls0 -> withMaxSuccess 1000 $ monadicIO $ action ls0
297+
$ \ls0 -> withNumTests 1000 $ monadicIO $ action ls0
302298

303299
where
304300

test/Streamly/Test/Data/Stream.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import Test.QuickCheck
3434
, listOf1
3535
, suchThat
3636
, vectorOf
37-
, withMaxSuccess
3837
)
3938
import Test.QuickCheck.Monadic (assert, monadicIO, pick, run)
4039

@@ -220,7 +219,7 @@ intercalateSplitEqId sep splitter lIntercalater sIntercalater i =
220219
<> show i <> " element separator)"
221220
in prop name
222221
$ forAll (listWithSep sep)
223-
$ \xs -> withMaxSuccess maxTestCount $ monadicIO $ testCase xs
222+
$ \xs -> withNumTests maxTestCount $ monadicIO $ testCase xs
224223

225224
where
226225

@@ -242,7 +241,7 @@ intercalateSplitEqIdNoSepEnd sep splitter lIntercalater sIntercalater i =
242241
$ forAll ((,) <$> listWithSep sep <*> nonSepElem sep)
243242
$ \(xs_, nonSep) -> do
244243
let xs = xs_ ++ [nonSep]
245-
withMaxSuccess maxTestCount $ monadicIO $ testCase xs
244+
withNumTests maxTestCount $ monadicIO $ testCase xs
246245

247246
where
248247

@@ -263,7 +262,7 @@ concatSplitIntercalateEqConcat sep splitter lIntercalater sIntercalater i =
263262
<> show i <> " element separator/possibly empty list)"
264263
in prop name
265264
$ forAll (listsWithoutSep sep)
266-
$ \xss -> withMaxSuccess maxTestCount $ monadicIO $ testCase xss
265+
$ \xss -> withNumTests maxTestCount $ monadicIO $ testCase xss
267266

268267
where
269268

@@ -285,7 +284,7 @@ splitIntercalateEqId sep splitter lIntercalater sIntercalater =
285284
in prop name
286285
$ forAll (listsWithoutSep1 sep)
287286
$ \xss -> do
288-
withMaxSuccess maxTestCount $ monadicIO $ testCase xss
287+
withNumTests maxTestCount $ monadicIO $ testCase xss
289288

290289
where
291290

@@ -396,7 +395,7 @@ intercalateSplitOnId ::
396395
intercalateSplitOnId x desc =
397396
prop (desc <> " intercalate [x] . splitOn (== x) == id") $
398397
forAll listWithZeroes $ \xs -> do
399-
withMaxSuccess maxTestCount $
398+
withNumTests maxTestCount $
400399
monadicIO $ do
401400
ys <- toList $ splitOn (== x) Fold.toList (Stream.fromList xs)
402401
listEquals (==) (intercalate [x] ys) xs
@@ -839,7 +838,7 @@ main = hspec
839838
serialOps $ eliminationOpsWord8 folded "serially folded"
840839
serialOps $ \t ->
841840
prop "drainWhile (> 0)" $ \n ->
842-
withMaxSuccess maxTestCount $
841+
withNumTests maxTestCount $
843842
monadicIO $ do
844843
let xs = [1..n]
845844
ioRef <- run $ newIORef ([] :: [Int])

test/Streamly/Test/Data/Stream/Concurrent.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Data.Maybe ( isJust, fromJust )
2020
import Data.Word (Word8)
2121
import Streamly.Data.Stream (Stream)
2222
import Test.Hspec.QuickCheck
23-
import Test.QuickCheck (Testable, Property, choose, forAll, withMaxSuccess)
23+
import Test.QuickCheck (Testable, Property, choose, forAll)
2424
import Test.QuickCheck.Monadic (monadicIO, run)
2525
import Test.Hspec as H
2626

@@ -29,7 +29,7 @@ import qualified Streamly.Internal.Data.Stream as Stream
2929
import qualified Streamly.Internal.Data.Stream.Prelude as Stream
3030
import qualified Streamly.Internal.Data.Stream.Prelude as Async
3131

32-
import Streamly.Test.Common (listEquals)
32+
import Streamly.Test.Common (withNumTests, listEquals)
3333

3434
moduleName :: String
3535
moduleName = "Data.Stream.Concurrent"
@@ -68,7 +68,7 @@ transformCombineFromList ::
6868
-> [Int]
6969
-> Property
7070
transformCombineFromList constr eq listOp op a b c =
71-
withMaxSuccess maxTestCount $
71+
withNumTests maxTestCount $
7272
monadicIO $ do
7373
let s1 = op (Async.parList id [constr b, constr c])
7474
let s2 = Async.parList id [constr a, s1]
@@ -199,7 +199,7 @@ constructWithLenM
199199
-> Word8
200200
-> Property
201201
constructWithLenM mkStream mkList len =
202-
withMaxSuccess maxTestCount
202+
withNumTests maxTestCount
203203
$ monadicIO $ do
204204
stream <-
205205
run

test/Streamly/Test/Prelude/Async.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Streamly.Test.Prelude.Async (main) where
1414
import Control.Concurrent (threadDelay)
1515
import Data.List (sort)
1616
import Test.Hspec.QuickCheck
17-
import Test.QuickCheck (Property, withMaxSuccess)
17+
import Test.QuickCheck (Property)
1818
import Test.QuickCheck.Monadic (monadicIO, run)
1919
import Test.Hspec as H
2020

@@ -32,7 +32,7 @@ moduleName = "Prelude.Async"
3232
constructfromAsyncSingleThread ::
3333
S.AsyncT IO Int -> S.AsyncT IO Int-> [Int] -> Property
3434
constructfromAsyncSingleThread s1 s2 res =
35-
withMaxSuccess maxTestCount $
35+
withNumTests maxTestCount $
3636
monadicIO $ do
3737
x <- run
3838
$ S.toList

test/Streamly/Test/Prelude/Concurrent.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import Data.IORef (readIORef, modifyIORef, newIORef)
2626
import GHC.Word (Word8)
2727
import Test.Hspec.QuickCheck
2828
import Test.Hspec as H
29-
import Test.QuickCheck
30-
(Property, withMaxSuccess)
29+
import Test.QuickCheck (Property)
3130
import Test.QuickCheck.Monadic (monadicIO, run)
3231

3332
import Streamly.Prelude hiding (fold, replicate, replicateM, reverse, runStateT)
@@ -149,7 +148,7 @@ concurrentOps
149148
-> (t IO Word8 -> SerialT IO Word8)
150149
-> Spec
151150
concurrentOps constr desc eq t = do
152-
let prop1 d p = prop d $ withMaxSuccess maxTestCount p
151+
let prop1 d p = prop d $ withNumTests maxTestCount p
153152

154153
prop1 (desc <> " fromFoldableM") $ concurrentFromFoldable eq t
155154
prop1 (desc <> " unfoldrM") $ concurrentUnfoldrM eq t
@@ -176,7 +175,7 @@ concurrentApplication :: IsStream t
176175
-> (t IO Word8 -> SerialT IO Word8)
177176
-> Word8
178177
-> Property
179-
concurrentApplication eq t n = withMaxSuccess maxTestCount $
178+
concurrentApplication eq t n = withNumTests maxTestCount $
180179
monadicIO $ do
181180
-- XXX we should test empty list case as well
182181
let list = [0..n]
@@ -423,9 +422,9 @@ main = hspec
423422
parallelConcurrentAppOps $
424423
prop "parallel" . concurrentApplication sortEq
425424

426-
prop "concurrent foldr application" $ withMaxSuccess maxTestCount
425+
prop "concurrent foldr application" $ withNumTests maxTestCount
427426
concurrentFoldrApplication
428-
prop "concurrent foldl application" $ withMaxSuccess maxTestCount
427+
prop "concurrent foldl application" $ withNumTests maxTestCount
429428
concurrentFoldlApplication
430429

431430
describe "take on infinite concurrent stream" $ takeInfinite fromAsync

test/Streamly/Test/Prelude/Serial.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import Test.QuickCheck
3939
, listOf1
4040
, suchThat
4141
, vectorOf
42-
, withMaxSuccess
4342
)
4443
import Test.QuickCheck.Monadic (assert, monadicIO, pick, run)
4544
import Test.Hspec as H
@@ -255,7 +254,7 @@ splitterProperties sep desc = do
255254
<> show i <> " element separator)"
256255
in prop name
257256
$ forAll listWithSep
258-
$ \xs -> withMaxSuccess maxTestCount $ monadicIO $ testCase xs
257+
$ \xs -> withNumTests maxTestCount $ monadicIO $ testCase xs
259258

260259
where
261260

@@ -277,7 +276,7 @@ splitterProperties sep desc = do
277276
$ forAll ((,) <$> listWithSep <*> nonSepElem)
278277
$ \(xs_, nonSep) -> do
279278
let xs = xs_ ++ [nonSep]
280-
withMaxSuccess maxTestCount $ monadicIO $ testCase xs
279+
withNumTests maxTestCount $ monadicIO $ testCase xs
281280

282281
where
283282

@@ -298,7 +297,7 @@ splitterProperties sep desc = do
298297
<> show i <> " element separator/possibly empty list)"
299298
in prop name
300299
$ forAll listsWithoutSep
301-
$ \xss -> withMaxSuccess maxTestCount $ monadicIO $ testCase xss
300+
$ \xss -> withNumTests maxTestCount $ monadicIO $ testCase xss
302301

303302
where
304303

@@ -320,7 +319,7 @@ splitterProperties sep desc = do
320319
in prop name
321320
$ forAll listsWithoutSep1
322321
$ \xss -> do
323-
withMaxSuccess maxTestCount $ monadicIO $ testCase xss
322+
withNumTests maxTestCount $ monadicIO $ testCase xss
324323

325324
where
326325

@@ -338,7 +337,7 @@ intercalateSplitOnId ::
338337
intercalateSplitOnId x desc =
339338
prop (desc <> " intercalate [x] . splitOn (== x) == id") $
340339
forAll listWithZeroes $ \xs -> do
341-
withMaxSuccess maxTestCount $
340+
withNumTests maxTestCount $
342341
monadicIO $ do
343342
ys <- toList $ splitOn (== x) toListFL (S.fromList xs)
344343
listEquals (==) (intercalate [x] ys) xs
@@ -711,7 +710,7 @@ main = hspec
711710
serialOps $ eliminationOpsWord8 folded "serially folded"
712711
serialOps $ \t ->
713712
prop "drainWhile (> 0)" $ \n ->
714-
withMaxSuccess maxTestCount $
713+
withNumTests maxTestCount $
715714
monadicIO $ do
716715
let xs = [1..n]
717716
ioRef <- run $ newIORef ([] :: [Int])

test/Streamly/Test/Prelude/WAsync.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Control.Concurrent ( threadDelay )
1616
#endif
1717
import Data.List (sort)
1818
import Test.Hspec.QuickCheck
19-
import Test.QuickCheck (Property, withMaxSuccess)
19+
import Test.QuickCheck (Property)
2020
import Test.QuickCheck.Monadic (monadicIO, run)
2121
import Test.Hspec as H
2222

@@ -32,7 +32,7 @@ moduleName = "Prelude.WAsync"
3232
constructfromWAsync ::
3333
S.WAsyncT IO Int -> S.WAsyncT IO Int-> [Int] -> Property
3434
constructfromWAsync s1 s2 res =
35-
withMaxSuccess maxTestCount $
35+
withNumTests maxTestCount $
3636
monadicIO $ do
3737
x <- run
3838
$ S.toList

test/lib/Streamly/Test/Common.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
12
-- |
23
-- Module : Streamly.Test.Common
34
-- Copyright : (c) 2020 Composewell Technologies
@@ -14,17 +15,23 @@ module Streamly.Test.Common
1415
, chooseInt
1516
, chooseDouble
1617
, performGCSweep
18+
, withNumTests
1719
) where
1820

1921
import Control.Monad (when, void, replicateM_)
2022
import Control.Monad.IO.Class (MonadIO(..))
2123
import Data.List ((\\))
2224
import System.Mem (performMajorGC)
23-
import Test.QuickCheck (Property, Gen, choose, counterexample)
25+
import Test.QuickCheck
26+
(Testable, Property, Gen, choose, counterexample, withMaxSuccess)
2427
import Test.QuickCheck.Monadic (PropertyM, assert, monitor, monadicIO)
2528

2629
import qualified Streamly.Internal.Data.MutArray as MA
2730

31+
-- withMaxSuccess is deprecated
32+
withNumTests :: Testable prop => Int -> prop -> Property
33+
withNumTests = withMaxSuccess
34+
2835
equals
2936
:: (Show a, Monad m)
3037
=> (a -> a -> Bool) -> a -> a -> PropertyM m ()

0 commit comments

Comments
 (0)