smallcheck-1.2.0: A property-based testing library

Copyright(c) Colin Runciman et al.
LicenseBSD3
MaintainerRoman Cheplyaka <roma@ro-che.info>
Safe HaskellSafe
LanguageHaskell2010

Test.SmallCheck.Series

Contents

Description

You need this module if you want to generate test values of your own types.

You'll typically need the following extensions:

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

SmallCheck itself defines data generators for all the data types used by the Prelude.

In order to generate values and functions of your own types, you need to make them instances of Serial (for values) and CoSerial (for functions). There are two main ways to do so: using Generics or writing the instances by hand.

Synopsis

Generic instances

The easiest way to create the necessary instances is to use GHC generics (available starting with GHC 7.2.1).

Here's a complete example:

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE DeriveGeneric #-}

import Test.SmallCheck.Series
import GHC.Generics

data Tree a = Null | Fork (Tree a) a (Tree a)
    deriving Generic

instance Serial m a => Serial m (Tree a)

Here we enable the DeriveGeneric extension which allows to derive Generic instance for our data type. Then we declare that Tree a is an instance of Serial, but do not provide any definitions. This causes GHC to use the default definitions that use the Generic instance.

One minor limitation of generic instances is that there's currently no way to distinguish newtypes and datatypes. Thus, newtype constructors will also count as one level of depth.

Data Generators

Writing Serial instances for application-specific types is straightforward. You need to define a series generator, typically using consN family of generic combinators where N is constructor arity.

For example:

data Tree a = Null | Fork (Tree a) a (Tree a)

instance Serial m a => Serial m (Tree a) where
  series = cons0 Null \/ cons3 Fork

For newtypes use newtypeCons instead of cons1. The difference is that cons1 is counts as one level of depth, while newtypeCons doesn't affect the depth.

newtype Light a = Light a

instance Serial m a => Serial m (Light a) where
  series = newtypeCons Light

For data types with more than 6 fields define consN as

consN f = decDepth $
  f <$> series
    <~> series
    <~> series
    <~> ...    {- series repeated N times in total -}

What does consN do, exactly?

consN has type (Serial t_1, ..., Serial t_N) => (t_1 -> ... -> t_N -> t) -> Series t.

consN f is a series which, for a given depth d > 0, produces values of the form

f x_1 ... x_N

where x_i ranges over all values of type t_i of depth up to d-1 (as defined by the series functions for t_i).

consN functions also ensure that x_i are enumerated in the breadth-first order. Thus, combinations of smaller depth come first (assuming the same is true for t_i).

If d <= 0, no values are produced.

cons0 :: a -> Series m a Source #

cons1 :: Serial m a => (a -> b) -> Series m b Source #

cons2 :: (Serial m a, Serial m b) => (a -> b -> c) -> Series m c Source #

cons3 :: (Serial m a, Serial m b, Serial m c) => (a -> b -> c -> d) -> Series m d Source #

cons4 :: (Serial m a, Serial m b, Serial m c, Serial m d) => (a -> b -> c -> d -> e) -> Series m e Source #

cons5 :: (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) => (a -> b -> c -> d -> e -> f) -> Series m f Source #

cons6 :: (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e, Serial m f) => (a -> b -> c -> d -> e -> f -> g) -> Series m g Source #

newtypeCons :: Serial m a => (a -> b) -> Series m b Source #

Same as cons1, but preserves the depth.

Function Generators

To generate functions of an application-specific argument type, make the type an instance of CoSerial.

Again there is a standard pattern, this time using the altsN combinators where again N is constructor arity. Here are Tree and Light instances:

instance CoSerial m a => CoSerial m (Tree a) where
  coseries rs =
    alts0 rs >>- \z ->
    alts3 rs >>- \f ->
    return $ \t ->
      case t of
        Null -> z
        Fork t1 x t2 -> f t1 x t2
instance CoSerial m a => CoSerial m (Light a) where
  coseries rs =
    newtypeAlts rs >>- \f ->
    return $ \l ->
      case l of
        Light x -> f x

