@@ -23,7 +23,7 @@ import Data.Foldable (foldMap)
2323import Data.Function
2424import Data.Traversable (Traversable (traverse ), foldMapDefault )
2525import Prelude hiding (lookup , null , map , filter , foldr , foldl , foldl' )
26- import qualified Prelude (map )
26+ import qualified Prelude (map , filter )
2727
2828import Data.List (nub ,sort )
2929import qualified Data.List as List
@@ -103,7 +103,8 @@ main = defaultMain $ testGroup "intmap-properties"
103103 , testCase " fromAscListWithKey" test_fromAscListWithKey
104104 , testCase " fromDistinctAscList" test_fromDistinctAscList
105105 , testCase " filter" test_filter
106- , testCase " filterWithKey" test_filteWithKey
106+ , testCase " filterKeys" test_filterKeys
107+ , testCase " filterWithKey" test_filterWithKey
107108 , testCase " partition" test_partition
108109 , testCase " partitionWithKey" test_partitionWithKey
109110 , testCase " mapMaybe" test_mapMaybe
@@ -182,6 +183,8 @@ main = defaultMain $ testGroup "intmap-properties"
182183 , testProperty " deleteMin" prop_deleteMinModel
183184 , testProperty " deleteMax" prop_deleteMaxModel
184185 , testProperty " filter" prop_filter
186+ , testProperty " filterKeys" prop_filterKeys
187+ , testProperty " filterWithKey" prop_filterWithKey
185188 , testProperty " partition" prop_partition
186189 , testProperty " takeWhileAntitone" prop_takeWhileAntitone
187190 , testProperty " dropWhileAntitone" prop_dropWhileAntitone
@@ -867,8 +870,13 @@ test_filter = do
867870 filter (> " x" ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= empty
868871 filter (< " a" ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= empty
869872
870- test_filteWithKey :: Assertion
871- test_filteWithKey = do
873+ test_filterKeys :: Assertion
874+ test_filterKeys = do
875+ filterKeys (> 4 ) (fromList [(5 ," a" ), (3 ," b" )]) @?= singleton 5 " a"
876+ filterKeys (> 4 ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= singleton 5 " a"
877+
878+ test_filterWithKey :: Assertion
879+ test_filterWithKey = do
872880 filterWithKey (\ k _ -> k > 4 ) (fromList [(5 ," a" ), (3 ," b" )]) @?= singleton 5 " a"
873881 filterWithKey (\ k _ -> k > 4 ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= singleton 5 " a"
874882
@@ -1506,6 +1514,18 @@ prop_filter p ys = length ys > 0 ==>
15061514 in valid m .&&.
15071515 m === fromList (List. filter (apply p . snd ) xs)
15081516
1517+ prop_filterKeys :: Fun Int Bool -> IMap -> Property
1518+ prop_filterKeys fun m =
1519+ valid m' .&&. toList m' === Prelude. filter (apply fun . fst ) (toList m)
1520+ where
1521+ m' = filterKeys (apply fun) m
1522+
1523+ prop_filterWithKey :: Fun (Int , Int ) Bool -> IMap -> Property
1524+ prop_filterWithKey fun m =
1525+ valid m' .&&. toList m' === Prelude. filter (apply fun) (toList m)
1526+ where
1527+ m' = filterWithKey (applyFun2 fun) m
1528+
15091529prop_partition :: Fun Int Bool -> [(Int , Int )] -> Property
15101530prop_partition p ys = length ys > 0 ==>
15111531 let xs = List. nubBy ((==) `on` fst ) ys
0 commit comments