on master help sign in
Add test cases for joinInnerHash
commit9fdce7a10af0a23e88bf80175b462a6db02c3bda authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 6 Jan 2022, 17:03 (5 years ago) parent46314a2
3 files changed+88−1
streamly.cabal+1−1 test/Streamly/Test/Prelude/Top.hs+83 test/streamly-tests.cabal+4
streamly.cabal+1−1
@@ -101,7 +101,7 @@ extra-source-files:
101101 test/Streamly/Test/Data/Array/Prim/Pinned.hs
102102 test/Streamly/Test/Data/Array/Foreign.hs
103103 test/Streamly/Test/Data/Array/Stream/Foreign.hs
104− test/Streamly/Test/Data/Parser/ParserD.hs
104+ test/Streamly/Test/Data/Parser/ParserD.hs
105105 test/Streamly/Test/FileSystem/Event.hs
106106 test/Streamly/Test/FileSystem/Event/Common.hs
107107 test/Streamly/Test/FileSystem/Event/Darwin.hs
test/Streamly/Test/Prelude/Top.hsnew file+83
@@ -0,0 +1,83 @@
1+module Main (main)
2+ where
3+
4+import Data.List (sort)
5+import Test.QuickCheck
6+ ( Gen
7+ , Property
8+ , choose
9+ , forAll
10+ , listOf
11+ )
12+import Test.QuickCheck.Monadic (monadicIO, assert, run)
13+import qualified Streamly.Prelude as S
14+import qualified Streamly.Internal.Data.Stream.IsStream.Top as Top
15+
16+import Prelude hiding
17+ (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
18+import Test.Hspec as H
19+import Test.Hspec.QuickCheck
20+
21+min_value :: Int
22+min_value = 0
23+
24+max_value :: Int
25+max_value = 10000
26+
27+chooseInt :: (Int, Int) -> Gen Int
28+chooseInt = choose
29+
30+eq :: Int -> Int -> Bool
31+eq = (==)
32+
33+
34+joinInner :: Property
35+joinInner =
36+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
37+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
38+ monadicIO $ action ls0 ls1
39+
40+ where
41+
42+ action ls0 ls1 = do
43+ v1 <-
44+ run
45+ $ S.toList
46+ $ Top.joinInner eq (S.fromList ls0) (S.fromList $ sort ls1)
47+ let v2 = [ (i,j) | i <- ls0, j <- ls1, i == j ]
48+ assert (v1 == v2)
49+
50+
51+
52+joinInnerHash :: Property
53+joinInnerHash =
54+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
55+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
56+ monadicIO $ action (map (\a -> (a,a)) ls0) (map (\a -> (a,a)) ls1)
57+
58+ where
59+
60+ action ls0 ls1 = do
61+ v1 <-
62+ run
63+ $ S.toList
64+ $ Top.joinInnerHash (S.fromList ls0) (S.fromList ls1)
65+ let v2 = [
66+ (fst i, fst i, fst j)
67+ | i <- ls0, j <- ls1
68+ , fst i == fst j
69+ ]
70+ assert (v1 == v2)
71+
72+
73+-------------------------------------------------------------------------------
74+moduleName :: String
75+moduleName = "Prelude.Top"
76+
77+main :: IO ()
78+main = hspec $ do
79+ describe moduleName $ do
80+ -- Joins
81+
82+ prop "joinInner" Main.joinInner
83+ prop "joinInnerHash" Main.joinInnerHash
test/streamly-tests.cabal+4
@@ -383,6 +383,10 @@ test-suite Prelude.Serial
383383 if flag(limit-build-mem)
384384 ghc-options: +RTS -M1500M -RTS
385385
386+test-suite Prelude.Top
387+ import: test-options
388+ type: exitcode-stdio-1.0
389+ main-is: Streamly/Test/Prelude/Top.hs
386390
387391test-suite Prelude.WAsync
388392 import: test-options