leancheck-instances: Common LeanCheck instances

[ bsd3, library, testing ] [ Propose Tags ] [ Report a vulnerability ]

Listable instances for types provided by the Haskell Platform.

The current objective is to include all types supported by quickcheck-instances: https://hackage.haskell.org/package/quickcheck-instances


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5
Change log changelog.md
Dependencies array, base (>=4 && <5), bytestring, containers, leancheck (>=0.9.2), nats, text, time [details]
Tested with ghc ==9.4, ghc ==9.2, ghc ==9.0, ghc ==8.10, ghc ==8.8, ghc ==8.6, ghc ==8.4, ghc ==8.2, ghc ==8.0, ghc ==7.10, ghc ==7.8
License BSD-3-Clause
Author Rudy Matela <rudy@matela.com.br>
Maintainer Rudy Matela <rudy@matela.com.br>
Category Testing
Home page https://github.com/rudymatela/leancheck-instances#readme
Source repo head: git clone https://github.com/rudymatela/leancheck-instances
this: git clone https://github.com/rudymatela/leancheck-instances(tag v0.0.5)
Uploaded by rudymatela at 2022-10-11T12:00:31Z
Distributions LTSHaskell:0.0.5, NixOS:0.0.5, Stackage:0.0.5
Downloads 2278 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-10-11 [all 1 reports]

Readme for leancheck-instances-0.0.5

[back to package description]

LeanCheck

leancheck-instances's Build Status leancheck-instances on Hackage leancheck-instances on Stackage LTS leancheck-instances on Stackage Nightly

This package extends LeanCheck by providing Listable instances for common types provided by the Haskell Platform.

This package is to LeanCheck what quickcheck-instances is to QuickCheck. The current objective is to include all types supported by quickcheck-instances.

Installing

To install the latest leancheck-instances version from Hackage, just run:

$ cabal update
$ cabal install leancheck-instances

Examples

Importing the library:

> import Test.LeanCheck
> import Test.LeanCheck.Instances

Checking properties of Text:

> import qualified Data.Text as T
> check $ \t -> T.reverse (T.reverse t) == t
+++ OK, passed 200 tests.
> check $ \t -> T.reverse t == t
*** Failed! Falsifiable (after 6 tests):
"a "

Enumerating Maps:

> import Data.Map
> list :: [Map Bool Bool]
[ fromList []
, fromList [(False,False)]
, fromList [(False,True)]
, fromList [(True,False)]
, fromList [(True,True)]
, fromList [(False,False),(True,False)]
, fromList [(False,False),(True,True)]
, fromList [(False,True),(True,False)]
, fromList [(False,True),(True,True)]
]
> take 7 $ list :: [Map Int Int]
[ fromList []
, fromList [(0,0)]
, fromList [(0,1)]
, fromList [(1,0)]
, fromList [(0,-1)]
, fromList [(1,1)]
, fromList [(0,0),(1,0)]
]

Adding more instances

Although the current objective is to include all types supported by quickcheck-instances, leancheck-instances only has about 10% of what is needed. Any help with new instances to increase that percentage will be appreciated.

This section provides a quick guide on how to add new instances.

  1. Choose the type to support Compare the instances provided on quickcheck-instances and leancheck-instances and choose any that has not been added to leancheck-instances yet.

  2. Create the module file if needed If needed, create a module that will contain your instance following the same structure in quickcheck-instances:

     $ cat > src/Test/LeanCheck/Instances/Something.hs
     -- |
     -- Module      : Test.LeanCheck.Instances.Containers
     -- Copyright   : (c) 2019 Authors of leancheck-instances
     -- License     : 3-Clause BSD  (see the file LICENSE)
     -- Maintainer  : Rudy Matela <rudy@matela.com.br>
     --
     -- 'Listable' something.
     module Test.LeanCheck.Instances.Something () where
    
     import Test.LeanCheck
     import Something
     ^D
    

    Remember to:

    • Import your newly created module on src/Test/LeanCheck/Instances.hs

    • Add your newly created module to the exposed-modules list in leancheck-instances.cabal.

    • You may need to add a package dependency to build-depends on leancheck-instances.cabal.

    • (Optionally) run make depend to update the mk/depend.mk file.

  3. Create your instance Open the relevant module with your favourite text editor and add your instance:

     instance ... => Listable Something where
       ...
    

    Check the existing modules and the Listable typeclass documentation for how to create one.

    Make sure your instance builds with cabal build.

  4. Create tests Go into tests/main.hs and add two properties exercising your type, one that holds and one that fails. Make sure the tests pass by running cabal test.

  5. (Optional) Add diff-tests

    • on bench/tiers.hs add an entry for your type;
    • add two matching entries on the diff-test-tiers and update-diff-test-tiers Makefile targets.
    • run make update-diff-test to generate the reference output file.
    • run make test just to make sure the test is working.
  6. Submit a Pull Request Then submit a pull request on GitHub and wait for your build to pass. Alternatively, send a patch via e-mail.

Further reading / see also