For data types with more than 6 fields define altsN as

altsN rs = do
  rs <- fixDepth rs
  decDepthChecked
    (constM $ constM $ ... $ constM rs)
    (coseries $ coseries $ ... $ coseries rs)
    {- constM and coseries are repeated N times each -}

What does altsN do, exactly?

altsN has type (Serial t_1, ..., Serial t_N) => Series t -> Series (t_1 -> ... -> t_N -> t).

altsN s is a series which, for a given depth d, produces functions of type

t_1 -> ... -> t_N -> t

If d <= 0, these are constant functions, one for each value produced by s.

If d > 0, these functions inspect each of their arguments up to the depth d-1 (as defined by the coseries functions for the corresponding types) and return values produced by s. The depth to which the values are enumerated does not depend on the depth of inspection.

alts0 :: Series m a -> Series m a Source #

alts1 :: CoSerial m a => Series m b -> Series m (a -> b) Source #

alts2 :: (CoSerial m a, CoSerial m b) => Series m c -> Series m (a -> b -> c) Source #

alts3 :: (CoSerial m a, CoSerial m b, CoSerial m c) => Series m d -> Series m (a -> b -> c -> d) Source #

alts4 :: (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => Series m e -> Series m (a -> b -> c -> d -> e) Source #

alts5 :: (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e) => Series m f -> Series m (a -> b -> c -> d -> e -> f) Source #

alts6 :: (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e, CoSerial m f) => Series m g -> Series m (a -> b -> c -> d -> e -> f -> g) Source #

newtypeAlts :: CoSerial m a => Series m b -> Series m (a -> b) Source #

Same as alts1, but preserves the depth.

Basic definitions

type Depth = Int Source #

Maximum depth of generated test values.

For data values, it is the depth of nested constructor applications.

For functional values, it is both the depth of nested case analysis and the depth of results.

data Series m a Source #

Series is a MonadLogic action that enumerates values of a certain type, up to some depth.

The depth bound is tracked in the SC monad and can be extracted using getDepth and changed using localDepth.

To manipulate series at the lowest level you can use its Monad, MonadPlus and MonadLogic instances. This module provides some higher-level combinators which simplify creating series.

A proper Series should be monotonic with respect to the depth — i.e. localDepth (+1) s should emit all the values that s emits (and possibly some more).

It is also desirable that values of smaller depth come before the values of greater depth.

Instances
MonadTrans Series Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

lift :: Monad m => m a -> Series m a #

Monad (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

(>>=) :: Series m a -> (a -> Series m b) -> Series m b #

(>>) :: Series m a -> Series m b -> Series m b #

return :: a -> Series m a #

fail :: String -> Series m a #

Functor (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

fmap :: (a -> b) -> Series m a -> Series m b #

(<$) :: a -> Series m b -> Series m a #

Applicative (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

pure :: a -> Series m a #

(<*>) :: Series m (a -> b) -> Series m a -> Series m b #

liftA2 :: (a -> b -> c) -> Series m a -> Series m b -> Series m c #

(*>) :: Series m a -> Series m b -> Series m b #

(<*) :: Series m a -> Series m b -> Series m a #

Alternative (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

empty :: Series m a #

(<|>) :: Series m a -> Series m a -> Series m a #

some :: Series m a -> Series m [a] #

many :: Series m a -> Series m [a] #

MonadPlus (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

mzero :: Series m a #

mplus :: Series m a -> Series m a -> Series m a #

Monad m => MonadLogic (Series m) Source # 
Instance details

Defined in Test.SmallCheck.SeriesMonad

Methods

msplit :: Series m a -> Series m (Maybe (a, Series m a)) #

interleave :: Series m a -> Series m a -> Series m a #

(>>-) :: Series m a -> (a -> Series m b) -> Series m b #

ifte :: Series m a -> (a -> Series m b) -> Series m b -> Series m b #

once :: Series m a -> Series m a #

lnot :: Series m a -> Series m () #

class Monad m => Serial m a where Source #

Minimal complete definition

Nothing

Methods

series :: Series m a Source #

series :: (Generic a, GSerial m (Rep a)) => Series m a Source #

Instances
Monad m => Serial m CSUSeconds Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CUSeconds Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CTime Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CTime Source #

Monad m => Serial m CClock Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CUIntMax Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CIntMax Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CUIntPtr Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CIntPtr Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CULLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CLLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CSigAtomic Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CWchar Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CSize Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CSize Source #

Monad m => Serial m CPtrdiff Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CULong Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CLong Source #

Monad m => Serial m CUInt Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CUInt Source #

Monad m => Serial m CInt Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CInt Source #

Monad m => Serial m CUShort Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CShort Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CUChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CSChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CChar Source #

Monad m => Serial m CBool Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m CBool Source #

Monad m => Serial m CDouble Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m CFloat Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Void Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Void Source #

Monad m => Serial m Bool Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Bool Source #

Monad m => Serial m Char Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Char Source #

Monad m => Serial m Double Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Float Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Float Source #

Monad m => Serial m Word64 Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Int64 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Int64 Source #

Monad m => Serial m Word32 Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Int32 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Int32 Source #

Monad m => Serial m Word16 Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Int16 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Int16 Source #

Monad m => Serial m Word8 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Word8 Source #

Monad m => Serial m Int8 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Int8 Source #

Monad m => Serial m Word Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Word Source #

Monad m => Serial m Int Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m Int Source #

Monad m => Serial m Natural Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m Integer Source # 
Instance details

Defined in Test.SmallCheck.Series

Monad m => Serial m () Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m () Source #

Serial m a => Serial m (NonEmpty a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonEmpty a) Source #

(Num a, Ord a, Serial m a) => Serial m (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonZero a) Source #

(Num a, Ord a, Serial m a) => Serial m (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonNegative a) Source #

(Num a, Ord a, Serial m a) => Serial m (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Positive a) Source #

Serial m a => Serial m (Complex a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Complex a) Source #

Serial m a => Serial m (NonEmpty a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonEmpty a) Source #

Serial m a => Serial m [a] Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m [a] Source #

Serial m a => Serial m (Maybe a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Maybe a) Source #

(Integral i, Serial m i) => Serial m (Ratio i) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Ratio i) Source #

(CoSerial m a, Serial m b) => Serial m (a -> b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a -> b) Source #

(Serial m a, Serial m b) => Serial m (Either a b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Either a b) Source #

(Serial m a, Serial m b) => Serial m (a, b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a, b) Source #

(Serial m a, Serial m b, Serial m c) => Serial m (a, b, c) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a, b, c) Source #

(Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a, b, c, d) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a, b, c, d) Source #

(Monad m, Serial m (f (g a))) => Serial m (Compose f g a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Compose f g a) Source #

(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) => Serial m (a, b, c, d, e) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a, b, c, d, e) Source #

(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e, Serial m f) => Serial m (a, b, c, d, e, f) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (a, b, c, d, e, f) Source #

class Monad m => CoSerial m a where Source #

Minimal complete definition

Nothing

Methods

coseries :: Series m b -> Series m (a -> b) Source #

A proper coseries implementation should pass the depth unchanged to its first argument. Doing otherwise will make enumeration of curried functions non-uniform in their arguments.

coseries :: (Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a -> b) Source #

A proper coseries implementation should pass the depth unchanged to its first argument. Doing otherwise will make enumeration of curried functions non-uniform in their arguments.

Instances
Monad m => CoSerial m CSUSeconds Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CSUSeconds -> b) Source #

Monad m => CoSerial m CUSeconds Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUSeconds -> b) Source #

