MIT licensed by IOG Ledger Team
Maintained by [email protected]
This version can be pinned in stack with:antigen-0.3.1.0@sha256:41f46b318c14f4700feb8a8c4fe98d5ac758d5a8c6c51357470b7b48253fa7d4,1861

Module documentation for 0.3.1.0

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.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.