-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from IntersectMBO/jdral/test-codec-generators…
…-shrinkers Test generators and shrinkers for snapshot metadata
- Loading branch information
Showing
8 changed files
with
147 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Util.Arbitrary ( | ||
prop_arbitraryAndShrinkPreserveInvariant | ||
, prop_forAllArbitraryAndShrinkPreserveInvariant | ||
, deepseqInvariant | ||
) where | ||
|
||
import Control.DeepSeq (NFData, deepseq) | ||
import Test.QuickCheck | ||
import Test.Tasty (TestTree) | ||
import Test.Tasty.QuickCheck (testProperty) | ||
|
||
prop_arbitraryAndShrinkPreserveInvariant :: | ||
forall a. (Arbitrary a, Show a) => (a -> Bool) -> [TestTree] | ||
prop_arbitraryAndShrinkPreserveInvariant = | ||
prop_forAllArbitraryAndShrinkPreserveInvariant arbitrary shrink | ||
|
||
prop_forAllArbitraryAndShrinkPreserveInvariant :: | ||
forall a. Show a => Gen a -> (a -> [a]) -> (a -> Bool) -> [TestTree] | ||
prop_forAllArbitraryAndShrinkPreserveInvariant gen shr inv = | ||
[ testProperty "Arbitrary satisfies invariant" $ | ||
property $ forAllShrink gen shr inv | ||
, testProperty "Shrinking satisfies invariant" $ | ||
property $ forAll gen $ \x -> | ||
case shr x of | ||
[] -> label "no shrinks" $ property True | ||
xs -> forAll (growingElements xs) inv | ||
] | ||
|
||
-- | Trivial invariant, but checks that the value is finite | ||
deepseqInvariant :: NFData a => a -> Bool | ||
deepseqInvariant x = x `deepseq` True |