quickcheck-arbitrary-template: Generate QuickCheck Gen for Sum Types

[ bsd3, library, testing ] [ Propose Tags ]

Building Sum Type arbitrary instance is kind of a pain. This tool helps automate the process.


[Skip to Readme]
Versions 0.2.0.0
Change log ChangeLog.md
Dependencies base (==4.*), QuickCheck, safe, template-haskell (>=2.11 && <2.13) [details]
License BSD-3-Clause
Copyright 2016-2018 Plow Technologies
Author Scott Murphy <scottmurphy09@gmail.com>
Maintainer Scott Murphy <scottmurphy09@gmail.com>
Category Testing
Home page https://github.com/plow-technologies/quickcheck-arbitrary-adt#readme
Bug tracker https://github.com/plow-technologies/quickcheck-arbitrary-template/issues
Source repo head: git clone https://github.com/plow-technologies/quickcheck-arbitrary-template
Uploaded by mchaver at Wed Feb 7 02:59:35 UTC 2018
Distributions NixOS:0.2.0.0
Downloads 85 total (23 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-02-07 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for quickcheck-arbitrary-template-0.2.0.0

[back to package description]

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