@@ -23,7 +23,7 @@ import Data.Foldable (foldMap)
23
23
import Data.Function
24
24
import Data.Traversable (Traversable (traverse ), foldMapDefault )
25
25
import Prelude hiding (lookup , null , map , filter , foldr , foldl , foldl' )
26
- import qualified Prelude (map )
26
+ import qualified Prelude (map , filter )
27
27
28
28
import Data.List (nub ,sort )
29
29
import qualified Data.List as List
@@ -103,7 +103,8 @@ main = defaultMain $ testGroup "intmap-properties"
103
103
, testCase " fromAscListWithKey" test_fromAscListWithKey
104
104
, testCase " fromDistinctAscList" test_fromDistinctAscList
105
105
, testCase " filter" test_filter
106
- , testCase " filterWithKey" test_filteWithKey
106
+ , testCase " filterKeys" test_filterKeys
107
+ , testCase " filterWithKey" test_filterWithKey
107
108
, testCase " partition" test_partition
108
109
, testCase " partitionWithKey" test_partitionWithKey
109
110
, testCase " mapMaybe" test_mapMaybe
@@ -182,6 +183,8 @@ main = defaultMain $ testGroup "intmap-properties"
182
183
, testProperty " deleteMin" prop_deleteMinModel
183
184
, testProperty " deleteMax" prop_deleteMaxModel
184
185
, testProperty " filter" prop_filter
186
+ , testProperty " filterKeys" prop_filterKeys
187
+ , testProperty " filterWithKey" prop_filterWithKey
185
188
, testProperty " partition" prop_partition
186
189
, testProperty " takeWhileAntitone" prop_takeWhileAntitone
187
190
, testProperty " dropWhileAntitone" prop_dropWhileAntitone
@@ -867,8 +870,13 @@ test_filter = do
867
870
filter (> " x" ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= empty
868
871
filter (< " a" ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= empty
869
872
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
872
880
filterWithKey (\ k _ -> k > 4 ) (fromList [(5 ," a" ), (3 ," b" )]) @?= singleton 5 " a"
873
881
filterWithKey (\ k _ -> k > 4 ) (fromList [(5 ," a" ), (- 3 ," b" )]) @?= singleton 5 " a"
874
882
@@ -1506,6 +1514,18 @@ prop_filter p ys = length ys > 0 ==>
1506
1514
in valid m .&&.
1507
1515
m === fromList (List. filter (apply p . snd ) xs)
1508
1516
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
+
1509
1529
prop_partition :: Fun Int Bool -> [(Int , Int )] -> Property
1510
1530
prop_partition p ys = length ys > 0 ==>
1511
1531
let xs = List. nubBy ((==) `on` fst ) ys
0 commit comments