|
2 | 2 | import qualified Data.IntSet as IntSet |
3 | 3 | import Data.List (nub, sort, sortBy) |
4 | 4 | import qualified Data.List as List |
5 | | -import Data.Maybe |
| 5 | +import Data.Maybe (isJust, fromJust) |
| 6 | +import qualified Data.Maybe as Maybe |
6 | 7 | import Data.Set |
7 | 8 | import Data.Set.Internal (link, merge) |
8 | 9 | import Prelude hiding (lookup, null, map, filter, foldr, foldl, foldl', all, take, drop, splitAt) |
@@ -98,6 +99,7 @@ main = defaultMain $ testGroup "set-properties" |
98 | 99 | , testProperty "prop_splitRoot" prop_splitRoot |
99 | 100 | , testProperty "prop_partition" prop_partition |
100 | 101 | , testProperty "prop_filter" prop_filter |
| 102 | + , testProperty "prop_mapMaybe" prop_mapMaybe |
101 | 103 | , testProperty "takeWhileAntitone" prop_takeWhileAntitone |
102 | 104 | , testProperty "dropWhileAntitone" prop_dropWhileAntitone |
103 | 105 | , testProperty "spanAntitone" prop_spanAntitone |
@@ -618,6 +620,12 @@ prop_partition s i = case partition odd s of |
618 | 620 | prop_filter :: Set Int -> Int -> Bool |
619 | 621 | prop_filter s i = partition odd s == (filter odd s, filter even s) |
620 | 622 |
|
| 623 | +prop_mapMaybe :: Fun Int (Maybe Int) -> Set Int -> Property |
| 624 | +prop_mapMaybe f s = |
| 625 | + let mapped = mapMaybe (applyFun f) s |
| 626 | + in valid mapped .&&. |
| 627 | + mapped === fromList (Maybe.mapMaybe (applyFun f) $ toList s) |
| 628 | + |
621 | 629 | prop_take :: Int -> Set Int -> Property |
622 | 630 | prop_take n xs = valid taken .&&. |
623 | 631 | taken === fromDistinctAscList (List.take n (toList xs)) |
|
0 commit comments