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
1
vote
1 answer

QuickCheck sequential Map key generation

I am trying to test a logic of custom data type. It receives a Map Int String as a parameter and then I need to add an element into the Map inside the object. Type declaration and insertion function look like this: import qualified…
Sergii Sopin
  • 411
  • 2
  • 11
1
vote
3 answers

How to generate strings drawn from every possible character?

At the moment I'm generating strings like this: arbStr :: Gen String arbStr = listOf $ elements (alpha ++ digits) where alpha = ['a'..'z'] digits = ['0'..'9'] But obviously this only generates strings from alpha num chars. How can I do it…
doctopus
  • 5,349
  • 8
  • 53
  • 105
1
vote
2 answers

Combining generator for different datatypes in Quickcheck

I would like to combine two custom generators of different data type, but which are grouped together in another datatype. In the following example, I would like to use the generator for Legumes and AnimalProteins to create another one for Proteins.…
alex_reader
  • 689
  • 1
  • 5
  • 22
1
vote
2 answers

How does QuickCheck detect datatypes?

If we define a function like this fun :: Int -> Property and then run quickCheck fun The quickCheck starts generating random data of type Int. The question is how does quickCheck detect that the argument datatype of fun is Int and not any other…
Coder
  • 431
  • 4
  • 11
1
vote
1 answer

How to debug diverging test using QuickCheck

I have some parsing code using Megaparsec that I've written a simple property to test (it generates a random expression tree, pretty-prints it, and then checks that the result parses back to the original tree). Unfortunately, there seems to be a bug…
Rupert Swarbrick
  • 2,793
  • 16
  • 26
1
vote
2 answers

Generating random terms from a grammar (simply typed lambda calculus)

I have the following grammar representing the simply typed lambda calculus (STLC) in Haskell. I saw a lot of papers in the literature about how to generate random lambda terms but was wondering if there are any libraries in Haskell that can generate…
Lana
  • 1,124
  • 1
  • 8
  • 17
1
vote
2 answers

How do I QuickCheck a Servant Application that is constructed from an IO?

I am writing an API server using Servant. The server includes persistent state. I would like to use QuickCheck to write tests for the server. The implementation of various endpoints that make up the Servant Application require a database value. …
Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
1
vote
1 answer

How to write a function to fire quickCheck prop_xxx?

I am using QuickCheck v1. Here is a simple prop_xxx defined as below: prop_foo :: (Num a) =>[a] -> Bool prop_foo xs = (reverse.reverse) xs == id xs This can be tested in GHCi correctly: quickCheck prop_foo However, when I tried to wrap the call…
Larry
  • 11
  • 1
1
vote
2 answers

Haskell: Property Based Testing for Higher Order Function

I have two properties that a function foo must satisfy: prop_1 :: [Int] -> Bool prop_1 xs = foo xs id == xs prop_2 :: [Int] -> (Int -> Int) -> (Int -> Int) -> Bool prop_2 xs f g = foo (foo xs f) g == foo xs (g . f) I am trying to check whether…
1
vote
1 answer

How do you write a new modifier in QuickCheck

I have come across a few instances in my testing with QuickCheck when it would have simplified things to write my own modifiers in some cases, but I'm not exactly sure how one would do this. In particular, it would be helpful to know how to write a…
josiah
  • 1,314
  • 1
  • 13
  • 33
1
vote
2 answers

Example that shows the limitations of integrated shrinking

I just watched a video that presents the notion of integrated shrinking for property based tests. The approach seems to have some advantages over type directed shrinking, however it was pointed out in this reddit thread that the integrated shrinking…
1
vote
0 answers

Haskell QuickCheck for testing n-ary tree eval

I have a n-ary tree defined as follows: data Tree = Leaf1 | Leaf2 | Tree ([Tree]) and I have a function eval :: Tree -> int which returns the winner (Leaf1 indicates that player one won, Leaf2 indicates that player two won) I've been trying to…
Ak-Mo
  • 389
  • 1
  • 4
  • 18
1
vote
1 answer

Couldn't match type ‘Int’ with ‘(a0, b0, c0)’ -- What does the trigger of `quickBatch` expect?

I want to quickcheck on this Sum type and I wrote the following code: data Sum a b = First a | Second b deriving (Eq, Show) instance Functor (Sum a) where fmap _ (First x) = First x fmap f (Second y) = Second (f y) instance Applicative…
cmal
  • 2,062
  • 1
  • 18
  • 35
1
vote
1 answer

doctest QuickCheck – can I import QC instances only in doctests?

I'm using doctest, and like the fact that I can test non-exported functions from where they're defined: module Foo (frobnicate) where -- | -- >>> randomInt = 42 -- True randomInt :: Int randomInt = 42 I've so far kept QuickCheck instances in the…
unhammer
  • 4,306
  • 2
  • 39
  • 52
1
vote
2 answers

Haskell there are files missing in the QuickCheck-2.11.3 package

I tried running my program which uses Haskell QuickCheck via ghc MyProgramm.hs , but received the following error: $ ghc Ex2.hs [1 of 1] Compiling Ex2 ( Ex2.hs, Ex2.o ) Ex2.hs:21:1: error: Could not find module ‘Test.QuickCheck’ …
Paradox
  • 4,602
  • 12
  • 44
  • 88