foundation-0.0.30: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | Foundation maintainers
Safe Haskell | Safe-Inferred
Language | Haskell2010

Foundation.Check

Contents

- Property
- Check Plan

Description

An implementation of a test framework and property expression & testing

Synopsis

- data Gen a
- class Arbitrary a where
  - arbitrary :: Gen a
- oneof :: NonEmpty [Gen a] -> Gen a
- elements :: NonEmpty [a] -> Gen a
- frequency :: NonEmpty [(Word, Gen a)] -> Gen a
- between :: (Word, Word) -> Gen Word
- data Test where
  - Unit :: String -> IO () -> Test
  - Property :: IsProperty prop => String -> prop -> Test
  - Group :: String -> [Test] -> Test
  - CheckPlan :: String -> Check () -> Test
- testName :: Test -> String
- data PropertyCheck
- data Property = Prop {
  - unProp :: Gen PropertyTestArg
  }
- class IsProperty p where
  - property :: p -> Property
- (===) :: (Show a, Eq a, Typeable a) => a -> a -> PropertyCheck
- propertyCompare :: (Show a, Typeable a) => String -> (a -> a -> Bool) -> a -> a -> PropertyCheck
- propertyCompareWith :: String -> (a -> a -> Bool) -> (a -> String) -> a -> a -> PropertyCheck
- propertyAnd :: PropertyCheck -> PropertyCheck -> PropertyCheck
- propertyFail :: String -> PropertyCheck
- forAll :: (Show a, IsProperty prop) => Gen a -> (a -> prop) -> Property
- data Check a
- validate :: IsProperty prop => String -> prop -> Check ()
- pick :: String -> IO a -> Check a
- iterateProperty :: CountOf TestResult -> GenParams -> (Word64 -> GenRng) -> Property -> IO (PropertyResult, CountOf TestResult)

# Documentation

data Gen a Source #

Generator monad

#### Instances

Instances details

Applicative Gen Source # |
Instance details Defined in Foundation.Check.Gen Methods pure :: a -> Gen a Source # (<*>) :: Gen (a -> b) -> Gen a -> Gen b Source # liftA2 :: (a -> b -> c) -> Gen a -> Gen b -> Gen c Source # (*>) :: Gen a -> Gen b -> Gen b Source # (<*) :: Gen a -> Gen b -> Gen a Source #
Functor Gen Source # |
Instance details Defined in Foundation.Check.Gen Methods fmap :: (a -> b) -> Gen a -> Gen b Source # (<$) :: a -> Gen b -> Gen a Source #
Monad Gen Source # |
Instance details Defined in Foundation.Check.Gen Methods (>>=) :: Gen a -> (a -> Gen b) -> Gen b Source # (>>) :: Gen a -> Gen b -> Gen b Source # return :: a -> Gen a Source #

class Arbitrary a where Source #

How to generate an arbitrary value for `a`

Methods

arbitrary :: Gen a Source #

#### Instances

Instances details

Arbitrary Int16 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int16 Source #
Arbitrary Int32 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int32 Source #
Arbitrary Int64 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int64 Source #
Arbitrary Int8 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int8 Source #
Arbitrary Word16 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word16 Source #
Arbitrary Word32 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word32 Source #
Arbitrary Word64 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word64 Source #
Arbitrary Word8 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word8 Source #
Arbitrary AsciiString Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen AsciiString Source #
Arbitrary Char7 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Char7 Source #
Arbitrary Word128 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word128 Source #
Arbitrary Word256 Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word256 Source #
Arbitrary String Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen String Source #
Arbitrary Field Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods arbitrary :: Gen Field Source #
Arbitrary Integer Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Integer Source #
Arbitrary Natural Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Natural Source #
Arbitrary Bool Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Bool Source #
Arbitrary Char Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Char Source #
Arbitrary Double Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Double Source #
Arbitrary Float Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Float Source #
Arbitrary Int Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int Source #
Arbitrary Word Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word Source #
KnownNat n => Arbitrary (Zn n) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Zn n) Source #
(NatWithinBound Word64 n, KnownNat n) => Arbitrary (Zn64 n) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Zn64 n) Source #
Arbitrary (CountOf ty) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (CountOf ty) Source #
Arbitrary a => Arbitrary (Maybe a) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Maybe a) Source #
Arbitrary a => Arbitrary [a] Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen [a] Source #
(Arbitrary l, Arbitrary r) => Arbitrary (Either l r) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Either l r) Source #
(Arbitrary a, KnownNat n, NatWithinBound Int n) => Arbitrary (ListN n a) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (ListN n a) Source #
(Arbitrary a, Arbitrary b) => Arbitrary (a, b) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b) Source #
(Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (a, b, c) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c) Source #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => Arbitrary (a, b, c, d) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d) Source #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e) => Arbitrary (a, b, c, d, e) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d, e) Source #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, Arbitrary f) => Arbitrary (a, b, c, d, e, f) Source # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d, e, f) Source #

