on master help sign in
Add tests for unfold and unfold0
commit9225c35d6bd6bca1c248f567fc2d6f1139297ecf authorShlok Datye <shlok@quant.is> dateFri 3 Jul 2020, 07:47 (6 years ago) parent6cc0e92
1 file changed+30−4
test/Streamly/Test/Internal/Prelude.hs+30−4
test/Streamly/Test/Internal/Prelude.hs+30−4
@@ -15,9 +15,13 @@ import Control.Concurrent (threadDelay)
1515import Control.Monad (when)
1616
1717import Test.Hspec as H
18+import Test.Hspec.QuickCheck (prop)
19+import Test.QuickCheck (Property, choose)
20+import Test.QuickCheck.Monadic (monadicIO, pick)
1821
1922import qualified Streamly.Prelude as S
2023import qualified Streamly.Internal.Data.Fold as FL
24+import qualified Streamly.Internal.Data.Unfold as UF
2125import qualified Streamly.Internal.Prelude as SI
2226
2327import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
@@ -25,6 +29,9 @@ import Streamly.Internal.Data.Time.Units
2529 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
2630import Data.Int (Int64)
2731
32+max_length :: Int
33+max_length = 1000
34+
2835tenPow8 :: Int64
2936tenPow8 = 10^(8 :: Int)
3037
@@ -70,9 +77,28 @@ testDropByTime = do
7077 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
7178 checkTakeDropTime (Just t0, mt1)
7279
80+unfold :: Property
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]
87+
88+unfold0 :: Property
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]
95+
7396main :: IO ()
7497main =
75− hspec $
76− describe "Filtering" $ do
77− it "takeByTime" (testTakeByTime `shouldReturn` True)
78− it "dropByTime" (testDropByTime `shouldReturn` True)
98+ hspec $ do
99+ describe "Filtering" $ do
100+ it "takeByTime" (testTakeByTime `shouldReturn` True)
101+ it "dropByTime" (testDropByTime `shouldReturn` True)
102+ describe "From Generators" $ do
103+ prop "unfold" unfold
104+ prop "unfold0" unfold0