Common LeanCheck instances
|Version on this page:||0.0.4|
|LTS Haskell 20.23:||0.0.5|
|Stackage Nightly 2023-05-31:||0.0.5|
|Latest on Hackage:||0.0.5|
This package extends LeanCheck by providing
Listable instances for common types provided by the
This package is to LeanCheck what quickcheck-instances is to QuickCheck. The current objective is to include all types supported by quickcheck-instances.
To install the latest leancheck-instances version from Hackage, just run:
$ cabal update $ cabal install leancheck-instances
Importing the library:
> import Test.LeanCheck > import Test.LeanCheck.Instances
Checking properties of
> 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 "
> 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.
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.
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 <email@example.com> -- -- 'Listable' something. module Test.LeanCheck.Instances.Something () where import Test.LeanCheck import Something ^D
Import your newly created module on
Add your newly created module to the
You may need to add a package dependency to
make dependto update the
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
Listabletypeclass documentation for how to create one.
Make sure your instance builds with
Create tests Go into
tests/main.hsand add two properties exercising your type, one that
holdsand one that
fails. Make sure the tests pass by running
(Optional) Add diff-tests
bench/tiers.hsadd an entry for your type;
- add two matching entries on the
make update-diff-testto generate the reference output file.
make testjust to make sure the test is working.
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
- leancheck-instances’ Haddock Documentation;
- LeanCheck provider for Tasty
$ cabal install tasty-leancheck;
- LeanCheck provider for test-framework
$ cabal install test-framework-leancheck;
- LeanCheck provider for Hspec
$ cabal install hspec-leancheck.
Changelog for leancheck-instances
- minor improvement on Listable UTCTime
- improve tests
- Add guide for how to add new Listable instances.
- Minor improvements in Haddock documentation.
- Fix minor bug in the Makefile.
- Listable Set instance;
- Listable Map instance;
- Listable IntSet instance;
- Listable IntMap instance;
- Some Data.Time instances;
- Listable Array instance.
- ByteString instances;
- Natural instance;
- Text instance;
- initial release on Hackage.