oneof :: NonEmpty [Gen a] -> Gen a Source #

elements :: NonEmpty [a] -> Gen a Source #

frequency :: NonEmpty [(Word, Gen a)] -> Gen a Source #

Call one of the generator weighted

between :: (Word, Word) -> Gen Word Source #

data Test where Source #

different type of tests supported

Constructors

Unit :: String -> IO () -> Test |
Property :: IsProperty prop => String -> prop -> Test |
Group :: String -> [Test] -> Test |
CheckPlan :: String -> Check () -> Test |

testName :: Test -> String Source #

Name of a test

# Property

data PropertyCheck Source #

The type of check this test did for a property

#### Instances

Instances details

IsProperty PropertyCheck Source # |
Instance details Defined in Foundation.Check.Property Methods property :: PropertyCheck -> Property Source #

data Property Source #

Constructors

Prop |

Fields

- unProp :: Gen PropertyTestArg

#### Instances

Instances details

IsProperty Property Source # |
Instance details Defined in Foundation.Check.Property Methods property :: Property -> Property Source #

class IsProperty p where Source #

Methods

property :: p -> Property Source #

#### Instances

Instances details

IsProperty Property Source # |
Instance details Defined in Foundation.Check.Property Methods property :: Property -> Property Source #
IsProperty PropertyCheck Source # |
Instance details Defined in Foundation.Check.Property Methods property :: PropertyCheck -> Property Source #
IsProperty Bool Source # |
Instance details Defined in Foundation.Check.Property Methods property :: Bool -> Property Source #
(Show a, Arbitrary a, IsProperty prop) => IsProperty (a -> prop) Source # |
Instance details Defined in Foundation.Check.Property Methods property :: (a -> prop) -> Property Source #
IsProperty (String, Bool) Source # |
Instance details Defined in Foundation.Check.Property Methods property :: (String, Bool) -> Property Source #

(===) :: (Show a, Eq a, Typeable a) => a -> a -> PropertyCheck infix 4 Source #

A property that check for equality of its 2 members.

propertyCompare Source #

Arguments

:: (Show a, Typeable a) |
=> String | name of the function used for comparaison, e.g. (<)
-> (a -> a -> Bool) | function used for value comparaison
-> a | value left of the operator
-> a | value right of the operator
-> PropertyCheck |

A property that check for a specific comparaison of its 2 members.

This is equivalent to `===` but with `compare`

propertyCompareWith Source #

Arguments

:: String | name of the function used for comparaison, e.g. (<)
-> (a -> a -> Bool) | function used for value comparaison
-> (a -> String) | function used to pretty print the values
-> a | value left of the operator
-> a | value right of the operator
-> PropertyCheck |

A property that check for a specific comparaison of its 2 members.

This is equivalent to `===` but with `compare` and a given method to pretty print the values.

propertyAnd :: PropertyCheck -> PropertyCheck -> PropertyCheck Source #

A conjuctive property composed of 2 properties that need to pass

propertyFail :: String -> PropertyCheck Source #

forAll :: (Show a, IsProperty prop) => Gen a -> (a -> prop) -> Property Source #

Running a generator for a specific type under a property

# Check Plan

data Check a Source #

#### Instances

Instances details

Applicative Check Source # |
Instance details Defined in Foundation.Check.Types Methods pure :: a -> Check a Source # (<*>) :: Check (a -> b) -> Check a -> Check b Source # liftA2 :: (a -> b -> c) -> Check a -> Check b -> Check c Source # (*>) :: Check a -> Check b -> Check b Source # (<*) :: Check a -> Check b -> Check a Source #
Functor Check Source # |
Instance details Defined in Foundation.Check.Types Methods fmap :: (a -> b) -> Check a -> Check b Source # (<$) :: a -> Check b -> Check a Source #
Monad Check Source # |
Instance details Defined in Foundation.Check.Types Methods (>>=) :: Check a -> (a -> Check b) -> Check b Source # (>>) :: Check a -> Check b -> Check b Source # return :: a -> Check a Source #
MonadState Check Source # |
Instance details Defined in Foundation.Check.Types Associated Types type State Check Source # Methods withState :: (State Check -> (a, State Check)) -> Check a Source #
type State Check Source # |
Instance details Defined in Foundation.Check.Types type State Check

validate :: IsProperty prop => String -> prop -> Check () Source #

pick :: String -> IO a -> Check a Source #

iterateProperty :: CountOf TestResult -> GenParams -> (Word64 -> GenRng) -> Property -> IO (PropertyResult, CountOf TestResult) Source #