Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strictness tests for IntMap construction #1063

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions containers-tests/containers-tests.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ test-suite map-strictness-properties

other-modules:
Utils.ArbitrarySetMap
Utils.MergeFunc
Utils.Strictness

if impl(ghc >= 8.6)
Expand All @@ -439,6 +440,8 @@ test-suite intmap-strictness-properties

other-modules:
Utils.IsUnit
Utils.MergeFunc
Utils.Strictness

if impl(ghc >= 8.6)
build-depends:
Expand Down
71 changes: 71 additions & 0 deletions containers-tests/tests/Utils/MergeFunc.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module Utils.MergeFunc
( WhenMatchedFunc(..)
, WhenMissingFunc(..)
) where

import Test.QuickCheck
import Utils.Strictness (Func, Func2, Func3)

-- k: key, x: left map value, y: right map value, z: result map value,
-- a,b: fmaps over the result value. a and b are independent variables to allow
-- for coercions involving Bot. See prop_strictMerge in map-strictness.hs for
-- an example.
data WhenMatchedFunc k x y z a b
= MaybeMatchedFunc (Func3 k x y (Maybe b))
| FmapMaybeMatchedFunc (Func a b) (Func3 k x y (Maybe z))
| MatchedFunc (Func3 k x y b)
| FmapMatchedFunc (Func a b) (Func3 k x y z)
deriving Show

instance
( CoArbitrary k, Function k
, CoArbitrary x, Function x
, CoArbitrary y, Function y
, Arbitrary z
, CoArbitrary a, Function a, Arbitrary a
, Arbitrary b
) => Arbitrary (WhenMatchedFunc k x y z a b) where
arbitrary = oneof
[ MaybeMatchedFunc <$> arbitrary
, FmapMaybeMatchedFunc <$> arbitrary <*> arbitrary
, MatchedFunc <$> arbitrary
, FmapMatchedFunc <$> arbitrary <*> arbitrary
]
shrink wmf = case wmf of
MaybeMatchedFunc fun -> MaybeMatchedFunc <$> shrink fun
FmapMaybeMatchedFunc fun2 fun1 ->
uncurry FmapMaybeMatchedFunc <$> shrink (fun2, fun1)
MatchedFunc fun -> MatchedFunc <$> shrink fun
FmapMatchedFunc fun2 fun1 ->
uncurry FmapMatchedFunc <$> shrink (fun2, fun1)

-- k: key, x: map value, y: result map value, a,b: fmaps over the result value.
-- a and b are independent variables to allow for coercions involving Bot. See
-- prop_strictMerge in map-strictness.hs for an example.
data WhenMissingFunc k x y a b
= MapMaybeMissingFunc (Func2 k x (Maybe b))
| FmapMapMaybeMissingFunc (Func a b) (Func2 k x (Maybe y))
| MapMissingFunc (Func2 k x b)
| FmapMapMissingFunc (Func a b) (Func2 k x y)
deriving Show

instance
( CoArbitrary k, Function k
, CoArbitrary x, Function x
, Arbitrary y
, CoArbitrary a, Function a, Arbitrary a
, Arbitrary b
) => Arbitrary (WhenMissingFunc k x y a b) where
arbitrary = oneof
[ MapMaybeMissingFunc <$> arbitrary
, FmapMapMaybeMissingFunc <$> arbitrary <*> arbitrary
, MapMissingFunc <$> arbitrary
, FmapMapMissingFunc <$> arbitrary <*> arbitrary
]
shrink wmf = case wmf of
MapMaybeMissingFunc fun -> MapMaybeMissingFunc <$> shrink fun
FmapMapMaybeMissingFunc fun2 fun1 ->
uncurry FmapMapMaybeMissingFunc <$> shrink (fun2, fun1)
MapMissingFunc fun -> MapMissingFunc <$> shrink fun
FmapMapMissingFunc fun2 fun1 ->
uncurry FmapMapMissingFunc <$> shrink (fun2, fun1)
Loading