Questions tagged [haskell-hedgehog]

Hedgehog is a property-based testing system, Haskell-Hedgehog is the very same testing system for Haskell. Use this tag for questions about the testing system, not for questions about the programming language Haskell.

21 questions
7
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,603
  • 1
  • 20
  • 30
7
votes
1 answer

Difference between generating random input through 'Gen' or through 'forAll' in Hedgehog

Suppose, I want to test the following associativity property for Sum with the help of hedgehog library in Haskell: a <> (b <> c) ≡ (a <> b) <> c I have actually two ways to generate random input. 1. Generate all in Gen (using Gen's Applicative and…
7
votes
1 answer

Safest way to generate random GADT with Hedgehog (or any other property-based testing framework)

I have GADT like this one: data TType a where TInt :: TType Int TBool :: TType Bool I want to have a function like this one: genTType :: Gen (TType a) Which can generate random constructor of TType type. I can do this simply by creating…
Shersh
  • 8,297
  • 3
  • 27
  • 54
4
votes
1 answer

Why does this Hedgehog generator not shrink faster?

I made a Hedgehog generator that generates arbitrary 256-bit values in the following way: genWord256 :: Gen Word256 genWord256 = do bytes <- Gen.integral (Range.linear 0 31) let lo = 2 ^ (8 * bytes) hi = 2 ^ (8 * (bytes + 1)) pred <$>…
Simon Shine
  • 14,573
  • 1
  • 40
  • 60
4
votes
1 answer

Haskell hedgehog-fn custom function generator

When using hedgehog-fn is it possible to create function generators that generate functions meeting a specific criteria? For example: would it be possible to have a function generator that only generates bijective functions?
Răzvan Flavius Panda
  • 20,376
  • 13
  • 101
  • 153
4
votes
0 answers

How to use `GenT` in `hedgehog`

In the hedgehog library, there is a GenT monad transformer. However the forAll function takes a Gen type. There is a forAllT function, but it is in an Internal module. So if I'd like to use a generator monad transformer with a specific monad (say…
Damian Nadales
  • 4,603
  • 1
  • 20
  • 30
3
votes
1 answer

Dependent shrinking in QuickCheck

I'm faced with the problem of writing a shrinking function for a generator that depends of the value (s) output by another one. Basically a generator of the form: do a <- genA b <- f a pure $! g a b where genA :: Gen a, f :: a -> Gen b g :: a…
Damian Nadales
  • 4,603
  • 1
  • 20
  • 30
3
votes
0 answers

Running a stateful Hedgehog generator

I've taken the following tree generator: genTree0 :: MonadGen m => m (Tree String) genTree0 = Gen.recursive Gen.choice [ Node "X" [] ] [ Node "X" <$> Gen.list (Range.linear 0 20) genTree0 ] and rewritten it into a stateful one: genTree1…
Simon Shine
  • 14,573
  • 1
  • 40
  • 60
3
votes
1 answer

Is there a corresponding optic for higher-order traversable functors?

Hedgehog has an HTraversable class defined like this: -- | Higher-order traversable functors. -- class HTraversable t where htraverse :: Applicative f => (forall a. g a -> f (h a)) -> t g -> f (t h) Which is used with their Var type for…
2
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,004
  • 5
  • 49
  • 87
2
votes
1 answer

Returning a list and getting to the items in Hedgehog state machine

I have a model for a state machine that is newtype State (v :: * -> *) = State (M.Map (Var UUID v) DataPerItem) deriving (Eq, Show) I then have a Command gen exec [Update update] with exec returning a list of UUID, i.e. it has type exec ::…
Magnus
  • 4,444
  • 1
  • 30
  • 47
2
votes
0 answers

What is the effect of freeze in the definition of Hedgehog.Gen.list

Hedgehog.Gen.list is defined as follows: -- | Generates a list using a 'Range' to determine the length. -- list :: MonadGen m => Range Int -> m a -> m [a] list range gen = sized $ \size -> (traverse snd =<<) . ensure (atLeast $…
Damian Nadales
  • 4,603
  • 1
  • 20
  • 30
2
votes
2 answers

Why the does this shrink tree looks the way it does when using filter

I'm trying to understand what is the effect that filter has in the shrink tree of a generator when using hedgehog integrated shrinking. Consider the following function: {-# LANGUAGE OverloadedStrings #-} import Hedgehog import qualified…
1
vote
0 answers

Run a property-test's iterations in parallel?

I have a property-based test (in Hedgehog), that does the following: Push an item to a remote service that queues it Poll the remote service to figure out when the item was processed Assert some properties on the item's processing results The test…
Saurabh Nanda
  • 5,737
  • 5
  • 30
  • 52
1
vote
0 answers

How can I define a generator in hedgehog that generates lists of certain length?

I try to create a list of integers in f# hedgehog. the list should have between 10 and 20 elements and hold integers in the range between 0 and 5. Gen.list (Range.linear 10 20) (Gen.int <| Range.constant 0 5) |> Gen.printSample throws an…
citykid
  • 7,920
  • 4
  • 46
  • 71
1
2