@@ -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