Questions tagged [smallcheck]

SmallCheck is a testing library that allows to verify properties for all test cases up to some depth. The test cases are generated automatically by SmallCheck.

SmallCheck is a testing library that allows to verify properties for all test cases up to some depth. The test cases are generated automatically by SmallCheck.

Test.SmallCheck

This module exports the main pieces of SmallCheck functionality.

To generate test cases for your own types, refer to Test.SmallCheck.Series.

For pointers to other sources of information about SmallCheck, please refer to the README at https://github.com/feuerbach/smallcheck/blob/master/README.md

Constructing tests

The simplest kind of test is a function (possibly of many arguments) returning Bool. The function arguments are interpreted as being universally, existentially or uniquely quantified, depending on the quantification context.

The default quantification context is universal (forAll).

forAll, exists and existsUnique functions set the quantification context for function arguments. Depending on the quantification context, the test \x y -> p x y may be equivalent to:

∀ x, y. p x y (forAll)
∃ x, y: p x y (exists)
∃! x, y: p x y (existsUnique)

The quantification context affects all the variables immediately following the quantification operator, also extending past over, changeDepth and changeDepth1 functions.

However, it doesn't extend past other functions, like monadic, and doesn't affect the operands of ==>. Such functions start a fresh default quantification context.

Examples

\x y -> p x y means ∀ x, y. p x y
exists $ \x y -> p x y means ∃ x, y: p x y
exists $ \x -> forAll $ \y -> p x y means ∃ x: ∀ y. p x y
existsUnique $ \x y -> p x y means ∃! (x, y): p x y
existsUnique $ \x -> over s $ \y -> p x y means ∃! (x, y): y ∈ s && p x y
existsUnique $ \x -> monadic $ \y -> p x y means ∃! x: ∀ y. [p x y]
existsUnique $ \x -> existsUnique $ \y -> p x y means ∃! x: ∃! y: p x y
exists $ \x -> (\y -> p y) ==> (\z -> q z) means ∃ x: (∀ y. p y) => (∀ z. p z)
20 questions
17
votes
3 answers

How to use SmallCheck in Haskell?

I am trying to use SmallCheck to test a Haskell program, but I cannot understand how to use the library to test my own data types. Apparently, I need to use the Test.SmallCheck.Series. However, I find the documentation for it extremely confusing. I…
6
votes
1 answer

Generics Series Generating Infinite List

With this fragment, and smallcheck-1.0.1 data Foo = A | B | Pair Foo Foo deriving Show deriving instance Generic Foo instance (Monad m) => Serial m Foo then this list 1 (series :: Series Identity Foo) generates an apparently infinite…
Ben Clifford
  • 1,398
  • 1
  • 12
  • 23
5
votes
2 answers

How much should one control the `Depth` parameter in smallcheck?

I'm doing my first bit of real work with smallcheck, and I'm a little confused about how to use the Depth parameter. Before I go into that, let me state what I'm using smallcheck for. At work, we're building a simple web service in front of our own…
ocharles
  • 6,172
  • 2
  • 35
  • 46
4
votes
2 answers

Haskell / SmallCheck: How to control the `Depth` parameter?

I have a simple data structure to test in smallcheck. {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} {-# LANGUAGE DeriveGeneric #-} import Test.Tasty import Test.Tasty.SmallCheck import Test.SmallCheck.Series import GHC.Generics data T1…
jules
  • 1,897
  • 2
  • 16
  • 19
4
votes
2 answers

How does one use monadic properties in SmallCheck?

I would like to write a SmallCheck property that uses IO, but I can't figure out how I am supposed to do it. Specifically, the goal is to write a property that is an instance of Testable IO Bool so that I can feed it into smallCheck (or…
Gregory Crosswhite
  • 1,457
  • 8
  • 17
3
votes
1 answer

Why does smallCheck's `Series` class have two types in the constructor?

This question is related to my other question about smallCheck's Test.SmallCheck.Series class. When I try to define an instance of the class Serial in the following natural way (suggested to me by an answer by @tel to the above question), I get…
2
votes
1 answer

Impure property test with SmallCheck and Tasty: resource acquisition

I am trying to write property based test with Tasty library and SmallCheck. But I need IO in the property check function and also I need I/O resource. So, I turned existing test into: myTests :: IO Cfg -> TestTree myTests getResource = testGroup "My…
RandomB
  • 3,367
  • 19
  • 30
2
votes
1 answer

Property Based Testing with Exceptions

I am writing an introduction to Haskell for my local functional programming group. As a base I am using the Tasty-testing framework and I want to test the indexing function (!!). MinimalExample.hs module MinimalExample where myIndex :: Int -> [a]…
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
2
votes
1 answer

SmallCheck: Making types instance of typeclass Serial

I'm trying to figure out how to use the smallcheck property-based test library in conjunction with tasty. I ran into a problem with multi-field record types: How can I make a record type with mor than 4 fields member of the Serial typeclass? I…
jules
  • 1,897
  • 2
  • 16
  • 19
1
vote
1 answer

Testing of high-order function with SmallCheck

I am trying SmallCheck with high-order functions, and the code is: import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.SmallCheck import Test.SmallCheck.Series ... type IntMorph = Int -> Int ... main :: IO () main = defaultMain $…
RandomB
  • 3,367
  • 19
  • 30
1
vote
0 answers

How to make Serial instance from another one with permutations (simulation of "any order")

SmallCheck related question. If I wrote the instance Series m [Something] then how can I create Series m Something from it? This list appeared in the type because I have 4 series and I want to generate series of their permutations (aka IN ANY…
RandomB
  • 3,367
  • 19
  • 30
1
vote
1 answer

How to write Serial instance for this function?

Suppose, I have types like data D = A | B String | C String data TestIt m = TestIt { x :: m Int , y :: Int -> m D } and I am writing SmallCheck test, so I need Serial instance on TestIt: instance Monad m => Serial m (TestIt m) where series =…
RandomB
  • 3,367
  • 19
  • 30
1
vote
0 answers

smallcheck what does "but n did not meet ==>" and how do I know which

I wrote this property prop_lookupsymbol = forAll $ \name table scope -> case lookupsymbol name table scope of Just (s,_) -> property $ is_ancestor s scope …
niceman
  • 2,653
  • 29
  • 57
1
vote
0 answers

SmallCheck series generation and duplicates (the parameters have relations)

The following data structure can be tested with the Tasty-SmallCheck related code that follows. There is a relation that has to hold with the constructor ShB: the second and the third positive integers should be at most as large as the first one.…
Gspia
  • 809
  • 6
  • 15
1
vote
1 answer

testing (tasty-smallcheck) and file organisation and avoiding orphan instances

A library is in src-directory and there is a data definition A. Code related to testing is in test-directory, as suggested in many tutorials, and that includes Serial instance to generate the test cases, see links below: instance Monad m => Serial…
Gspia
  • 809
  • 6
  • 15
1
2