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

How do I improve QuickCheck and Parsec debugging?

I am using Haskell and Parsec to parse a file format. My parsing function looks something like: parseInput :: String -> Model parseInput input = ... data Model = Model { mNumV :: Int, mNumF :: Int, ... } In order to test this, I am using…
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
7
votes
1 answer

Haskell quickcheck to generate and test rose trees?

I am trying out a simple rose tree code. data RoseT a = Leaf a | Node a [RoseT a] deriving (Show) instance Eq (RoseT a) where (==) (Leaf a) (Leaf b) = a == b (==) (Node a rs1) (Node b rs2) = and ((a==b): (zipWith (==) rs1 rs2)) (==) _ _ = False…
Tem Pora
  • 2,043
  • 2
  • 24
  • 30
6
votes
3 answers

Why is this implementation a bad instance of the Foldable Typeclass?

I'm working through the wonderful Haskell Book. At the end of the Traversable chapter (21), I need to write an instance for the following Tree: data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) Here is a link to the full code of my…
javinor
  • 674
  • 4
  • 8
6
votes
1 answer

Make Test.QuickCheck.Batch use a default type for testing list functions

I am testing a function called extractions that operates over any list. extractions :: [a] -> [(a,[a])] extractions [] = [] extractions l = extract l [] where extract [] _ = [] extract (x:xs) prev = (x, prev++xs) : extract xs (x :…
Nathan Shively-Sanders
  • 18,329
  • 4
  • 46
  • 56
6
votes
1 answer

Generate injective functions with QuickCheck?

I'm using QuickCheck to generate arbitrary functions, and I'd like to generate arbitrary injective functions (i.e. f a == f b if and only if a == b). I thought I had it figured out: newtype Injective = Injective (Fun Word Char) deriving…
ivan
  • 6,032
  • 9
  • 42
  • 65
6
votes
2 answers

QuickCheck: why isn't there a function to pass a test and what to use instead?

Why isn't there a QuickCheck function similar to hedgehog's success? In particular I was wondering how one could translate a property like the following one: prop_specialPair :: Property prop_specialPair = property $ do (_, xs) <- forAll…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
6
votes
1 answer

Why does shrinking stop once one of the terms is fully shrunk

I'm looking at the comments in shrink: It is tempting to write the last line as [Branch x' l' r' | x' <- shrink x, l' <- shrink l, r' <- shrink r] but this is the wrong thing! It will force QuickCheck to shrink x, l and r in tandem, and shrinking…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
6
votes
1 answer

CoArbitrary in Haskell

I am working through the Haskell Book and have come to the point of writing an Arbitrary instance for newType Comp. The code is below instance Show (Comp a) where show f = "Unicorns!!" newtype Comp a = Comp { unComp :: (a -> a) } instance…
tesserakt
  • 3,231
  • 4
  • 27
  • 40
6
votes
0 answers

How to test the Functor laws with the checkers library

How do I use the checkers library to test the Functor laws of a simple Parser? import Test.QuickCheck import Test.QuickCheck.Checkers import Test.QuickCheck.Classes import qualified Data.ByteString as BS type Index = Int newtype Parser a = Parser…
Jogger
  • 1,617
  • 2
  • 12
  • 22
6
votes
1 answer

Complete minimal example for using quickCheckAll

I could use a complete example of how to use quickCheckAll. Here's what I've tried so far: In a file A.hs: module A where import Test.QuickCheck prop_a = 1 == 0 check = do return [] $quickCheckAll In another file…
Guillaume Chérel
  • 1,478
  • 8
  • 17
6
votes
1 answer

fscheck doesn't generate random enough data

I'm playing with FsCheck so I have this implementation: let add a b = if a > 100 then failwith "nasty bug" else a + b ...and this FsCheck based test: fun (a:int) -> (add a 0) = a |> Check.QuickThrowOnFailure and the test never fails.…
vidi
  • 2,056
  • 16
  • 34
6
votes
3 answers

How to use QuickCheck to test database related functions?

I need to test a lot of functions that access the database (via Persistent). While I can do this using monadicIO and withSqlitePool it will result in inefficient tests. Each test, not property, but test, will create and destroy the DB pool. How do I…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
6
votes
1 answer

Is it possible to check cases when exception is thrown with QuickCheck?

Suppose I have a function that should calculate some value in one case and throw an exception otherwise. I would like to use QuickCheck to ensure my function behaves correctly, however is not obvious how to perform this sort of check. Is it possible…
Mark Karpov
  • 7,499
  • 2
  • 27
  • 62
6
votes
1 answer

Generate Strings from Grammar in ScalaCheck

In Scala, I have a grammar implemented using the Parser Combinators library. Now, what I want to do is generate random strings given a grammar from the parser combinators library. It seems to me, that what the ScalaCheck library does it somehow the…
Felix
  • 8,385
  • 10
  • 40
  • 59
6
votes
1 answer

QuickCheck: How to combine two generators?

I have two generators, gen_n & gen_arr: gen_n :: Gen Int gen_n = suchThat arbitrary (\i -> i >= 0 && i <= 10) gen_elem :: Gen Int gen_elem = suchThat arbitrary (\i -> i >= 0 && i <= 100) gen_arr :: Gen [Int] gen_arr = listOf gen_elem How can I…
muhuk
  • 15,777
  • 9
  • 59
  • 98