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
19
votes
1 answer

Test.QuickCheck.Monadic: why is assert applied to Bool, not Testable a => a

In Testing Monadic Code with QuickCheck (Claessen, Hughes 2002), assert has the type: assert :: (Monad m, Testable a) => a -> PropertyM m () However, in Test.QuickCheck.Monadic, it has the type: assert :: (Monad m) => Bool -> PropertyM m () Why…
frasertweedale
  • 5,424
  • 3
  • 26
  • 38
18
votes
1 answer

Controlling how test data is generated in QuickCheck

I wrote an algorithm to find a solution to the subset sum problem in Haskell. The signature is subsetSum :: (Ord a, Num a) => [a] -> a -> Maybe [a] QuickCheck seems to be a good fit to test that. For example I here is one of the properties that I…
Antoine
  • 5,158
  • 1
  • 24
  • 37
17
votes
1 answer

How do you override Haskell type class instances provided by package code?

I have some old Haskell code that includes QuickCheck test cases. Newer versions of QuickCheck (I've just upgraded to 2.4.0.1) include type class instances for Arbitrary Word8 and others. These did not exist in older 2.0.x versions of…
David Joyner
  • 22,449
  • 4
  • 28
  • 33
16
votes
2 answers

What to use property testing for

I'd like to know what is the property testing aiming for, what is it's sweet point, where it should be used. Let' have an example function that I want to test: f :: [Integer] -> [Integer] This function, f, takes a list of numbers and will square…
ryskajakub
  • 6,351
  • 8
  • 45
  • 75
16
votes
1 answer

Conditional QuickCheck properties

I wrote a QuickCheck property for a function that merges two sorted inputs into a sorted output: prop_merge xs ys = if (sorted xs && sorted ys) then (sorted (merge xs ys)) else True That is, when the inputs are sorted, the output is sorted as…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
16
votes
3 answers

How to tell QuickCheck to generate only valid list indices for a parameter?

Say I want to write some unit tests for the (!!) function. my_prop xs n = ... I want to restrict n to only valid indexes and I know I could do something like my_prop xs n = (not.null) (drop n xs) ==> ... But this makes it so that the vast majority…
hugomg
  • 68,213
  • 24
  • 160
  • 246
16
votes
2 answers

"cookbook" for converting from QuickCheck1 to QuickCheck2?

Is there a cookbook available for converting from QuickCheck1 to QuickCheck2? As some examples, defaultConfig (replaced by Args) and trivial were removed and CoArbitrary introduced. I did read the what's new in QuickCheck 2 (with single answer ...).
gliptak
  • 3,592
  • 2
  • 29
  • 61
15
votes
2 answers

Property based testing in PHP?

In various more functional based languages there are tools (like Quickcheck) which allow for property based testing. How would I go about property based testing in PHP? I would like to be able to specify the in and output properties of a PHP method,…
Ward Bekker
  • 6,316
  • 9
  • 38
  • 61
15
votes
4 answers

QuickCheck: How to use exhaustiveness checker to prevent forgotten constructors of a sum type

I have a Haskell data type like data Mytype = C1 | C2 Char | C3 Int String If I case on a Mytype and forget to handle one of the cases, GHC gives me a warning (exhaustiveness check). I now want to write a QuickCheck Arbitrary instance to…
nh2
  • 24,526
  • 11
  • 79
  • 128
15
votes
2 answers

Idiomatic way to shrink a record in QuickCheck

Suppose I have a record type: data Foo = Foo {x, y, z :: Integer} A neat way of writing an Arbitrary instance uses Control.Applicative like this: instance Arbitrary Foo where arbitrary = Foo <$> arbitrary <*> arbitrary <*> arbitrary shrink f…
Paul Johnson
  • 17,438
  • 3
  • 42
  • 59
14
votes
2 answers

How can I test a higher-order function using QuickCheck?

I have a higher-order function that I want to test, and one of the properties I want to test is what it does with the functions that are passed in. For purposes of illustration, here is a contrived example: gen :: a -> ([a] -> [a]) -> ([a] -> Bool)…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
14
votes
2 answers

Find the value that failed for quickcheck

When a value fails a QuickCheck'd test, I'd like to use it for debugging. Is there any way I can do something like: let failValue = quickCheck' myTest in someStuff failValue If my data was readable then I could probably hack some way to get it in…
Xodarap
  • 11,581
  • 11
  • 56
  • 94
14
votes
3 answers

Generating a lists of a specific length with Haskell's QuickCheck

-- 3 (find k"th element of a list) element_at xs x = xs !! x prop_3a xs x = (x < length xs && x >= 0) ==> element_at xs (x::Int) == (xs !! x::Int) When prop_3a is ran through QuickCheck, it gives up, because it won't generate long enough lists. How…
Joe Van Dyk
  • 6,828
  • 8
  • 57
  • 73
14
votes
1 answer

haskell - Average floating point error using QuickCheck

I am using QuickCheck-2.5.1.1 to do QA. I am testing two pure functions gold :: a -> Float and f :: a -> Float, where a instances Arbitrary. Here gold is a reference calculation and f is a variation I am optimizing. To date, most of my tests using…
Matt W-D
  • 1,605
  • 2
  • 19
  • 22
13
votes
1 answer

What is the name of this generalization of idempotence?

Lots of commonly useful properties of functions have concise names. For example, associativity, commutativity, transitivity, etc. I am making a library for use with QuickCheck that provides shorthand definitions of these properties and others. The…
Doug McClean
  • 14,265
  • 6
  • 48
  • 70
1
2
3
28 29