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
8
votes
2 answers
quickCheckAll always return "True"
I'm trying to use QuickCheck following another answer.
I test like this:
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All
last' :: [a] -> a
last' [x] = x
last' (_:xs) = last' xs
prop_test x = last' x == last…

Ervine
- 83
- 5
8
votes
1 answer
QuickCheck tests for dependent types
I am writing Vector and Matrix data types that are dependently typed.
data Vector n e where
EmptyVector :: Vector Zero e
(:>) :: e -> Vector n e -> Vector (Succ n) e
deriving instance Eq e => Eq (Vector n e)
infixr :>
data Matrix r c e…

sdasdadas
- 23,917
- 20
- 63
- 148
8
votes
1 answer
Haskell - Parsec testing with the help of QuickCheck
I'd like to write a tests for a Parsec parser. Here is the example of parser and data structure:
data Event = Event { keyEvent :: String }
deriving Show
parseKey :: Parser Event
parseKey = do
char '<'
k <- many1…

m0nhawk
- 22,980
- 9
- 45
- 73
8
votes
1 answer
How to use modifiers with Quickcheck (Positive in my case)
I've a function, rev, that returns some value for a type that is in three typeclasses:
rev :: (Integral a, Show a, Read a) => a -> a
rev = read . reverse . show
I'd like to test some property about it with quickcheck. Though, I'm not interested in…

m09
- 7,490
- 3
- 31
- 58
8
votes
2 answers
Automatically gather all quickChecks
Being a fan of quickCheck, I have a lot of
prop_something_something = ...
throughout my program.
For convenience, to easily run all of them, I define
runchecks = do
quickCheck prop_something_something
quickCheck…

Christian Neverdal
- 5,655
- 6
- 38
- 93
7
votes
3 answers
How can I prevent QuickCheck from catching all exceptions?
The QuickCheck library seems to catch all exceptions that are thrown when testing a property. In particular, this behavior prevents me from putting a time limit on the entire QuickCheck computation. For example:
module QuickCheckTimeout…

Brad Larsen
- 995
- 1
- 12
- 20
7
votes
3 answers
How do I emulate Lisp (apply) or (curry) in Rust?
I'm porting QuickCheck to Rust, and I've written everything except for_all as I'm not sure what the type signature should be.
I know that in general, for_all will accept a property lambda and a collection of generator lambdas. It will evaluate the…

mcandre
- 22,868
- 20
- 88
- 147
7
votes
1 answer
Haskell: How to test a (reactive) FSM with quickcheck?
I wrote a finite state machine module for a little soccer game I'm currently working at. It provides an interface for setting up an FSM (basically its states and transitions). For each state, you can provide functions that will be fired on entry and…

martingw
- 4,153
- 3
- 21
- 26
7
votes
2 answers
Why does quickcheck pass for these two different functions Haskell?
I have two functions. They are:
f1 [] = []
f1 (x:xs) = if contains x xs then f1 xs else x:f1 xs
and
f6 xs = f1 (rev xs)
It would not make sense that these two functions return the same list for anything other than the empty list and any list with…

knowledge_seeker
- 811
- 1
- 8
- 18
7
votes
2 answers
How to test Semigroup law for this data type?
I'm trying to solve the same exercise as this other question in Chapter 15 of "Haskell Programming from First Principles". I've already made a Semigroup instance, and I'm having trouble writing the QuickCheck part of the exercise.
A Semigroup…

Thales MG
- 761
- 5
- 15
7
votes
1 answer
Running QuickCheck against Simple Test w/ Function
Given the following:
test :: (Int -> Int) -> Int -> Bool
test _ _ = True
After compiling the source, I try to run quickCheck test:
> quickCheck test
:27:1:
No instance for (Show (Int -> Int))
arising from a use of…

Kevin Meredith
- 41,036
- 63
- 209
- 384
7
votes
1 answer
Haskell QuickCheck Test not running properly when run with Cabal
Something did not make sense with a Cabal package I was developing, and I have boiled the issue down to the following example:
I have the following simple test module:
module Main where
import Test.QuickCheck (quickCheck)
main = quickCheck…

mherzl
- 5,624
- 6
- 34
- 75
7
votes
3 answers
How can I constrain a QuickCheck parameter to a list of non-empty Strings?
I have a property that takes a list of Strings:
myProp :: [String] -> Bool
I need to constrain the inputs that QuickCheck generates so that only non-empty strings are in the list.
How can I do this?

Colin McEnearney
- 73
- 3
7
votes
3 answers
How can I constraint QuickCheck parameters, e.g. only use non-negative ints?
I'm new to Haskell. It's very nice so far, but I'm running into copy-pasting for my QuickCheck properties, and I'd like to fix that.
Here's a made-up example:
prop_Myfunc :: [Int] -> (Int,Int) -> Bool
prop_Myfunc ints (i,j) = ints !! i == ints !!…

Joel Hinz
- 24,719
- 6
- 62
- 75
7
votes
3 answers
QuickCheck values equal
I have a QuickCheck property that looks like this:
prop42 :: Foo -> Bool
prop42 foo = fn1 foo == fn2 foo
If this property fails, it will print out what foo was. But I'd really like to know what fn1 and fn2 returned. And if foo is large, it's kinda…

MathematicalOrchid
- 61,854
- 19
- 123
- 220