-
Notifications
You must be signed in to change notification settings - Fork 0
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 #15 from input-output-hk/jdral/diff-containers-bri…
…ng-back-unsafe-constructors `diff-containers`: Bring back unsafe constructors
- Loading branch information
Showing
4 changed files
with
166 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE GeneralisedNewtypeDeriving #-} | ||
|
||
module Test.Util (OftenSmall (..)) where | ||
|
||
import Test.QuickCheck | ||
|
||
-- | See the @'Arbitrary'@ instance for this type. | ||
newtype OftenSmall a = OftenSmall a | ||
deriving newtype (Show, Eq, Ord) | ||
|
||
-- | This instance will generate a small @a@ with high probability, and it will | ||
-- defer to @a@'s generator with a low probability. Shrinking is deferred to | ||
-- @a@'s shrinker. | ||
-- | ||
-- Generating @a@'s in a small range can sometimes be essential for hitting | ||
-- interesting cases in property tests. See "Test.Data.Map.Diff.Strict" for | ||
-- examples. We defer to @a@'s generator with low probability to diversify the | ||
-- test cases we hit. | ||
instance (Arbitrary a, Integral a) => Arbitrary (OftenSmall a) where | ||
arbitrary = frequency [ | ||
(10, OftenSmall . fromIntegral <$> chooseInt (-5, 5)) | ||
, (1, OftenSmall <$> arbitrary) | ||
] | ||
shrink (OftenSmall x) = OftenSmall <$> shrink x |