I have a QuickCheck property that looks like this:
prop42 :: Foo -> Bool
prop42 foo = fn1 foo == fn2 foo
If this property fails, it will print out what foo
was. But I'd really like to know what fn1
and fn2
returned. And if foo
is large, it's kinda non-trivial to generate this information by hand. (I.e., sit there and manually type in the huge wedge of text printed to the Windows console window.)
It's common for testing frameworks to have a thing that compares for equality, and prints out both values if equality didn't hold. But I can't seem to find such a function for QuickCheck...
Take a look at combinators from here. For example, printTestCase
allows to add an arbitrary string to the output of failing cases. A quick example:
prop x = let f = sin x
in printTestCase ("Should be at least " ++ show f) $ x >= sin x
$> quickCheck prop *** Failed! Falsifiable (after 2 tests and 1 shrink): -1.0 Should be at least -0.8414709848078965
Based on the answer from Yuuri, this is what I went with:
(?==?) :: (Eq x, Show x) => x -> x -> Property
x ?==? y =
printTestCase ("Left: " ++ show x) $
printTestCase ("Right: " ++ show y) $
x == y
Now I can write things like
prop42 :: Foo -> Prop
prop42 foo = fn1 foo ?==? fn2 foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With