License | MIT |
---|---|
Maintainer | mail@doisinkidney.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module provides functions which can be quickly converted into smallcheck or QuickCheck-like properties. The functions are of the form:
a -> Either String String
where the left case is failure of the test, and the right case is success.
For smallcheck, this function can be used directly as a property:
smallCheck 10 (plusId :: UnaryLaws Integer)
(the typealias is provided as well)
For QuickCheck, you might want to provide an instance like this:
instance Testable (Either String String) where property = either (`counterexample` False) (const (property True))
And then testing is as simple as:
quickCheck (plusAssoc :: TernaryLaws Integer)
There are also functions provided to test multiple laws at once. Putting all of
this together, writing a test for all the semiring laws for, say, Integer
looks like this:
quickCheck (unaryLaws :: UnaryLaws Integer) quickCheck (binaryLaws :: BinaryLaws Integer) quickCheck (ternaryLaws :: TernaryLaws Integer)
- type UnaryLaws a = a -> Either String String
- type BinaryLaws a = a -> a -> Either String String
- type TernaryLaws a = a -> a -> a -> Either String String
- plusId :: (Eq a, Semiring a, Show a) => a -> Either String String
- mulId :: (Eq a, Semiring a, Show a) => a -> Either String String
- annihilateL :: (Eq a, Semiring a, Show a) => a -> Either String String
- annihilateR :: (Eq a, Semiring a, Show a) => a -> Either String String
- unaryLaws :: (Eq a, Semiring a, Show a) => a -> Either String String
- plusComm :: (Eq a, Semiring a, Show a) => a -> a -> Either String String
- binaryLaws :: (Eq a, Semiring a, Show a) => a -> a -> Either String String
- plusAssoc :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- mulAssoc :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- mulDistribL :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- mulDistribR :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- ternaryLaws :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- nearUnaryLaws :: (Eq a, Semiring a, Show a) => a -> Either String String
- nearTernaryLaws :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String
- starLaw :: (Eq a, StarSemiring a, Show a) => a -> Either String String
- plusLaw :: (Eq a, StarSemiring a, Show a) => a -> Either String String
- starLaws :: (Eq a, StarSemiring a, Show a) => a -> Either String String
- zeroLaw :: (Eq a, DetectableZero a, Show a) => a -> Either String String
- zeroIsZero :: (DetectableZero a, Show a) => f a -> Either String String
- zeroLaws :: (DetectableZero a, Show a, Eq a) => a -> Either String String
- ordMulLaw :: (Ord a, Semiring a, Show a) => a -> a -> a -> Either String String
- ordAddLaw :: (Ord a, Semiring a, Show a) => a -> a -> a -> Either String String
- ordLaws :: (Ord a, Semiring a, Show a) => a -> a -> a -> Either String String
Type Aliases
type UnaryLaws a = a -> Either String String Source #
Typealias for unary laws. Can be used like so:
smallCheck 10 (unaryLaws :: UnaryLaws Int)
type BinaryLaws a = a -> a -> Either String String Source #
Typealias for binary laws. Can be used like so:
smallCheck 8 (binaryLaws :: BinaryLaws Int)
type TernaryLaws a = a -> a -> a -> Either String String Source #
Typealias for ternary laws. Can be used like so:
smallCheck 6 (ternaryLaws :: TernaryLaws Int)
Semiring Laws
Unary
unaryLaws :: (Eq a, Semiring a, Show a) => a -> Either String String Source #
A test for all three unary laws for Semiring
s (plusId
, mulId
,
annihilateL
, and annihilateR
).
Binary
Ternary
ternaryLaws :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String Source #
A test for all of the ternary laws for Semiring
s (plusAssoc
, mulAssoc
,
mulDistribL
, mulDistribR
).
Near-semiring laws
Unary
nearUnaryLaws :: (Eq a, Semiring a, Show a) => a -> Either String String Source #
A test for the unary laws for near-Semiring
s (plusId
, mulId
, and
annihilateR
).
Ternary
nearTernaryLaws :: (Eq a, Semiring a, Show a) => a -> a -> a -> Either String String Source #
A test for all of the ternary laws for near-Semiring
s (plusAssoc
,
mulAssoc
, mulDistribR
).
StarSemiring Laws
Unary
plusLaw :: (Eq a, StarSemiring a, Show a) => a -> Either String String Source #
The plus law for StarSemiring
s.
plus
x = x<.>
star
x
starLaws :: (Eq a, StarSemiring a, Show a) => a -> Either String String Source #
The laws for StarSemiring
s (starLaw
, plusLaw
).
DetectableZero Laws
Unary
zeroIsZero :: (DetectableZero a, Show a) => f a -> Either String String Source #
zeroLaws :: (DetectableZero a, Show a, Eq a) => a -> Either String String Source #
The laws for DetectableZero
Semiring
s (zeroLaw
, zeroIsZero
).