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
3
votes
0 answers

How do I write a Hedgehog generator for a wrapped function?

I'm currently working through the book Thinking with Types. In the third chapter Variance, the author provides an exercise in which the reader should implement the functor instance for T1. newtype T1 a = T1 (Int -> a) I found a couple of ways to…
Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91
3
votes
1 answer

How to prevent tested functions from outputting to terminal when using QuickCheck monadicIO

I'm wondering if there's some way to prevent functions from printing to the terminal when they're being tested through GHCI with QuickCheck and monadicIO. For example, say I have the following code: import Test.Hspec import…
nHaskins
  • 805
  • 8
  • 22
3
votes
0 answers

How to use DerivingVia with Arbitrary

I need to write a heck of Arbitrary instances for newtypes. I am trying to cheap on typing and use deriving via GHC extension. My use case complies, but blows up in runtime! GHCi is 8.8.4 import Test.QuickCheck (Gen, elements, listOf, Arbitrary,…
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
3
votes
1 answer

Where do I define Arbitrary instances?

I can't figure out where to define Arbitrary instances for my datatype. If I put it in the package, then the package unnecessarily has to have QuickCheck as a dependency. If I put it in the tests, then other packages can't make use of the instance.…
dspyz
  • 5,280
  • 2
  • 25
  • 63
3
votes
1 answer

How to select a value in a range with QuickCheck?

I have the following code I am using for creating a challenge on the following site : codewars describe "Random cases" $ do it "It should handle random test cases" $ property $ prop_check where prop_check (Positive x) =…
Any3nymous user
  • 216
  • 2
  • 11
3
votes
1 answer

How do I write a QuickCheck property which expects a non-empty list of non-zero numbers?

This is a hack (cogsRpm is a user supplied function which is supposed to match the output of go): propCheck ns = cogsRpm (ns ++ [42]) == go (ns ++ [42]) I added the 42 to stop quickcheck from generating zero length lists. It also could fail still…
Cliff Stamp
  • 531
  • 5
  • 11
3
votes
2 answers

Checkers and EqProp

I am going through the Haskell Book and the chapter on applicatives started using the checkers library for testing. This library introduces the EqProp typeclass, and I don't understand how it differs from Eq. Most of the examples that call for…
tesserakt
  • 3,231
  • 4
  • 27
  • 40
3
votes
2 answers

How to combine Arbitrary and IO monads?

I am trying to write a program which writes to a file a list of data generated by an Arbitrary instance, and I am having trouble combining the Arbitrary and IO monads. A simplified version of what I am trying to do is shown below. main = do let n…
mherzl
  • 5,624
  • 6
  • 34
  • 75
3
votes
1 answer

Arbitrary String generator in Haskell (Test.QuickCheck.Gen)

I am struggling on Real World Haskell Chapter 11 quickCheck generator implementation for a an algebraic data type. Following the book implementation (which was published in 2008), I came up with the following: -- file: ch11/Prettify2.hs module…
mabe02
  • 2,676
  • 2
  • 20
  • 35
3
votes
1 answer

How to generate arbitrary two argument function with QuickCheck?

I am trying to test my implementation of zipWith using QuickCheck. My implementation, myZipWith, I would like to QuickCheck test by comparing to the standard function. Something like: main = do quickCheck (prop_myZipWith :: (Int -> Int -> Int) ->…
mherzl
  • 5,624
  • 6
  • 34
  • 75
3
votes
2 answers

Using QuickCheck to generate multiple arbitrary parameters for a given function

Context I have the following function: prop_SignAndVerify :: (PrivKey a b) => Blind a -> BS.ByteString -> Bool prop_SignAndVerify bsk msg = case verify pk msg sig of Left e -> error e Right b…
plint
  • 75
  • 7
3
votes
1 answer

How to check monadic IO properties with tasty-quickcheck?

How does one test a monadicIO property with tasty-quickcheck? I tried the following, where the testCase is working as expected (which is coming from HUnit), but the testProperty (from QuickCheck) is not compiling. import Test.Common import…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
3
votes
1 answer

How to share test interfaces between Go packages?

Go doesn't share code between test files of different packages, so definitions of test interfaces aren't automatically reused. How can we work around this in practice? Example using testing/quick: foo/foo.go: package foo type Thing int const ( X…
Mike Craig
  • 1,677
  • 1
  • 13
  • 22
3
votes
1 answer

How to write an Arbitrary instance for a type that wraps a function?

I have this type which wraps a function newtype Transaction d e r = Transaction (d -> Either e (d,r)) ...and I want to do quickcheck tests for its Functor & Applicative instances but the compiler complains that it doesn't have an Arbitrary…
vidi
  • 2,056
  • 16
  • 34
3
votes
0 answers

Is it possible to quickcheck functor properties of the function type?

I am trying to implement my own functor instances and quickcheck them, and have run into issues on typeclasses which are not instances of Eq, namely (->) and IO. My attempts result in a No instance for (Eq ...) error. In the (->) case I had run into…
mherzl
  • 5,624
  • 6
  • 34
  • 75