ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Util.QuickCheck

Description

QuickCheck utilities

Synopsis

Generic QuickCheck utilities

checkGenerator ∷ (Arbitrary a, Show a) ⇒ (a → Property) → Property Source #

Test the generator

Uses explicit forAll as we don't want to assume a correct shrinker.

checkInvariant ∷ (a → Except String ()) → a → Property Source #

Check invariant

checkShrinker ∷ ∀ a. (Arbitrary a, Show a) ⇒ (a → Property) → Property Source #

Test the shrinker

Comparison functions

expectRight ∷ (Show a, Show b, Eq b) ⇒ b → Either a b → Property Source #

Check that we have the expected Right value

expectRight b ab is roughly equivalent to Right b === ab, but avoids an equality constraint on a.

ge ∷ (Ord a, Show a) ⇒ a → a → Property infix 4 Source #

Like >=, but prints a counterexample when it fails.

gt ∷ (Ord a, Show a) ⇒ a → a → Property infix 4 Source #

Like >, but prints a counterexample when it fails.

le ∷ (Ord a, Show a) ⇒ a → a → Property infix 4 Source #

Like <=, but prints a counterexample when it fails.

lt ∷ (Ord a, Show a) ⇒ a → a → Property infix 4 Source #

Like <, but prints a counterexample when it fails.

strictlyIncreasing ∷ ∀ a. (Show a, Ord a) ⇒ [a] → Property Source #

Comparing maps

isSubmapOfBy ∷ (Ord k, Show k, Show a, Show b) ⇒ (a → b → Property) → Map k a → Map k b → Property Source #

Improved variants

elementsHasCallStack ⇒ [a] → Gen a Source #

Generates one of the given values. The input list must be non-empty.

NOTE unlike the standard elements, this variant has a HasCallStack constraint, which makes debugging the error much easier.

(=:=) ∷ (Eq a, Condense a) ⇒ a → a → Property infix 4 Source #

Like ===, but uses Condense instead of Show when it fails.

SOP

cshrinkNP ∷ ∀ proxy c f g xs. All c xs ⇒ proxy c → (∀ a. c a ⇒ f a → g a) → (∀ a. c a ⇒ f a → [g a]) → NP f xs → [NP g xs] Source #

shrinkNP ∷ (∀ a. f a → g a) → (∀ a. f a → [g a]) → NP f xs → [NP g xs] Source #

Convenience

collectsShow a ⇒ [a] → PropertyProperty Source #

forAllGenRunShrinkCheckTestable prop ⇒ Gen input → (input → output) → (input → output → [input]) → (input → output → prop) → Property Source #

Explicit quantification using the “gen-run-shrink-check” pattern.

Instead of the usual two stages where one generates an input and then checks the property for that input, we rely on three stages: one generates an input, then transforms it into an output, and then checks the output.

When adding a shrinker to the mix, we can allow it to inspect the output value as well, which increases its expressivity. This makes sense if the “run” phase is particularly expensive.

impliesTestable prop ⇒ Bool → prop → Property infixr 0 Source #

QuickCheck's ==> discards the test if p1 fails; this is sometimes not what we want, for example if we have other properties that do not depend on p1 being true.

Typeclass laws

prop_lawfulEqAndTotalOrd ∷ ∀ a. (Show a, Ord a) ⇒ a → a → a → Property Source #