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 specialPair
case xs of
x:_ -> x /== 3
_ -> success
In QuickCheck if I use =/= then I'm forced to return something of type Property, and there seem to be no constant function to return a passing property.
So I either have to resort to the Bool type:
prop_specialPair :: SpecialPair -> Bool
prop_specialPair SpecialPair { xs } =
case xs of
x:_ -> x == 3
_ -> True
Or use a very awkward encoding for success, e.g.:
prop_specialPair :: SpecialPair -> Property
prop_specialPair SpecialPair { xs } =
case xs of
x:_ -> x =/= 3
_ -> True === True
Are there better ways to express the property above in QuickCheck?
You can use the
propertyfunction from theTestableclass, and variousTestableinstances to create aPropertywith whatever characteristics you need.For example,
property ()always succeeds. For another example,property (b :: Bool)succeeds iffb == True.So you could do this for example:
Or you can make it more explicit by using the
Testable Resultinstance and the valuesucceeded :: Result: