为什么没有QuickCheck
的功能类似于hedgehog
的success
?我特别想知道如何转换以下属性:
success
在prop_specialPair :: Property
prop_specialPair = property $ do
(_, xs) <- forAll specialPair
case xs of
x:_ -> x /== 3
_ -> success
中,如果我使用QuickCheck
,那么我将被迫返回类型为=/=
的东西,并且似乎没有常量函数返回传递的属性。
所以我要么不得不求助于=/=
类型:
Property
或对Bool
使用非常笨拙的编码,例如:
prop_specialPair :: SpecialPair -> Bool
prop_specialPair SpecialPair { xs } =
case xs of
x:_ -> x == 3
_ -> True
[success
中是否有更好的方法来表达上面的属性?
您可以使用prop_specialPair :: SpecialPair -> Property
prop_specialPair SpecialPair { xs } =
case xs of
x:_ -> x =/= 3
_ -> True === True
类中的QuickCheck
函数,并使用各种property
实例通过创建一个Testable
。
例如,Testable
总是成功。再举一个例子,Property
仅在property ()
时成功。
因此,您可以这样做:
property (b :: Bool)
或者您可以通过使用b == True
实例和值prop_specialPair :: SpecialPair -> Property
prop_specialPair SpecialPair { xs } =
case xs of
x:_ -> x =/= 3
_ -> property ()
使它更加明确:
Testable Result