Monad m => CoSerial m CTime Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CTime -> b) Source #

Monad m => CoSerial m CClock Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CClock -> b) Source #

Monad m => CoSerial m CUIntMax Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUIntMax -> b) Source #

Monad m => CoSerial m CIntMax Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CIntMax -> b) Source #

Monad m => CoSerial m CUIntPtr Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUIntPtr -> b) Source #

Monad m => CoSerial m CIntPtr Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CIntPtr -> b) Source #

Monad m => CoSerial m CULLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CULLong -> b) Source #

Monad m => CoSerial m CLLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CLLong -> b) Source #

Monad m => CoSerial m CSigAtomic Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CSigAtomic -> b) Source #

Monad m => CoSerial m CWchar Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CWchar -> b) Source #

Monad m => CoSerial m CSize Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CSize -> b) Source #

Monad m => CoSerial m CPtrdiff Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CPtrdiff -> b) Source #

Monad m => CoSerial m CULong Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CULong -> b) Source #

Monad m => CoSerial m CLong Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CLong -> b) Source #

Monad m => CoSerial m CUInt Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUInt -> b) Source #

Monad m => CoSerial m CInt Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CInt -> b) Source #

Monad m => CoSerial m CUShort Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUShort -> b) Source #

Monad m => CoSerial m CShort Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CShort -> b) Source #

