| Copyright | (c) 2015-2018 Rudy Matela |
|---|---|
| License | 3-Clause BSD (see the file LICENSE) |
| Maintainer | Rudy Matela <rudy@matela.com.br> |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.LeanCheck.Utils.Types
Contents
Description
This module is part of LeanCheck, a simple enumerative property-based testing library.
Types to aid in property-based testing.
Synopsis
- newtype Int1 = Int1 {}
- newtype Int2 = Int2 {}
- newtype Int3 = Int3 {}
- newtype Int4 = Int4 {}
- newtype Word1 = Word1 {}
- newtype Word2 = Word2 {}
- newtype Word3 = Word3 {}
- newtype Word4 = Word4 {}
- newtype Nat = Nat {}
- newtype Nat1 = Nat1 {}
- newtype Nat2 = Nat2 {}
- newtype Nat3 = Nat3 {}
- newtype Nat4 = Nat4 {}
- newtype Nat5 = Nat5 {}
- newtype Nat6 = Nat6 {}
- newtype Nat7 = Nat7 {}
- newtype Natural = Natural {}
- type UInt1 = Word1
- type UInt2 = Word2
- type UInt3 = Word3
- type UInt4 = Word4
- newtype X a = X {
- unX :: a
- newtype Xs a = Xs [a]
- newtype NoDup a = NoDup [a]
- newtype Bag a = Bag [a]
- newtype Set a = Set [a]
- newtype Map a b = Map [(a, b)]
- data Space = Space {}
- data Lower = Lower {}
- data Upper = Upper {}
- data Alpha = Alpha {}
- data Digit = Digit {}
- data AlphaNum = AlphaNum {
- unAlphaNum :: Char
- data Letter = Letter {}
- data Spaces = Spaces {}
- data Lowers = Lowers {}
- data Uppers = Uppers {}
- data Alphas = Alphas {}
- data Digits = Digits {}
- data AlphaNums = AlphaNums {}
- data Letters = Letters {}
Integer types
Small-width integer types to aid in property-based testing. Sometimes it is useful to limit the possibilities of enumerated values when testing polymorphic functions, these types allow that.
The signed integer types IntN are of limited bit width N
bounded by -2^(N-1) to 2^(N-1)-1.
The unsigned integer types WordN are of limited bit width N
bounded by 0 to 2^N-1.
Operations are closed and modulo 2^N. e.g.:
maxBound + 1 = minBound read "2" = -2 :: Int2 abs minBound = minBound negate n = 2^N - n :: WordN
Single-bit signed integers: -1, 0
Two-bit signed integers: -2, -1, 0, 1
Three-bit signed integers: -4, -3, -2, -1, 0, 1, 2, 3
Four-bit signed integers: -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7
Single-bit unsigned integer: 0, 1
Instances
| Bounded Word1 # | |
| Enum Word1 # | |
Defined in Test.LeanCheck.Utils.Types | |
| Eq Word1 # | |
| Integral Word1 # | |
| Num Word1 # | |
| Ord Word1 # | |
| Read Word1 # | |
| Real Word1 # | |
Defined in Test.LeanCheck.Utils.Types Methods toRational :: Word1 -> Rational # | |
| Show Word1 # | |
| Listable Word1 # | |
| ShowFunction Word1 # | |
Defined in Test.LeanCheck.Function.ShowFunction | |
Two-bit unsigned integers: 0, 1, 2, 3
Instances
| Bounded Word2 # | |
| Enum Word2 # | |
Defined in Test.LeanCheck.Utils.Types | |
| Eq Word2 # | |
| Integral Word2 # | |
| Num Word2 # | |
| Ord Word2 # | |
| Read Word2 # | |
| Real Word2 # | |
Defined in Test.LeanCheck.Utils.Types Methods toRational :: Word2 -> Rational # | |
| Show Word2 # | |
| Listable Word2 # | |
| ShowFunction Word2 # | |
Defined in Test.LeanCheck.Function.ShowFunction | |
Three-bit unsigned integers: 0, 1, 2, 3, 4, 5, 6, 7
Instances
| Bounded Word3 # | |
| Enum Word3 # | |
Defined in Test.LeanCheck.Utils.Types | |
| Eq Word3 # | |
| Integral Word3 # | |
| Num Word3 # | |
| Ord Word3 # | |
| Read Word3 # | |
| Real Word3 # | |
Defined in Test.LeanCheck.Utils.Types Methods toRational :: Word3 -> Rational # | |
| Show Word3 # | |
| Listable Word3 # | |
| ShowFunction Word3 # | |
Defined in Test.LeanCheck.Function.ShowFunction | |
Four-bit unsigned integers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
Instances
| Bounded Word4 # | |
| Enum Word4 # | |
Defined in Test.LeanCheck.Utils.Types | |
| Eq Word4 # | |
| Integral Word4 # | |
| Num Word4 # | |
| Ord Word4 # | |
| Read Word4 # | |
| Real Word4 # | |
Defined in Test.LeanCheck.Utils.Types Methods toRational :: Word4 -> Rational # | |
| Show Word4 # | |
| Listable Word4 # | |
| ShowFunction Word4 # | |
Defined in Test.LeanCheck.Function.ShowFunction | |
Natural numbers (including 0): 0, 1, 2, 3, 4, 5, 6, 7, ...
Internally, this type is represented as an Int.
So, it is limited by the maxBound of Int.
Its Enum, Listable and Num instances only produce non-negative values.
When x < y then x - y = 0.
Natural numbers modulo 1: 0
Natural numbers modulo 2: 0, 1
Natural numbers modulo 3: 0, 1, 2
Natural numbers modulo 4: 0, 1, 2, 3
Natural numbers modulo 5: 0, 1, 2, 3, 4
Natural numbers modulo 6: 0, 1, 2, 3, 4, 5
Natural numbers modulo 7: 0, 1, 2, 3, 4, 5, 6
Natural numbers (including 0): 0, 1, 2, 3, 4, 5, 6, 7, ...
Internally, this type is represented as an Integer
allowing for an infinity of possible values.
Its Enum, Listable and Num instances only produce non-negative values.
When x < y then x - y = 0.
Instances
| Enum Natural # | |
| Eq Natural # | |
| Integral Natural # | |
Defined in Test.LeanCheck.Utils.Types | |
| Num Natural # | |
| Ord Natural # | |
Defined in Test.LeanCheck.Utils.Types | |
| Read Natural # | |
| Real Natural # | |
Defined in Test.LeanCheck.Utils.Types Methods toRational :: Natural -> Rational # | |
| Show Natural # | |
| Listable Natural # | |
Aliases to word types (deprecated)
Extreme Integers
X type to be wrapped around integer types for an e-X-treme integer
enumeration. See the Listable instance for X. Use X when
testing properties about overflows and the like:
> check $ \x -> x + 1 > (x :: Int) +++ OK, passed 200 tests.
> check $ \(X x) -> x + 1 > (x :: Int) +++ Failed! Falsifiable (after 4 tests): 9223372036854775807
Instances
| Eq a => Eq (X a) # | |
| Ord a => Ord (X a) # | |
| Show a => Show (X a) # | |
| (Integral a, Bounded a) => Listable (X a) # | Extremily large integers are intercalated with small integers. list :: [X Int] = map X
[ 0, 1, -1, maxBound, minBound
, 2, -2, maxBound-1, minBound+1
, 3, -3, maxBound-2, minBound+2
, ... ] |
Wrap around lists of integers for an enumeration containing e-X-treme
integer values.
> check $ \xs -> all (>=0) xs ==> sum (take 1 xs :: [Int]) <= sum xs +++ OK, passed 200 tests.
> check $ \(Xs xs) -> all (>=0) xs ==> sum (take 1 xs :: [Int]) <= sum xs *** Failed! Falsifiable (after 56 tests): [1,9223372036854775807]
Constructors
| Xs [a] |
List-wrapper types
Lists without repeated elements.
> take 6 $ list :: [NoDup Nat] [NoDup [],NoDup [0],NoDup [1],NoDup [0,1],NoDup [1,0],NoDup [2]]
Example, checking the property that nub is an identity:
import Data.List (nub) > check $ \xs -> nub xs == (xs :: [Int]) *** Failed! Falsifiable (after 3 tests): [0,0] > check $ \(NoDup xs) -> nub xs == (xs :: [Int]) +++ OK, passed 200 tests.
Constructors
| NoDup [a] |
Lists representing bags (multisets).
The Listable tiers enumeration will not have repeated bags.
> take 6 (list :: [Bag Nat]) [Bag [],Bag [0],Bag [0,0],Bag [1],Bag [0,0,0],Bag [0,1]]
See also: bagsOf and bagCons.
Constructors
| Bag [a] |
Lists representing sets.
The Listable tiers enumeration will not have repeated sets.
> take 6 (list :: [Set Nat]) [Set [],Set [0],Set [1],Set [0,1],Set [2],Set [0,2]]
Constructors
| Set [a] |
Lists of pairs representing maps.
The Listable tiers enumeration will not have repeated maps.
> take 6 (list :: [Map Nat Nat]) [Map [],Map [(0,0)],Map [(0,1)],Map [(1,0)],Map [(0,2)],Map [(1,1)]]
Constructors
| Map [(a, b)] |
Character types
Constructors
| AlphaNum | |
Fields
| |
String types
Constructors
| AlphaNums | |
Fields | |