QuickCheck:为什么没有通过测试的功能以及要使用的功能呢?

问题描述 投票:0回答:1

为什么没有QuickCheck的功能类似于hedgehogsuccess?我特别想知道如何转换以下属性:

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中是否有更好的方法来表达上面的属性?

haskell quickcheck haskell-hedgehog
1个回答
0
投票

您可以使用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
© www.soinside.com 2019 - 2024. All rights reserved.