antigen

Fault injection for QuickCheck

Stackage Nightly 2026-04-09:0.4.0.0
Latest on Hackage:0.4.0.0

See all snapshots antigen appears in

MIT licensed by IOG Ledger Team
Maintained by [email protected]
This version can be pinned in stack with:antigen-0.4.0.0@sha256:3061b142657ed523cbfc3f9462261e039d896e541539f82cddb206e770e73ede,2002

Module documentation for 0.4.0.0

Used by 1 package in nightly-2026-04-09(full list with versions):

AntiGen

AntiGen lets you write QuickCheck generators that can also be negated to generate negative examples. It can be used as a drop-in replacement for Gen.

Example

-- Returns an integer `n` (such that 0 <= n <= 5) and a string of length `n` consisting only of characters 'a'
antiGenLengthString :: AntiGen (Int, String)
antiGenLengthString = do
  -- Use (|!) to provide both a positive and a negative generator
  l <- choose (0, 5) |! choose (6, 10)
  s <-
    pure (replicate l 'a') |! do
      NonNegative l' <- suchThat arbitrary $ \(NonNegative x) -> x /= l
      pure $ replicate l' 'b'
  pure (l, s)

To generate a positive example, use runAntiGen

ghci> generate (runAntiGen antiGenLengthString)
(1, "a")

To generate a negative example, use zapAntiGen

ghci> generate (zapAntiGen 1 antiGenLengthString)
(6, "aaaaaa") -- length is too long
ghci> generate (zapAntiGen 1 antiGenLengthString)
(2, "bbbb") -- length of the string does not match up with the integer

Notice that there is exactly one mistake in the example above. The first argument of zapAntiGen can be used to specify how many negations the generator should introduce.

ghci> generate $ zapAntiGen 2 antiGenLengthString
(10,"b") -- both values are wrong

Changes

Revision history for antigen

0.4.0.0

  • Add antiSamePair
  • Add faultyNumRange
  • Add hierarchical annotations with withAnnotation and (#!)
  • Add ZapResult with annotation tracking
  • Add zapAntiGenResult to get full zap metadata
  • Add prettyZapResult for displaying zap results
  • Add weighted decision points with scaleWeight and reweigh
  • Add replicateMNorm for normalized list generation
  • Remove tryZapAntiGen (use zapAntiGenResult instead)

0.3.1.0

  • Add tryZapAntiGen

0.3.0.0

  • Rename fickle* to faulty*
  • Add antiJust, antiNonEmpty, antiDistinctPair

0.2.0.0

  • Rename antiNum and antiBool to fickleNum and fickleBool
  • Rename antiTry and antiTryGen to fickleTry and fickleTryGen

0.1.2.0

  • Fixed sized and resize implementations for AntiGen
  • Added utility functions:
    • (||!)
    • antiNum
    • antiBool
    • antiChoose
    • antiChooseBounded
    • antiTry
    • antiTryGen
    • antiPositive
    • antiNonPositive
    • antiNegative
    • antiNonNegative

0.1.0.0

  • First version. Released on an unsuspecting world.