Fix review suggestions for joinOuterHash

This commit is contained in:
Harendra Kumar 2022-01-24 18:27:53 +05:30
parent c8d1ca3fc7
commit 870958d766
2 changed files with 30 additions and 18 deletions

View File

@ -102,7 +102,6 @@ extra-source-files:
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/Stream/Top.hs
test/Streamly/Test/FileSystem/Event.hs
test/Streamly/Test/FileSystem/Event/Common.hs
test/Streamly/Test/FileSystem/Event/Darwin.hs

View File

@ -69,27 +69,49 @@ joinInnerMap =
]
assert (sort v1 == sort v2)
joinOuterList :: [(Int, Int)] -> [(Int, Int)] -> [(Int, Maybe Int, Maybe Int)]
joinOuterList ls0 ls1 =
let v2 = do
i <- ls0
if i `elem` ls1
then return (fst i, Just (fst i), Just (fst i))
else return (fst i, Just (fst i), Nothing)
v3 = do
j <- ls1
if j `elem` ls0
then return (fst j, Just (fst j), Just (fst j))
else return (fst j, Nothing, Just (fst j))
v4 = filter (\(_, a2, _) -> isNothing a2) v3
in v2 ++ v4
-- XXX A bug need to be fixed in joinOuter function
{-
joinOuter :: Property
joinOuter =
forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
monadicIO $ action ls0 ls1
monadicIO $ action ls0 (nub ls1)
where
action ls0 ls1 = do
v1 <-
run
$ S.toList
$ Top.joinOuter eq (S.fromList ls0) (S.fromList ls1)
let v2 = [ (Just i, Just j) | i <- ls0, j <- ls1, i == j ]
assert (v1 == v2)
let v2 = joinOuterList
(map (\a -> (a, a)) ls0)
(map (\a -> (a, a)) ls1)
v3 = map (\(_, v10, v20) -> (v10, v20)) v2
assert (sort v1 == sort v3)
-}
joinOuterMap :: Property
joinOuterMap =
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)) (nub ls1))
action
(map (\a -> (a,a)) (nub ls0))
(map (\a -> (a,a)) (nub ls1))
where
@ -98,18 +120,8 @@ joinOuterMap =
run
$ S.toList
$ Top.joinOuterMap (S.fromList ls0) (S.fromList ls1)
let v2 = do
i <- ls0
if (elem i ls1)
then return (fst i, Just (fst i), Just (fst i))
else return (fst i, Just (fst i), Nothing)
v3 = do
j <- ls1
if (elem j ls0)
then return (fst j, Just (fst j), Just (fst j))
else return (fst j, Nothing, Just (fst j))
v4 = filter (\(_, a2, _) -> isNothing a2) v3
assert (v1 == v2 ++ v4)
let v2 = joinOuterList ls0 ls1
assert (sort v1 == sort v2)
-------------------------------------------------------------------------------
-- Main
@ -125,5 +137,6 @@ main = hspec $ do
prop "joinInner" Main.joinInner
prop "joinInnerMap" Main.joinInnerMap
prop "joinOuter" Main.joinOuter
-- XXX currently API is broken https://github.com/composewell/streamly/issues/1032
--prop "joinOuter" Main.joinOuter
prop "joinOuterMap" Main.joinOuterMap