Skip to content

Commit

Permalink
Add property tests for genNonEmptyDisjointMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed May 7, 2024
1 parent 247442a commit e24a05b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/test-utils/test/Test/QuickCheck/ExtraSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import Test.QuickCheck
)
import Test.QuickCheck.Extra
( Pretty (..)
, genNonEmptyDisjointMap
, genNonEmptyDisjointSet
, genShrinkSequence
, genericRoundRobinShrink
Expand Down Expand Up @@ -206,6 +207,15 @@ spec = describe "Test.QuickCheck.ExtraSpec" $ do

describe "Generating and shrinking associative maps" $ do

describe "Generation" $ do

it "prop_genNonEmptyDisjointMap_disjoint" $
prop_genNonEmptyDisjointMap_disjoint
@Int @Int & property
it "prop_genNonEmptyDisjointMap_nonEmpty" $
prop_genNonEmptyDisjointMap_nonEmpty
@Int @Int & property

describe "Shrinking" $ do

it "prop_shrinkMapToSubmaps_all_isProperSubmapOf" $
Expand Down Expand Up @@ -616,6 +626,36 @@ prop_genNonEmptyDisjointSet_nonEmpty set1 =
"Set.size set1 >= 10 && Set.size set2 >= 10"
& checkCoverage

--------------------------------------------------------------------------------
-- Generating maps
--------------------------------------------------------------------------------

prop_genNonEmptyDisjointMap_disjoint
:: (Arbitrary k, Show k, Ord k)
=> (Arbitrary v, Show v, Eq v)
=> Map k v
-> Property
prop_genNonEmptyDisjointMap_disjoint map1 =
forAll (genNonEmptyDisjointMap arbitrary arbitrary map1) $ \map2 ->
Map.intersectionWith (,) map1 map2 === Map.empty
& cover 10
(Map.size map1 >= 10 && Map.size map2 >= 10)
"Map.size map1 >= 10 && Map.size map2 >= 10"
& checkCoverage

prop_genNonEmptyDisjointMap_nonEmpty
:: (Arbitrary k, Show k, Ord k)
=> (Arbitrary v, Show v, Eq v)
=> Map k v
-> Property
prop_genNonEmptyDisjointMap_nonEmpty map1 =
forAll (genNonEmptyDisjointMap arbitrary arbitrary map1) $ \map2 ->
Map.size map2 =/= 0
& cover 10
(Map.size map1 >= 10 && Map.size map2 >= 10)
"Map.size map1 >= 10 && Map.size map2 >= 10"
& checkCoverage

--------------------------------------------------------------------------------
-- Selecting map entries (one at a time)
--------------------------------------------------------------------------------
Expand Down

0 comments on commit e24a05b

Please sign in to comment.