0

I'm trying to write a property based test that is verifying congruence of equality.

To do that I need to be able to run it by providing 2 values of the type Gen a:

fun_cong_equality
:: forall m a
. (Monad m, Arg a, Vary a, Eq a, Show a)
=> Gen a
-> Gen a
-> PropertyT m ()
fun_cong_equality genA genB = do
a <- forAll genA
b <- forAll genB
f <- forAllFn $ fn @a genA
f a === f b

prop_fun_cong_equality :: Property
prop_fun_cong_equality =
property $
    fun_cong_equality $ -- TODO need to pass 2 `Gen a` values as arguments

My question is: how do I create values of type Gen a?

Note: the property based test is not finished, it still need to filter for generated values that are equal.

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • 1
    The question is: what is `a`? You can make `Gen`s by using the `MkGen` constructor (http://hackage.haskell.org/package/QuickCheck-2.13.2/docs/Test-QuickCheck-Gen.html#t:Gen). But you can not just generate *sensical* `Gen`s for each type (although you can indeed to some extent automate this). – Willem Van Onsem Aug 17 '19 at 15:20
  • @WillemVanOnsem I think I get what you mean. My actual issue is completing the property based test above. If I'm asking a wrong question please tell me. What would be the solution? – Răzvan Flavius Panda Aug 17 '19 at 15:28
  • I don't understand how this property holds. You would generate a random `a`, another random `a`, a random function from `a -> a` and hope that when you apply the function the results would coincide? Ah, just saw your note :-). Maybe the property you want to write is `if a == b then f a === f b else success`? – Eric Aug 17 '19 at 15:48
  • @Eric yup, this is my final implementation: https://github.com/qfpl/hedgehog-fn/pull/6/commits/5d1772d460349d0dc7756af8b4bebd7e1a2fd014#diff-46d8b9d3356a1a6adad01917f90baf8fR29-R41 – Răzvan Flavius Panda Aug 17 '19 at 18:33

1 Answers1

0

What I needed was a value of a type that has instances of the typeclasses Vary, Arg, Eq and Show.

Int happens to meet that criteria.

A solution is to use:

fun_cong_equality (Gen.int (Range.linear 1 100)) (Gen.int (Range.linear 1 100))
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169