Open brandon-leapyear opened 3 years ago
:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:
And also perhaps
propMatches :: Show a => a -> (a -> Bool) -> Property
propMatches x f = counterexample (show x) (f x)
prop_foo_negative_throws_error1' x =
x < 0 ==> propMatches (foo x) (\case Left Error1{} -> True; _ -> False)
I not-uncommonly find myself writing property tests where the expected result isn't a concrete value I can check equality with, but it should pattern match a certain way.
Two (contrived) examples:
My question is two-fold: is there a current best way to do this that I'm not seeing? If not, can we add helpers for these cases?
My current approach to the first example is to maybe do something like:
which I like better than just doing
True
/False
, becausecounterexample
would show the failing result, just like===
would.My current approach to the second example is using
counterexample
like before:it could also be done like
but that feels a bit roundabout to me.
I think both of these approaches could be improved with simple aliases provided by the
QuickCheck
library, something likewhich would look like