@@ -15,9 +15,13 @@ import Control.Concurrent (threadDelay)
15import Control.Monad (when)
15import Control.Monad (when)
17import Test.Hspec as H
17import Test.Hspec as H
18+import Test.Hspec.QuickCheck (prop)
19+import Test.QuickCheck (Property, choose)
20+import Test.QuickCheck.Monadic (monadicIO, pick)
19import qualified Streamly.Prelude as S
22import qualified Streamly.Prelude as S
20import qualified Streamly.Internal.Data.Fold as FL
23import qualified Streamly.Internal.Data.Fold as FL
24+import qualified Streamly.Internal.Data.Unfold as UF
21import qualified Streamly.Internal.Prelude as SI
25import qualified Streamly.Internal.Prelude as SI
23import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
27import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
@@ -25,6 +29,9 @@ import Streamly.Internal.Data.Time.Units
25 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
29 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
26import Data.Int (Int64)
30import Data.Int (Int64)
28tenPow8 :: Int64
35tenPow8 :: Int64
29tenPow8 = 10^(8 :: Int)
36tenPow8 = 10^(8 :: Int)
@@ -70,9 +77,28 @@ testDropByTime = do
70 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
77 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
71 checkTakeDropTime (Just t0, mt1)
78 checkTakeDropTime (Just t0, mt1)
81+unfold = monadicIO $ do
82+ a <- pick $ choose (0, max_length `div` 2)
83+ b <- pick $ choose (0, max_length)
84+ let unf = UF.enumerateFromToIntegral b
85+ ls <- S.toList $ S.unfold unf a
86+ return $ ls == [a..b]
89+unfold0 = monadicIO $ do
90+ a <- pick $ choose (0, max_length `div` 2)
91+ b <- pick $ choose (0, max_length)
92+ let unf = UF.supply (UF.enumerateFromToIntegral b) a
93+ ls <- S.toList $ SI.unfold0 unf
94+ return $ ls == [a..b]
73main :: IO ()
96main :: IO ()
75− hspec $
98+ hspec $ do
76− describe "Filtering" $ do
99+ describe "Filtering" $ do
77− it "takeByTime" (testTakeByTime `shouldReturn` True)
100+ it "takeByTime" (testTakeByTime `shouldReturn` True)
78− it "dropByTime" (testDropByTime `shouldReturn` True)
101+ it "dropByTime" (testDropByTime `shouldReturn` True)
102+ describe "From Generators" $ do
103+ prop "unfold" unfold
104+ prop "unfold0" unfold0