Skip to content

Commit c707ea8

Browse files
committed
More tests on laziness of iterate'
See haskell/core-libraries-committee#335
1 parent fcce912 commit c707ea8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/Properties.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Test.Tasty
2323
import Test.Tasty.QuickCheck as QC
2424

2525
import Control.Applicative
26+
import Control.Exception
2627
import Control.Monad
2728
import Control.Monad.Fix (mfix)
2829
import Data.Bifunctor
@@ -240,13 +241,24 @@ main = defaultMain $ testGroup "All"
240241
, testProperty "iterate" $
241242
\(applyFun -> (f :: Int -> Int)) s ->
242243
trim (I.iterate f s) === L.take 10 (L.iterate f s)
243-
, testProperty "iterate laziness" $ once $
244+
, testProperty "iterate laziness 1" $ once $
244245
I.head (I.iterate undefined 'q') === 'q'
246+
, testProperty "iterate laziness 2" $ once $
247+
I.head (I.tail (I.iterate (\c -> if c == 'r' then undefined else 'r') 'q')) === 'r'
248+
, testProperty "iterate laziness 3" $ once $
249+
I.iterate (const 'q') undefined `seq` () === ()
245250
, testProperty "iterate'" $
246251
\(applyFun -> (f :: Int -> Int)) s ->
247252
trim (I.iterate' f s) === L.take 10 (L.iterate f s)
248-
, testProperty "iterate' laziness" $ once $
253+
, testProperty "iterate' laziness 1" $ once $
249254
I.head (I.iterate' undefined 'q') === 'q'
255+
, testProperty "iterate' laziness 2" $ once $
256+
I.head (I.tail (I.iterate' (\c -> if c == 'r' then undefined else 'r') 'q')) === 'r'
257+
, testProperty "iterate' laziness 3" $ once $ ioProperty $ do
258+
xs <- try $ evaluate $ I.iterate' (const 'q') undefined
259+
pure $ case xs of
260+
Left (_ :: SomeException) -> True
261+
_ -> False
250262

251263
, testProperty "repeat" $
252264
\(s :: Int) ->

0 commit comments

Comments
 (0)