项目作者: rudymatela

项目描述 :
Common LeanCheck instances
高级语言: Haskell
项目地址: git://github.com/rudymatela/leancheck-instances.git
创建时间: 2018-11-28T22:45:53Z
项目社区:https://github.com/rudymatela/leancheck-instances

开源协议:Other

下载


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:

  1. $ cabal update
  2. $ cabal install leancheck-instances

Examples

Importing the library:

  1. > import Test.LeanCheck
  2. > import Test.LeanCheck.Instances

Checking properties of Text:

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

Enumerating Maps:

  1. > import Data.Map
  2. > list :: [Map Bool Bool]
  3. [ fromList []
  4. , fromList [(False,False)]
  5. , fromList [(False,True)]
  6. , fromList [(True,False)]
  7. , fromList [(True,True)]
  8. , fromList [(False,False),(True,False)]
  9. , fromList [(False,False),(True,True)]
  10. , fromList [(False,True),(True,False)]
  11. , fromList [(False,True),(True,True)]
  12. ]
  13. > take 7 $ list :: [Map Int Int]
  14. [ fromList []
  15. , fromList [(0,0)]
  16. , fromList [(0,1)]
  17. , fromList [(1,0)]
  18. , fromList [(0,-1)]
  19. , fromList [(1,1)]
  20. , fromList [(0,0),(1,0)]
  21. ]

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:

    1. $ cat > src/Test/LeanCheck/Instances/Something.hs
    2. -- |
    3. -- Module : Test.LeanCheck.Instances.Containers
    4. -- Copyright : (c) 2019 Authors of leancheck-instances
    5. -- License : 3-Clause BSD (see the file LICENSE)
    6. -- Maintainer : Rudy Matela <rudy@matela.com.br>
    7. --
    8. -- 'Listable' something.
    9. module Test.LeanCheck.Instances.Something () where
    10. import Test.LeanCheck
    11. import Something
    12. ^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:

    1. instance ... => Listable Something where
    2. ...

    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