QuickCheck is a Haskell library for software testing. It generates test cases and validates them against assertions provided by the programmer.
Questions tagged [quickcheck]
422 questions
4
votes
1 answer
How can I make my type an instance of Arbitrary?
I have the following data and function
data Foo = A | B deriving (Show)
foolist :: Maybe Foo -> [Foo]
foolist Nothing = [A]
foolist (Just x) = [x]
prop_foolist x = (length (foolist x)) == 1
when running quickCheck prop_foolist, ghc tells me that…

lsund
- 744
- 5
- 16
4
votes
1 answer
Quickcheck: produce arbitrary elements of an arbitrary set
Suppose that I am writing tests for Data.Set. I would like to check that deleting elements from the set works, and so I might write something like this:
prop_deleteA it x = member x it ==> not (member x (delete x it))
assuming that it has a…

sircolinton
- 6,536
- 3
- 21
- 19
4
votes
0 answers
Sample from a regular expression
How do I generate random strings that match a regular expression with quickcheck?
In such a way that the regex (i.e. the corresponding finite automaton) generates the strings. (And not: generate some random strings that are then filtered by a…

maxschlepzig
- 35,645
- 14
- 145
- 182
4
votes
1 answer
How do I avoid 'source trait is private' when using subtraits?
I'm trying to use quickcheck in Rust. I want to define my enum as an instance of Arbitrary, so I can use it in tests.
#![feature(plugin)]
#![plugin(quickcheck_macros)]
#[cfg(test)]
extern crate quickcheck;
use…

Wilfred Hughes
- 29,846
- 15
- 139
- 192
4
votes
1 answer
Haskell, QuickCheck, falsify a (wrong) property:
Is there a way to falsify this (wrong) property:
prop :: Eq a => [a] -> Bool
prop xs = reverse xs == xs
When i Use QuickCheck and later VerboseCheck it gives 100 different forms of:
[(),(),(),(),(),(),(),(),(),(),(),(),(),(),()]
Passed:
and the…

Jack
- 41
- 1
4
votes
1 answer
Testing type classes with Quickcheck, variable number of parameters
I have a ring type class which looks like this:
class Ring a where
addId :: a
addInverse :: a -> a
mulId :: a
add :: a -> a -> a
mul :: a -> a -> a
For this class I have several instances, e.g.
instance Ring Matrix where ...
instance…

Arno
- 77
- 4
4
votes
0 answers
How do you control type defaulting in doctests
How does doctest decide what type defaulting rules to use?
I have written several doctests that I would like to default to Double (because of RealFrac or Floating contexts) that are instead failing because they are defaulting to Integer and the…

Doug McClean
- 14,265
- 6
- 48
- 70
4
votes
1 answer
Augmenting Test.QuickCheck
I want to extend QuickCheck to give me better messages when tests fail (rather than just the seed). For instance, I'd like to be able to create things along the lines of:
eqTest :: Eq a => a -> a -> TestResult
eqTest x y = if x == y
…

bfops
- 5,348
- 5
- 36
- 48
4
votes
2 answers
Test.QuickCheck: speed up testing multiple properties for the same type
I am testing a random generator generating instances of my own type. For that I have a custom instance of Arbitrary:
complexGenerator :: (RandomGen g) => g -> (MyType, g)
instance Arbitrary MyType where
arbitrary = liftM (fst . complexGenerator…

Koterpillar
- 7,883
- 2
- 25
- 41
3
votes
2 answers
How to test Monad instance for custom StateT?
I'm learning Monad Transformers, and one of the exercises asks to implement the Monad instance for StateT.
I want to test that my implementation admits to the Monad laws using the validity package, which is like the checkers package.
Problem is, my…

Abhijit Sarkar
- 21,927
- 20
- 110
- 219
3
votes
1 answer
Generate stateful function pointer for FFI testing
I want to generate stateful functions (C signature T f()) with QuickCheck as arguments for foreign functions. Preferably I also want to make them (or their inner s->(T,s)) showable.
I know that for stateless functions I can write something like
type…

Johannes Riecken
- 2,301
- 16
- 17
3
votes
2 answers
Using choose in frequency Haskell QuickCheck
So I have the code below and I am trying to make it an instance of Arbitrary:
data MyData = I Int | B Bool
instance Arbitrary MyData where
arbitrary = do {
frequency [(1, return (I 1)),
(1, return (choose((B True), (B…

Max Podpera
- 47
- 6
3
votes
1 answer
Using IO within a QuickCheck property test?
I'm currently writing a Haskell library to replace a closed-source 3rd party command line application. This 3rd party CLI has a spec that I've replicated, but the actually binary allows much more permissive inputs than the spec.
I'd like to be able…

danielbeard
- 9,120
- 3
- 44
- 58
3
votes
2 answers
Why cannot I get `where` to work in Hspec
I'm struggling with the semantics of where within do blocks, specifically with Test.Hspec. The following works:
module ExampleSpec where
import Test.Hspec
import Test.QuickCheck
spec :: Spec
spec = do
describe "foo" $ do
let
…

Ben Heilman
- 65
- 4
3
votes
1 answer
What's wrong with my quickCheck type declaration?
I roll my own elem function called elem'
elem' :: (Eq a) => a -> [a] -> Bool
elem' n ys = foldl (\acc p -> if (p == n) then True else False) False ys
Seems to work but I want to quickCheck it in GHCi so I import Test.QuickCheck
verboseCheck (\a ->…

wide_eyed_pupil
- 3,153
- 7
- 24
- 35