Questions tagged [quickcheck]

QuickCheck is a Haskell library for software testing. It generates test cases and validates them against assertions provided by the programmer.

422 questions
11
votes
1 answer

QuickCheck: defining Arbitrary instance in terms of other Arbitraries

I'm using QuickCheck 1 and I've got the following data types: data A = ... instance Arbitrary A where ... data B = ... instance Arbitrary B where ... data C = C A B Now I'd like to define an Arbitrary instance for C so that C values are generated…
narthi
  • 2,188
  • 1
  • 16
  • 27
11
votes
1 answer

How can I use multi-line input with QuickCheck in doctest?

From Doctest's readme, one can use doctest with QuickCheck, like this: -- | -- prop> sort xs == (sort . sort) (xs :: [Int]) I would like to describe this property using multiple lines, probably like -- | -- prop> sort xs == -- (sort .…
Yosh
  • 2,512
  • 3
  • 24
  • 30
11
votes
1 answer

QuickCheck 2 batch processing

The Batch module of QuickCheck was removed with version 2 (1.2.0.1 still has it). Because of this, I'm always feeling like mapM_-ing multiple tests together is kind of hacky. Am I overlooking the successor feature in QuickCheck 2? Is there a…
David
  • 8,275
  • 5
  • 26
  • 36
10
votes
3 answers

Which package version do I have?

One should think that this is a FAQ, but I haven't been able to find an answer to this simple question: Which version of a certain package do I have in my GHC installation? Background I'm trying to learn Haskell, and in order to do that, I'm making…
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
10
votes
5 answers

verboseCheck in QuickCheck 2?

The function verboseCheck from QuickCheck 1 seems to be absent in QuickCheck 2 (or at least, I can't find it). Is there any other way to show which values are used during testing?
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
9
votes
2 answers

Is there a monadic version of Arbitrary to use with QuickCheck?

When I want to test pure code using QuickCheck I often have to write an Arbitrary instance. To test monadic code, I can use Test.QuickCheck.Monadic as described in this article. My question is: Is there some canonical way to generate data that…
julx
  • 8,694
  • 6
  • 47
  • 86
9
votes
0 answers

Running QuickCheck properties in parallel

In my project, I have several QuickCheck properties, most of which I collect using forAllProperties, defined in Test.QuickCheck.All. I am trying to run all my properties in parallel which is proving troublesome: at the end of a run, I get the output…
9
votes
2 answers

How can I test functions polymorphic over Applicatives?

I've just written a function (for Data.Sequence) traverseWithIndex :: Applicative f => (Int -> a -> f b) -> Seq a -> f (Seq b) which should obey traverseWithIndex f = sequenceA . mapWithIndex f Thankfully, this is a straightforward mechanical…
dfeuer
  • 48,079
  • 5
  • 63
  • 167
9
votes
2 answers

Haskell QuickCheck minimal counter example

Consider the following tests for the distributivity law between reverse and ++, import Test.QuickCheck test :: [Int] -> [Int] -> Bool test xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys test2 :: (Eq a) => [a] -> [a] -> Bool test2 xs ys =…
elm
  • 20,117
  • 14
  • 67
  • 113
9
votes
3 answers

What is the general case of QuickCheck's promote function?

What is the general term for a functor with a structure resembling QuickCheck's promote function, i.e., a function of the form: promote :: (a -> f b) -> f (a -> b) (this is the inverse of flip $ fmap (flip ($)) :: f (a -> b) -> (a -> f b)). Are…
9
votes
1 answer

How do I write QuickCheck tests that don't mimic implementation of the function?

I am using Haskell and QuickCheck to write a test for the following function: {-| Given a list of points and a direction, find the point furthest along in that direction. -} fn :: (Eq a, Ord a, DotProd a) => [a] -> a -> a fn pnts dir = pnts !!…
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
9
votes
2 answers

typeclass challenge: having both variadic arguments and results

While writing some Arbitrary instances, I implemented a couple of functions with the following quite mechanical pattern: type A = Arbitrary -- to cut down on the size of the annotations below shrink1 :: (A a ) => (a -> r) -> (a …
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
9
votes
1 answer

Testing Parsec parsers by generating inputs with QuickCheck

I'd like to write tests for a suite of Parsec parsers. Here's a simple example of a parser I want to test with QuickCheck: identifier = do c <- letter cs <- many (alphaNum <|> oneOf identSymbols) skipSpaces return $ Ident $ c:cs So,…
Derek Thurn
  • 14,953
  • 9
  • 42
  • 64
8
votes
3 answers

Is it a good or a bad thing that a suite of quickcheck tests match the implementations?

I'm trying to get started with Haskell's QuickCheck, and while I am familiar with the concepts behind the testing methodology, this is the first time I am trying to put it to use on a project that goes beyond testing stuff like reverse . reverse ==…
8
votes
2 answers

Is there a "there exists" quantifier in QuickCheck?

There is the forAll quantifier that returns a property which checks if all test cases pass. Is there a way to define a "there exists" quantifier that returns a property which checks it at least one test case passes?
Guillaume Chérel
  • 1,478
  • 8
  • 17