Monad m => CoSerial m CUChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CUChar -> b) Source #

Monad m => CoSerial m CSChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CSChar -> b) Source #

Monad m => CoSerial m CChar Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CChar -> b) Source #

Monad m => CoSerial m CBool Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CBool -> b) Source #

Monad m => CoSerial m CDouble Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CDouble -> b) Source #

Monad m => CoSerial m CFloat Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (CFloat -> b) Source #

Monad m => CoSerial m Void Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Void -> b) Source #

Monad m => CoSerial m Bool Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Bool -> b) Source #

Monad m => CoSerial m Char Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Char -> b) Source #

Monad m => CoSerial m Double Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Double -> b) Source #

Monad m => CoSerial m Float Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Float -> b) Source #

Monad m => CoSerial m Word64 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Word64 -> b) Source #

Monad m => CoSerial m Int64 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Int64 -> b) Source #

Monad m => CoSerial m Word32 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Word32 -> b) Source #

Monad m => CoSerial m Int32 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Int32 -> b) Source #

Monad m => CoSerial m Word16 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Word16 -> b) Source #

Monad m => CoSerial m Int16 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Int16 -> b) Source #

Monad m => CoSerial m Word8 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Word8 -> b) Source #

Monad m => CoSerial m Int8 Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Int8 -> b) Source #

Monad m => CoSerial m Word Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Word -> b) Source #

Monad m => CoSerial m Int Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Int -> b) Source #

Monad m => CoSerial m Natural Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Natural -> b) Source #

Monad m => CoSerial m Integer Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Integer -> b) Source #

Monad m => CoSerial m () Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (() -> b) Source #

CoSerial m a => CoSerial m (Complex a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Complex a -> b) Source #

CoSerial m a => CoSerial m (NonEmpty a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (NonEmpty a -> b) Source #

CoSerial m a => CoSerial m [a] Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m ([a] -> b) Source #

CoSerial m a => CoSerial m (Maybe a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Maybe a -> b) Source #

(Integral i, CoSerial m i) => CoSerial m (Ratio i) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Ratio i -> b) Source #

(Serial m a, CoSerial m a, Serial m b, CoSerial m b) => CoSerial m (a -> b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a -> b) -> b0) Source #

(CoSerial m a, CoSerial m b) => CoSerial m (Either a b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m (Either a b -> b0) Source #

(CoSerial m a, CoSerial m b) => CoSerial m (a, b) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a, b) -> b0) Source #

(CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a, b, c) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a, b, c) -> b0) Source #

(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a, b, c, d) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a, b, c, d) -> b0) Source #

(Monad m, CoSerial m (f (g a))) => CoSerial m (Compose f g a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b -> Series m (Compose f g a -> b) Source #

(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e) => CoSerial m (a, b, c, d, e) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a, b, c, d, e) -> b0) Source #

(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e, CoSerial m f) => CoSerial m (a, b, c, d, e, f) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

coseries :: Series m b0 -> Series m ((a, b, c, d, e, f) -> b0) Source #

Generic implementations

genericSeries :: (Monad m, Generic a, GSerial m (Rep a)) => Series m a Source #

