quickcheck-classes
QuickCheck common typeclasses
https://github.com/andrewthad/quickcheck-classes#readme
| Version on this page: | 0.6.1.0@rev:1 |
| LTS Haskell 24.16: | 0.6.5.0@rev:3 |
| Stackage Nightly 2025-10-24: | 0.6.5.0@rev:3 |
| Latest on Hackage: | 0.6.5.0@rev:3 |
quickcheck-classes-0.6.1.0@sha256:518cc42b075fd5dd82930d2e802bdded42a0b7a389acd3cf6ac345c43172c8d8,6766Module documentation for 0.6.1.0
- Test
- Test.QuickCheck
quickcheck-classes
This library provides sets of properties that should hold for common typeclasses, along with three (3) simple functions that you can use to test them.
lawsCheck:
A convenience function for testing properties in GHCi. For example, at GHCi:
>>> lawsCheck (monoidLaws (Proxy :: Proxy Ordering))
Monoid: Associative +++ OK, passed 100 tests.
Monoid: Left Identity +++ OK, passed 100 tests.
Monoid: Right Identity +++ OK, passed 100 tests.
Assuming that the Arbitrary instance for Ordering is good, we now
have confidence that the Monoid instance for Ordering satisfies
the monoid laws.
lawsCheckMany:
A convenience function for checking multiple typeclass instances of multiple types. Consider the following Haskell source file:
import Data.Proxy (Proxy(..))
import Data.Map (Map)
import Data.Set (Set)
-- A 'Proxy' for 'Set' 'Int'.
setInt :: Proxy (Set Int)
setInt = Proxy
-- A 'Proxy' for 'Map' 'Int' 'Int'.
mapInt :: Proxy (Map Int Int)
mapInt = Proxy
myLaws :: Proxy a -> [Laws]
myLaws p = [eqLaws p, monoidLaws p]
namedTests :: [(String, [Laws])]
namedTests =
[ ("Set Int", myLaws setInt)
, ("Map Int Int", myLaws mapInt)
]
Now, in GHCi:
>>> lawsCheckMany namedTests
Testing properties for common typeclasses
-------------
-- Set Int --
-------------
Eq: Transitive +++ OK, passed 100 tests.
Eq: Symmetric +++ OK, passed 100 tests.
Eq: Reflexive +++ OK, passed 100 tests.
Monoid: Associative +++ OK, passed 100 tests.
Monoid: Left Identity +++ OK, passed 100 tests.
Monoid: Right Identity +++ OK, passed 100 tests.
Monoid: Concatenation +++ OK, passed 100 tests.
-----------------
-- Map Int Int --
-----------------
Eq: Transitive +++ OK, passed 100 tests.
Eq: Symmetric +++ OK, passed 100 tests.
Eq: Reflexive +++ OK, passed 100 tests.
Monoid: Associative +++ OK, passed 100 tests.
Monoid: Left Identity +++ OK, passed 100 tests.
Monoid: Right Identity +++ OK, passed 100 tests.
Monoid: Concatenation +++ OK, passed 100 tests.
lawsCheckOne
A convenience function that allows one to check many typeclass instances of the same type.
For example, in GHCi:
>>> lawsCheckOne (Proxy :: Proxy Word) [jsonLaws, showReadLaws]
ToJSON/FromJSON: Encoding Equals Value +++ OK, passed 100 tests.
ToJSON/FromJSON: Partial Isomorphism +++ OK, passed 100 tests.
Show/Read: Partial Isomorphism +++ OK, passed 100 tests.
Changes
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to the Haskell Package Versioning Policy.
[0.6.1.0] - 2019-01-12
Change
genericLawsandgeneric1Lawswere not exported. Now they are.
Added
- Add
muvectorLaws.
[0.6.0.0] - 2018-12-24
Change
- Support QuickCheck 2.7 and 2.8. This adds
Arbitraryorphan instances to the test suite. - Fix CPP that caused build failures on GHC 7.10 and some old package versions.
- Fix compiling the test suite without semigroupoids and compiling with old versions of transformers.
- Add lower bound for semigroups to make sure the
stimesmethod is available. - The laws
commutativeSemigroupLawsandcommutativeMonoidLawsno longer check any property other than commutativity. They must now be used in conjunction with, rather than in place of,semigroupLawsandmonoidLaws. This is a breaking change. - Fix the right distribution law for semirings.
- The function
lawsCheckManynow terminates with exit code 1 if a test fails. - Extend
showReadLawswith new properties forshowsPrec,readsPrec,showListandreadList. - Prettify JSON partial isomorphism test failure.
Added
- Add
genericLawsandgeneric1Laws - Add property tests for special classes of semigroups. This includes: commutative, idempotent, rectangular band, and exponential.
bifoldableLaws,bifoldableFunctorLaws- Add
showLaws.
[0.5.0.0] - 2018-09-25
Change
- When compiling with GHC 8.6 and newer, use
QuantifiedConstraintsinstead ofEq1,Show1,Arbitrary1,Eq2,Show, andArbitrary2.
[0.4.14.3] - 2018-09-21
Change
- Fix a CPP conditional import problem that caused build failures on GHC 7.10
- Set an explicit lower bound for containers
[0.4.14.2] - 2018-09-12
Change
- Support QuickCheck-2.12
- Fix compilation for containers<0.5.9
- Fix compilation with QuickCheck-2.9
[0.4.14.1] - 2018-07-24
Change
- Build correctly when dependency on semigroupoids is disabled.
[0.4.14] - 2018-07-23
Added
- commutativeSemigroupLaws
- the following typeclasses:
Data.Semigroupoid.Semigroupoid(semigroupoids)Data.Functor.Plus.Plus(semigroupoids)
Change
- semiringLaws were never exported, we now export them.
- make documentation for
MonadPlusandAlternativeconsistent. - bump semirings to 0.2.0.0
- deprecate
Test.QuickCheck.Classes.specialisedLawsCheckManyin favour ofTest.QuickCheck.Classes.lawsCheckOne
[0.4.13] - 2018-07-18
Added
- Laws for
Enumtypeclass. - Laws for
Categorytypeclass.
[0.4.12] - 2018-06-07
Added
- Remaining laws for
Storabletypeclass. - Laws for
Primtypeclass requiringsetByteArrayandsetOffAddrto match the behavior that would result from manually iterating over the array and writing the value element-by-element.
Change
- Correct the law from the
Bitstypeclass that relatesclearBitandzeroBits. - Limit the size of the lists that are used when testing that
mconcatandsconcathave behaviors that match their default implementations. For some data structures, concatenating the elements in a list of several dozen arbitrary values does not finish in a reasonable amount of time. So, the size of these has been limited to 6. - Make library build against
primitive-0.6.1.0.
[0.4.11.1] - 2018-05-25
Change
- Fix compatibility with older GHCs when
semigroupoidssupport is disabled.
[0.4.11] - 2018-05-24
Added
- Greatly improved documentation
specialisedLawsCheckManyfunction, a shorter way for the user to uselawsCheckManyon a single type.
Change
- Some internal names, making it more clear what it is that they do.
[0.4.10] - 2018-05-03
Added
- Property tests for
mconcat,sconcat, andstimes. It isn’t common to override the defaults for these, but when you do, it’s nice to check that they agree with what they are supposed to do.
[0.4.9] - 2018-04-06
Change
- Be more careful with import of
Data.Primitive. There is a branch ofprimitivethat addsPrimArray. The implementation ofPrimArrayin this library should eventually be removed, but for now it will be sufficient to ensure that it does not create a conflicting import problem with the one in the branch.
[0.4.8] - 2018-03-29
Change
- Fix compilation regression for older versions of transformers.
[0.4.7] - 2018-03-29
Change
- Split up monolithic module into hidden internal modules.
- Fix compilation regression for older GHCs.
[0.4.6] - 2018-03-29
Added
- Property test the naturality law for
MonadZip. There is another law that instances should satisfy (the Information Preservation law), but it’s more difficult to write a test for. It has been omitted for now. - Property tests for all
MonadPluslaws. - Several additional property tests for list-like containers: mapMaybe, replicate, filter.
[0.4.5] - 2018-03-26
Added
- Property tests for list-like containers that have
IsListinstances. These are useful for things that are nearlyFoldableor nearlyTraversablebut are either constrained in their element type or totally monomorphic in it.
[0.4.4] - 2018-03-23
Added
- Cabal flags for controlling whether or not
aesonandsemigroupoidsare used. These are mostly provided to accelerate buildsprimitive’s test suite.
[0.4.3] - 2018-03-23
Added
- Property tests for
foldl1andfoldr1. - Property tests for
Traversable.
[0.4.2] - 2018-03-22
Changed
- Made compatible with
transformers-0.3. Tests for higher-kinded typeclasses are unavailable when built with a sufficiently old version of bothtransformersandbase. This is becauseEq1andShow1are unavailable in this situation.
[0.4.1] - 2018-03-21
Changed
- Made compatible with
transformers-0.4.
[0.4.0] - 2018-03-20
Added
- Property tests for
BifunctorandAlternative.
Changed
- Made compatible with older GHCs all the way back to 7.8.4.
- Lower dependency footprint. Eliminate the dependency on
prim-arrayand inline the relevant functions and types from it intoTest.QuickCheck.Classes. None of these are exported.