BSD-3-Clause licensed and maintained by Scott Murphy

Module documentation for 0.2.1.0

This version can be pinned in stack with:quickcheck-arbitrary-template-0.2.1.0@sha256:01f9deb34f8af3e6b879ee984b0be8803eb9c31e389490b5ddb8ca5fde32957c,2026

quickcheck-arbitrary-template

Test.QuickCheck.TH.GeneratorsSpec

contains one routine: makeArbitrary

Which builds, a generator that can be used to create an arbitrary instance.

It does not create the instance directly for you.

It supports creating sum types and record types each constructor may have at most 7 arguments.

Installation

stack build

Usage

An example (from the tests)

{-# LANGUAGE TemplateHaskell #-}
module Test.QuickCheck.TH.GeneratorsSpec (tests) where

import Test.QuickCheck.TH.Generators

import Test.Tasty
import Test.Tasty.QuickCheck as QC
import Test.Tasty.HUnit

import Data.List
import Data.Ord



-- | These example types should build arbitrary instances correctly 

data ExampleSumTypes = ExampleSum0 
                    | ExampleSum1 Int
                    | ExampleSum2 Int Int
                    | ExampleSum3 Int Int Int
                    | ExampleSum4 Int Int Int Int
                    | ExampleSum5  Int Int Int Int Int
                    | ExampleSum6 Int Int Int Int Int Int
                    | ExampleSum7 Int Int Int Int Int Int
 deriving (Show,Ord,Eq)

makeArbitrary ''ExampleSumTypes


instance Arbitrary ExampleSumTypes where
  arbitrary = arbitraryExampleSumTypes

tests :: TestTree
tests = testGroup "Tests" [properties]

properties :: TestTree
properties = testGroup "Properties" [qcProps]

qcProps = testGroup "(checked by QuickCheck)"
  [ QC.testProperty "sort == sort . reverse" (
       \list -> sort (list :: [ExampleSumTypes]) == sort (reverse list)) ]

How to run tests

stack test quickcheck-arbitrary-template

Changes

Revision history for quickcheck-arbitrary-template

0.2.1.0 – 2018-08-03

  • Update version range template-haskell >= 2.11 && < 2.15.

0.2.0.0 – 2018-02-07

  • Add version range template-haskell >= 2.11 && < 2.13 and add support for 2.12.
comments powered byDisqus