Skip to content

Commit 0d83f53

Browse files
committed
Improve the Data.IntMap.mergeWithKey test to test more cases and have clearer output
1 parent 71e293e commit 0d83f53

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

tests/intmap-properties.hs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ test_toDescList = toDescList (fromList [(5,"a"), (3,"b")]) @?= [(5,"a"), (3,"b")
552552
test_showTree :: Assertion
553553
test_showTree =
554554
(let t = fromDistinctAscList [(x,()) | x <- [1..5]]
555-
in showTree t) @?= "*\n+--*\n| +-- 1:=()\n| +--*\n| +-- 2:=()\n| +-- 3:=()\n+--*\n +-- 4:=()\n +-- 5:=()\n"
555+
in showTree t) @?= "1 ()\n+--5 ()\n |\n +--3 ()\n | |\n | +-.\n | |\n | +--2 ()\n | |\n | +-.\n | |\n | +-.\n |\n +--4 ()\n |\n +-.\n |\n +-.\n"
556556

557557
test_fromAscList :: Assertion
558558
test_fromAscList = do
@@ -815,17 +815,9 @@ prop_withoutKeys m s0 = m `withoutKeys` s === filterWithKey (\k _ -> k `IntSet.n
815815
s = keysSet s0
816816
reduced = withoutKeys m s
817817

818-
prop_mergeWithKeyModel :: [(Int,Int)] -> [(Int,Int)] -> Bool
819-
prop_mergeWithKeyModel xs ys
820-
= and [ testMergeWithKey f keep_x keep_y
821-
| f <- [ \_k x1 _x2 -> Just x1
822-
, \_k _x1 x2 -> Just x2
823-
, \_k _x1 _x2 -> Nothing
824-
, \k x1 x2 -> if k `mod` 2 == 0 then Nothing else Just (2 * x1 + 3 * x2)
825-
]
826-
, keep_x <- [ True, False ]
827-
, keep_y <- [ True, False ]
828-
]
818+
prop_mergeWithKeyModel :: Fun (Int, Int, Int) (Maybe Int) -> Bool -> Bool -> [(Int,Int)] -> [(Int,Int)] -> Bool
819+
prop_mergeWithKeyModel f keep_x keep_y xs ys
820+
= testMergeWithKey (apply3 f) keep_x keep_y
829821

830822
where xs' = List.nubBy ((==) `on` fst) xs
831823
ys' = List.nubBy ((==) `on` fst) ys

0 commit comments

Comments
 (0)