quickcheck-monoid-subclasses

Testing monoid subclass instances with QuickCheck

Version on this page:0.3.0.3
LTS Haskell 23.1:0.3.0.4
Stackage Nightly 2024-12-21:0.3.0.4
Latest on Hackage:0.3.0.4

See all snapshots quickcheck-monoid-subclasses appears in

Apache-2.0 licensed by Jonathan Knowles
Maintained by [email protected]
This version can be pinned in stack with:quickcheck-monoid-subclasses-0.3.0.3@sha256:401b857a9054b8a5d7d5259bcd41ea54a1598402d5db0e235093f9dc3e96eb18,4559

quickcheck-monoid-subclasses

Overview

The quickcheck-monoid-subclasses library provides:

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 Monus laws hold for the Sum Natural type:

import Data.Monoid (Sum)
import Data.Proxy (Proxy (Proxy))
import Numeric.Natural (Natural)
import Test.QuickCheck.Classes (lawsCheck)
import Test.QuickCheck.Classes.Monoid.Monus (monusLaws)

lawsCheck (monusLaws (Proxy :: Proxy (Sum Natural)))

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

Monus: axiom1 +++ OK, passed 100 tests.
Monus: axiom2 +++ OK, passed 100 tests.
Monus: axiom3 +++ OK, passed 100 tests.
Monus: axiom4 +++ OK, passed 100 tests.
Monus: stripPrefixOverlap +++ OK, passed 100 tests.
Monus: stripSuffixOverlap +++ 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 Sum Natural type satisfies the laws of Semigroup and its subclasses:

import Data.Monoid (Sum)
import Data.Proxy (Proxy (Proxy))
import Numeric.Natural (Natural)
import Test.QuickCheck.Classes
import Test.QuickCheck.Classes.Monoid.GCD
import Test.QuickCheck.Classes.Monoid.LCM
import Test.QuickCheck.Classes.Monoid.Monus
import Test.QuickCheck.Classes.Monoid.Null
import Test.QuickCheck.Classes.Semigroup.Cancellative
import Test.QuickCheck.Classes.Semigroup.Factorial

lawsCheckOne (Proxy :: Proxy (Sum Natural))
    [ cancellativeLaws
    , commutativeLaws
    , distributiveGCDMonoidLaws
    , distributiveLCMMonoidLaws
    , factorialLaws
    , factorialMonoidLaws
    , gcdMonoidLaws
    , lcmMonoidLaws
    , leftCancellativeLaws
    , leftDistributiveGCDMonoidLaws
    , leftGCDMonoidLaws
    , leftReductiveLaws
    , monoidLaws
    , monoidNullLaws
    , monusLaws
    , overlappingGCDMonoidLaws
    , positiveMonoidLaws
    , reductiveLaws
    , rightCancellativeLaws
    , rightDistributiveGCDMonoidLaws
    , rightGCDMonoidLaws
    , rightReductiveLaws
    , semigroupLaws
    , stableFactorialLaws
    ]

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.

To increase coverage of interesting and important cases, this library also checks that laws hold for combinations of generated arbitrary values.

:stars: Example

Suppose we are testing the following law:

isPrefixOf a b == isJust (stripPrefix a b)

This library will also test that the following derived laws hold:

isPrefixOf a (a <> a) == isJust (stripPrefix a (a <> a))
isPrefixOf a (a <> b) == isJust (stripPrefix a (a <> b))
isPrefixOf a (b <> a) == isJust (stripPrefix a (b <> a))

Changes

0.3.0.3

  • Revised upper bounds for package dependencies.

0.3.0.2

  • Revised upper bounds for package dependencies.

0.3.0.1

  • Added support for GHC 9.8.

0.3.0.0

  • Added laws for the following factorial semigroup and monoid classes:

    • Data.Semigroup.Factorial.Factorial
    • Data.Semigroup.Factorial.StableFactorial
    • Data.Monoid.Factorial.FactorialMonoid
  • Added laws for the following GCD and LCM monoid classes:

    • Data.Monoid.GCD.{Left,Right}DistributiveGCDMonoid
    • Data.Monoid.GCD.DistributiveGCDMonoid
    • Data.Monoid.LCM.DistributiveLCMMonoid
  • Added missing laws for the following class:

    • Data.Monoid.GCD.OverlappingGCDMonoid
  • Removed cancellativeGCDMonoidLaws.

    • The documentation for the GCDMonoid class no longer states these laws.

0.2.0.0

  • Improved generation of arbitrary Semigroup value combinations.
  • Added derived laws for the LeftGCDMonoid type class.
  • Added derived laws for the RightGCDMonoid type class.
  • Removed hard-to-satisfy coverage check from LCMMonoid type class laws.
  • Added support for building with GHC 9.6 series.

0.1.0.0

  • Added laws for the LCMMonoid type class.
  • Added laws for the GCDMonoid type class to match those of LCMMonoid.

0.0.0.1

  • Revised lower dependency bound for the vector package.

0.0.0.0

  • Provides support for testing instances of classes defined in the following modules:
    • Data.Monoid.GCD
    • Data.Monoid.Monus
    • Data.Monoid.Null
    • Data.Semigroup.Cancellative