quickcheck-classes: QuickCheck common typeclasses

[ bsd3, library, testing ] [ Propose Tags ]

This library provides QuickCheck properties to ensure that typeclass instances adhere to the set of laws that they are supposed to. There are other libraries that do similar things, such as genvalidity-hspec and checkers. This library differs from other solutions by not introducing any new typeclasses that the user needs to learn.


[Skip to Readme]
Versions 0.1, 0.2, 0.3, 0.3.1, 0.3.2, 0.3.3, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.4.9, 0.4.10, 0.4.11, 0.4.11.1, 0.4.12 (info)
Change log changelog.md
Dependencies aeson, base (>=4.5 && <5), bifunctors, containers, primitive (>=0.6.1 && <0.7), QuickCheck (>=2.9), semigroupoids, semigroups, semirings (>=0.1.3), tagged, transformers (>=0.3 && <0.6) [details]
License BSD-3-Clause
Copyright 2018 Andrew Martin
Author Andrew Martin
Maintainer andrew.thaddeus@gmail.com
Category Testing
Home page https://github.com/andrewthad/quickcheck-classes#readme
Source repo head: git clone https://github.com/andrewthad/quickcheck-classes
Uploaded by andrewthad at Thu Jun 7 18:39:07 UTC 2018
Distributions LTSHaskell:0.4.12, NixOS:0.4.12, openSUSE:0.3.3
Downloads 1104 total (149 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-06-07 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
aeson

You can disable the use of the aeson package using -f-aeson.

This may be useful for accelerating builds in sandboxes for expert users.

EnabledManual
semigroupoids

You can disable the use of the semigroupoids package using -f-semigroupoids.

This may be useful for accelerating builds in sandboxes for expert users.

EnabledManual
semirings

You can disable the use of the semirings package using -f-semirings.

This may be useful for accelerating builds in sandboxes for expert users. default: True manual: True

EnabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for quickcheck-classes-0.4.12

[back to package description]

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.

specialisedLawsCheckMany

A convenience function that allows one to check many typeclass instances of the same type.

For example, in GHCi:

>>> specialisedLawsCheckMany (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.