Add test cases for joinInnerHash

This commit is contained in:
Ranjeet Kumar Ranjan 2022-01-06 17:03:56 +05:30 committed by Harendra Kumar
parent 46314a25a0
commit 9fdce7a10a
3 changed files with 88 additions and 1 deletions

View File

@ -101,7 +101,7 @@ extra-source-files:
test/Streamly/Test/Data/Array/Prim/Pinned.hs
test/Streamly/Test/Data/Array/Foreign.hs
test/Streamly/Test/Data/Array/Stream/Foreign.hs
test/Streamly/Test/Data/Parser/ParserD.hs
test/Streamly/Test/Data/Parser/ParserD.hs
test/Streamly/Test/FileSystem/Event.hs
test/Streamly/Test/FileSystem/Event/Common.hs
test/Streamly/Test/FileSystem/Event/Darwin.hs

View File

@ -0,0 +1,83 @@
module Main (main)
where
import Data.List (sort)
import Test.QuickCheck
( Gen
, Property
, choose
, forAll
, listOf
)
import Test.QuickCheck.Monadic (monadicIO, assert, run)
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Data.Stream.IsStream.Top as Top
import Prelude hiding
(maximum, minimum, elem, notElem, null, product, sum, head, last, take)
import Test.Hspec as H
import Test.Hspec.QuickCheck
min_value :: Int
min_value = 0
max_value :: Int
max_value = 10000
chooseInt :: (Int, Int) -> Gen Int
chooseInt = choose
eq :: Int -> Int -> Bool
eq = (==)
joinInner :: Property
joinInner =
forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
monadicIO $ action ls0 ls1
where
action ls0 ls1 = do
v1 <-
run
$ S.toList
$ Top.joinInner eq (S.fromList ls0) (S.fromList $ sort ls1)
let v2 = [ (i,j) | i <- ls0, j <- ls1, i == j ]
assert (v1 == v2)
joinInnerHash :: Property
joinInnerHash =
forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
monadicIO $ action (map (\a -> (a,a)) ls0) (map (\a -> (a,a)) ls1)
where
action ls0 ls1 = do
v1 <-
run
$ S.toList
$ Top.joinInnerHash (S.fromList ls0) (S.fromList ls1)
let v2 = [
(fst i, fst i, fst j)
| i <- ls0, j <- ls1
, fst i == fst j
]
assert (v1 == v2)
-------------------------------------------------------------------------------
moduleName :: String
moduleName = "Prelude.Top"
main :: IO ()
main = hspec $ do
describe moduleName $ do
-- Joins
prop "joinInner" Main.joinInner
prop "joinInnerHash" Main.joinInnerHash

View File

@ -383,6 +383,10 @@ test-suite Prelude.Serial
if flag(limit-build-mem)
ghc-options: +RTS -M1500M -RTS
test-suite Prelude.Top
import: test-options
type: exitcode-stdio-1.0
main-is: Streamly/Test/Prelude/Top.hs
test-suite Prelude.WAsync
import: test-options