genericCoseries :: (Monad m, Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a -> b) Source #

Convenient wrappers

newtype Positive a Source #

Positive x: guarantees that x > 0.

Constructors

Positive 

Fields

Instances
Functor Positive Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fmap :: (a -> b) -> Positive a -> Positive b #

(<$) :: a -> Positive b -> Positive a #

Foldable Positive Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fold :: Monoid m => Positive m -> m #

foldMap :: Monoid m => (a -> m) -> Positive a -> m #

foldr :: (a -> b -> b) -> b -> Positive a -> b #

foldr' :: (a -> b -> b) -> b -> Positive a -> b #

foldl :: (b -> a -> b) -> b -> Positive a -> b #

foldl' :: (b -> a -> b) -> b -> Positive a -> b #

foldr1 :: (a -> a -> a) -> Positive a -> a #

foldl1 :: (a -> a -> a) -> Positive a -> a #

toList :: Positive a -> [a] #

null :: Positive a -> Bool #

length :: Positive a -> Int #

elem :: Eq a => a -> Positive a -> Bool #

maximum :: Ord a => Positive a -> a #

minimum :: Ord a => Positive a -> a #

sum :: Num a => Positive a -> a #

product :: Num a => Positive a -> a #

Traversable Positive Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

traverse :: Applicative f => (a -> f b) -> Positive a -> f (Positive b) #

sequenceA :: Applicative f => Positive (f a) -> f (Positive a) #

mapM :: Monad m => (a -> m b) -> Positive a -> m (Positive b) #

sequence :: Monad m => Positive (m a) -> m (Positive a) #

