MyNixOS website logo
Description

Testing group class instances with QuickCheck.

QuickCheck support for testing instances of type classes defined in the groups library.

quickcheck-groups

Overview

The quickcheck-groups library provides:

  • QuickCheck support for testing instances of type classes defined in the groups library.
  • Compatibility with the quickcheck-classes library.
  • Reusable properties for type class laws, in the form of Laws definitions.

Usage

In general, usage is identical to that of the quickcheck-classes library. If you're already familiar with quickcheck-classes, then using this library should be straightforward.

Testing laws for a single type class

To test that the laws of a particular class hold for a particular type, use the lawsCheck function with the Laws definition for the class you wish to test.

:stars: Example

To test that the Group laws hold for the SumInteger type:

import Data.Monoid (Sum)
import Data.Proxy (Proxy (Proxy))
import Test.QuickCheck.Classes (lawsCheck)
import Test.QuickCheck.Classes.Group (groupLaws)

lawsCheck (groupLaws (Proxy :: Proxy (Sum Integer)))

If all tests pass, you should see output similar to:

Group: groupLaw_invert_mempty    +++ OK, passed 1 test.
Group: groupLaw_invert_invert    +++ OK, passed 100 tests.
Group: groupLaw_invert_mappend_1 +++ OK, passed 100 tests.
Group: groupLaw_invert_mappend_2 +++ OK, passed 100 tests.
Group: groupLaw_subtract_mempty  +++ OK, passed 100 tests.
Group: groupLaw_subtract_self    +++ OK, passed 100 tests.
Group: groupLaw_subtract_other   +++ OK, passed 100 tests.
Group: groupLaw_pow_zero         +++ OK, passed 100 tests.
Group: groupLaw_pow_nonNegative  +++ OK, passed 100 tests.
Group: groupLaw_pow_nonPositive  +++ OK, passed 100 tests.

Testing laws for multiple type classes

To test that the laws of multiple classes hold for a particular type, use the lawsCheckOne function with the Laws definitions for the classes you wish to test.

:stars: Example

To test that the SumInteger type satisfies the laws of Abelian and all superclasses:

import Data.Monoid (Sum)
import Data.Proxy (Proxy (Proxy))
import Test.QuickCheck.Classes
import Test.QuickCheck.Classes.Group

lawsCheckOne (Proxy :: Proxy (Sum Integer))
    [ semigroupLaws
    , monoidLaws
    , groupLaws
    , abelianLaws
    ]

Subclasses and superclasses

Each of the Laws definitions provided by this library corresponds to exactly one type class, and includes just the laws for that class. Laws for subclasses and superclasses are not automatically included. Therefore, you'll need to explicitly test the laws of every single class you wish to cover.

Coverage checks

This library includes coverage checks to ensure that important cases are covered, and to reduce the probability of test passes that are false positives. These coverage checks are performed automatically.

Metadata

Version

0.0.1.3

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows