Skip to content

Commit 09ebe0f

Browse files
committed
Changes after review 2
1 parent 1c8ebc2 commit 09ebe0f

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

containers-tests/tests/intmap-properties.hs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Data.Foldable (foldMap)
2222
import Data.Function
2323
import Data.Traversable (Traversable(traverse), foldMapDefault)
2424
import Prelude hiding (lookup, null, map, filter, foldr, foldl, foldl')
25-
import qualified Prelude (map)
25+
import qualified Prelude (map, filter)
2626

2727
import Data.List (nub,sort)
2828
import qualified Data.List as List
@@ -180,6 +180,9 @@ main = defaultMain $ testGroup "intmap-properties"
180180
, testProperty "deleteMin" prop_deleteMinModel
181181
, testProperty "deleteMax" prop_deleteMaxModel
182182
, testProperty "filter" prop_filter
183+
, testProperty "filterWithKey" prop_filterWithKey
184+
, testProperty "filterKeys" prop_filterKeys
185+
, testProperty "filterKeysFidelity" prop_filterKeysFidelity
183186
, testProperty "partition" prop_partition
184187
, testProperty "takeWhileAntitone" prop_takeWhileAntitone
185188
, testProperty "dropWhileAntitone" prop_dropWhileAntitone
@@ -1470,6 +1473,24 @@ prop_filter p ys = length ys > 0 ==>
14701473
in valid m .&&.
14711474
m === fromList (List.filter (apply p . snd) xs)
14721475

1476+
prop_filterWithKey :: Fun (Int, Int) Bool -> IMap -> Property
1477+
prop_filterWithKey fun m =
1478+
valid m' .&&. toList m' === Prelude.filter (apply fun) (toList m)
1479+
where
1480+
m' = filterWithKey (apply2 fun) m
1481+
1482+
prop_filterKeys :: Fun Int Bool -> IMap -> Property
1483+
prop_filterKeys fun m =
1484+
valid m' .&&. toList m' === Prelude.filter (apply fun . fst) (toList m)
1485+
where
1486+
m' = filterKeys (apply fun) m
1487+
1488+
prop_filterKeysFidelity :: Fun Int Bool -> IMap -> Property
1489+
prop_filterKeysFidelity p m = fwk === fk
1490+
where
1491+
fwk = filterWithKey (\k _ -> apply p k) m
1492+
fk = filterKeys (apply p) m
1493+
14731494
prop_partition :: Fun Int Bool -> [(Int, Int)] -> Property
14741495
prop_partition p ys = length ys > 0 ==>
14751496
let xs = List.nubBy ((==) `on` fst) ys

containers-tests/tests/intmap-strictness.hs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,6 @@ pInsertLookupWithKeyValueStrict f k v m
8787
not (isBottom $ M.insertLookupWithKey (const3 1) k bottom m)
8888
| otherwise = isBottom $ M.insertLookupWithKey (apply3 f) k bottom m
8989

90-
pFilterWithKey :: Fun (Int, Int) Bool -> IMap -> Property
91-
pFilterWithKey fun m =
92-
valid m' .&&. toList m' === Prelude.filter (apply fun) (toList m)
93-
where
94-
m' = filterWithKey (apply2 fun) m
95-
96-
-- pFilterKeys :: Fun (Int, Int) Bool -> IMap -> Property
97-
-- pFilterKeys fun m =
98-
-- valid m' .&&. toList m' === Prelude.filter (apply fun) (toList m)
99-
-- where
100-
-- m' = filterKeys (apply2 fun) m
101-
102-
-- pFilter :: Fun (Int, Int) Bool -> IMap -> Property
103-
-- pFilter fun m =
104-
-- valid m' .&&. toList m' === Prelude.filter (apply fun) (toList m)
105-
-- where
106-
-- m' = filter (apply2 fun) m
107-
10890
------------------------------------------------------------------------
10991
-- test a corner case of fromAscList
11092
--
@@ -217,7 +199,6 @@ tests =
217199
pInsertLookupWithKeyValueStrict
218200
, testProperty "fromAscList is somewhat value-lazy" pFromAscListLazy
219201
, testProperty "fromAscList is somewhat value-strict" pFromAscListStrict
220-
, testProperty "filterWithKey" pFilterWithKey
221202
#if __GLASGOW_HASKELL__ >= 806
222203
, testProperty "strict foldr'" pStrictFoldr'
223204
, testProperty "strict foldl'" pStrictFoldl'

containers-tests/tests/map-properties.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ main = defaultMain $ testGroup "map-properties"
115115
, testCase "fromDistinctAscList" test_fromDistinctAscList
116116
, testCase "fromDistinctDescList" test_fromDistinctDescList
117117
, testCase "filter" test_filter
118+
, testCase "filterKeys" test_filterKeys
118119
, testCase "filterWithKey" test_filterWithKey
119120
, testCase "partition" test_partition
120121
, testCase "partitionWithKey" test_partitionWithKey

containers/src/Data/Map/Internal.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,7 @@ filter p m
28612861
-- | \(O(n)\). Filter all keys that satisfy the predicate.
28622862
--
28632863
-- > filterKeys (> 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
2864+
-- @since FIXME
28642865

28652866
filterKeys :: (k -> Bool) -> Map k a -> Map k a
28662867
filterKeys p m = filterWithKey (\k _ -> p k) m

0 commit comments

Comments
 (0)