(Num a, Ord a, Serial m a) => Serial m (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (Positive a) Source #

(Num a, Bounded a) => Bounded (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Enum a => Enum (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Eq a => Eq (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

(==) :: Positive a -> Positive a -> Bool #

(/=) :: Positive a -> Positive a -> Bool #

Integral a => Integral (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Num a => Num (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Ord a => Ord (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

compare :: Positive a -> Positive a -> Ordering #

(<) :: Positive a -> Positive a -> Bool #

(<=) :: Positive a -> Positive a -> Bool #

(>) :: Positive a -> Positive a -> Bool #

(>=) :: Positive a -> Positive a -> Bool #

max :: Positive a -> Positive a -> Positive a #

min :: Positive a -> Positive a -> Positive a #

Real a => Real (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

toRational :: Positive a -> Rational #

Show a => Show (Positive a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

showsPrec :: Int -> Positive a -> ShowS #

show :: Positive a -> String #

showList :: [Positive a] -> ShowS #

newtype NonNegative a Source #

NonNegative x: guarantees that x >= 0.

Constructors

NonNegative 

Fields

Instances
Functor NonNegative Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fmap :: (a -> b) -> NonNegative a -> NonNegative b #

(<$) :: a -> NonNegative b -> NonNegative a #

Foldable NonNegative Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fold :: Monoid m => NonNegative m -> m #

foldMap :: Monoid m => (a -> m) -> NonNegative a -> m #

foldr :: (a -> b -> b) -> b -> NonNegative a -> b #

foldr' :: (a -> b -> b) -> b -> NonNegative a -> b #

foldl :: (b -> a -> b) -> b -> NonNegative a -> b #

foldl' :: (b -> a -> b) -> b -> NonNegative a -> b #

foldr1 :: (a -> a -> a) -> NonNegative a -> a #

foldl1 :: (a -> a -> a) -> NonNegative a -> a #

toList :: NonNegative a -> [a] #

null :: NonNegative a -> Bool #

length :: NonNegative a -> Int #

elem :: Eq a => a -> NonNegative a -> Bool #

maximum :: Ord a => NonNegative a -> a #

minimum :: Ord a => NonNegative a -> a #

sum :: Num a => NonNegative a -> a #

product :: Num a => NonNegative a -> a #

Traversable NonNegative Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

traverse :: Applicative f => (a -> f b) -> NonNegative a -> f (NonNegative b) #

sequenceA :: Applicative f => NonNegative (f a) -> f (NonNegative a) #

mapM :: Monad m => (a -> m b) -> NonNegative a -> m (NonNegative b) #

sequence :: Monad m => NonNegative (m a) -> m (NonNegative a) #

(Num a, Ord a, Serial m a) => Serial m (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonNegative a) Source #

(Num a, Bounded a) => Bounded (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Enum a => Enum (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Eq a => Eq (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Integral a => Integral (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Num a => Num (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Ord a => Ord (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Real a => Real (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Show a => Show (NonNegative a) Source # 
Instance details

Defined in Test.SmallCheck.Series

newtype NonZero a Source #

NonZero x: guarantees that x /= 0.

Constructors

NonZero 

Fields

Instances
Functor NonZero Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fmap :: (a -> b) -> NonZero a -> NonZero b #

(<$) :: a -> NonZero b -> NonZero a #

Foldable NonZero Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

fold :: Monoid m => NonZero m -> m #

foldMap :: Monoid m => (a -> m) -> NonZero a -> m #

foldr :: (a -> b -> b) -> b -> NonZero a -> b #

foldr' :: (a -> b -> b) -> b -> NonZero a -> b #

foldl :: (b -> a -> b) -> b -> NonZero a -> b #

foldl' :: (b -> a -> b) -> b -> NonZero a -> b #

foldr1 :: (a -> a -> a) -> NonZero a -> a #

foldl1 :: (a -> a -> a) -> NonZero a -> a #

toList :: NonZero a -> [a] #

null :: NonZero a -> Bool #

length :: NonZero a -> Int #

elem :: Eq a => a -> NonZero a -> Bool #

maximum :: Ord a => NonZero a -> a #

minimum :: Ord a => NonZero a -> a #

sum :: Num a => NonZero a -> a #

product :: Num a => NonZero a -> a #

Traversable NonZero Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

traverse :: Applicative f => (a -> f b) -> NonZero a -> f (NonZero b) #

sequenceA :: Applicative f => NonZero (f a) -> f (NonZero a) #

mapM :: Monad m => (a -> m b) -> NonZero a -> m (NonZero b) #

sequence :: Monad m => NonZero (m a) -> m (NonZero a) #

(Num a, Ord a, Serial m a) => Serial m (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonZero a) Source #

(Eq a, Num a, Bounded a) => Bounded (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Enum a => Enum (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

succ :: NonZero a -> NonZero a #

pred :: NonZero a -> NonZero a #

toEnum :: Int -> NonZero a #

fromEnum :: NonZero a -> Int #

enumFrom :: NonZero a -> [NonZero a] #

enumFromThen :: NonZero a -> NonZero a -> [NonZero a] #

enumFromTo :: NonZero a -> NonZero a -> [NonZero a] #

enumFromThenTo :: NonZero a -> NonZero a -> NonZero a -> [NonZero a] #

Eq a => Eq (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

(==) :: NonZero a -> NonZero a -> Bool #

(/=) :: NonZero a -> NonZero a -> Bool #

Integral a => Integral (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

quot :: NonZero a -> NonZero a -> NonZero a #

rem :: NonZero a -> NonZero a -> NonZero a #

div :: NonZero a -> NonZero a -> NonZero a #

mod :: NonZero a -> NonZero a -> NonZero a #

quotRem :: NonZero a -> NonZero a -> (NonZero a, NonZero a) #

divMod :: NonZero a -> NonZero a -> (NonZero a, NonZero a) #

toInteger :: NonZero a -> Integer #

Num a => Num (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

(+) :: NonZero a -> NonZero a -> NonZero a #

(-) :: NonZero a -> NonZero a -> NonZero a #

(*) :: NonZero a -> NonZero a -> NonZero a #

negate :: NonZero a -> NonZero a #

abs :: NonZero a -> NonZero a #

signum :: NonZero a -> NonZero a #

fromInteger :: Integer -> NonZero a #

Ord a => Ord (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

compare :: NonZero a -> NonZero a -> Ordering #

(<) :: NonZero a -> NonZero a -> Bool #

(<=) :: NonZero a -> NonZero a -> Bool #

(>) :: NonZero a -> NonZero a -> Bool #

(>=) :: NonZero a -> NonZero a -> Bool #

max :: NonZero a -> NonZero a -> NonZero a #

min :: NonZero a -> NonZero a -> NonZero a #

Real a => Real (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

toRational :: NonZero a -> Rational #

Show a => Show (NonZero a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

showsPrec :: Int -> NonZero a -> ShowS #

show :: NonZero a -> String #

showList :: [NonZero a] -> ShowS #

newtype NonEmpty a Source #

NonEmpty xs: guarantees that xs is not null

Constructors

NonEmpty 

Fields

Instances
Serial m a => Serial m (NonEmpty a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

series :: Series m (NonEmpty a) Source #

Show a => Show (NonEmpty a) Source # 
Instance details

Defined in Test.SmallCheck.Series

Methods

showsPrec :: Int -> NonEmpty a -> ShowS #

show :: NonEmpty a -> String #

showList :: [NonEmpty a] -> ShowS #

Other useful definitions

(\/) :: Monad m => Series m a -> Series m a -> Series m a infixr 7 Source #

Sum (union) of series

(><) :: Monad m => Series m a -> Series m b -> Series m (a, b) infixr 8 Source #

Product of series

(<~>) :: Monad m => Series m (a -> b) -> Series m a -> Series m b infixl 4 Source #

Fair version of ap and <*>

(>>-) :: MonadLogic m => m a -> (a -> m b) -> m b infixl 1 #

Fair conjunction. Similarly to the previous function, consider the distributivity law for MonadPlus:

(mplus a b) >>= k = (a >>= k) `mplus` (b >>= k)

If 'a >>= k' can backtrack arbitrarily many tmes, (b >>= k) may never be considered. (>>-) takes similar care to consider both branches of a disjunctive computation.

localDepth :: (Depth -> Depth) -> Series m a -> Series m a Source #

Run a series with a modified depth

decDepth :: Series m a -> Series m a Source #

Run a Series with the depth decreased by 1.

If the current depth is less or equal to 0, the result is mzero.

getDepth :: Series m Depth Source #

Query the current depth

generate :: (Depth -> [a]) -> Series m a Source #

A simple series specified by a function from depth to the list of values up to that depth.

limit :: forall m a. Monad m => Int -> Series m a -> Series m a Source #

Limit a Series to its first n elements

listSeries :: Serial Identity a => Depth -> [a] Source #

Given a depth, return the list of values generated by a Serial instance.

Example, list all integers up to depth 1:

  • listSeries 1 :: [Int]   -- returns [0,1,-1]

list :: Depth -> Series Identity a -> [a] Source #

Return the list of values generated by a Series. Useful for debugging Serial instances.

Examples:

  • list 3 series :: [Int]                  -- returns [0,1,-1,2,-2,3,-3]
  • list 3 (series :: Series Identity Int)  -- returns [0,1,-1,2,-2,3,-3]
  • list 2 series :: [[Bool]]               -- returns [[],[True],[False]]

The first two are equivalent. The second has a more explicit type binding.

listM :: Monad m => Depth -> Series m a -> m [a] Source #

Monadic version of list

fixDepth :: Series m a -> Series m (Series m a) Source #

Fix the depth of a series at the current level. The resulting series will no longer depend on the "ambient" depth.

decDepthChecked :: Series m a -> Series m a -> Series m a Source #

If the current depth is 0, evaluate the first argument. Otherwise, evaluate the second argument with decremented depth.

constM :: Monad m => m b -> m (a -> b) Source #

Orphan instances

(Serial Identity a, Show a, Show b) => Show (a -> b) Source # 
Instance details

Methods

showsPrec :: Int -> (a -> b) -> ShowS #

show :: (a -> b) -> String #

showList :: [a -> b] -> ShowS #