Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 如何在Expecto上注册自己的FsCheck生成器_F#_Fscheck_Property Based Testing_Expecto - Fatal编程技术网

F# 如何在Expecto上注册自己的FsCheck生成器

F# 如何在Expecto上注册自己的FsCheck生成器,f#,fscheck,property-based-testing,expecto,F#,Fscheck,Property Based Testing,Expecto,我已经建立了我的发电机类型,生成三的倍数。我想用它来测试Expecto。如何注册此生成器并告诉我的测试使用它 let multipleOfThree n = n * 3 type ThreeGenerator = static member ThreeMultiple() = Arb.generate<NonNegativeInt> |> Gen.map (fun (NonNegativeInt n) -> multipleOfT

我已经建立了我的发电机类型,生成三的倍数。我想用它来测试Expecto。如何注册此生成器并告诉我的测试使用它

let multipleOfThree n = n * 3

type ThreeGenerator =
    static member ThreeMultiple() =
        Arb.generate<NonNegativeInt>
        |> Gen.map (fun (NonNegativeInt n) -> multipleOfThree n)
        |> Gen.filter (fun n -> n > 0)
        |> Arb.fromGen
n=n*3的倍数
三型发电机=
静态成员ThreeMultiple()=
生成
|>Gen.map(乐趣(非负元素n)->三重元素n的倍数)
|>发电机过滤器(乐趣n->n>0)
|>弗罗姆根

我找到了自己的answare。用于在Expecto中注册发电机

    let multipleOfThree =
    { FsCheckConfig.defaultConfig with
          arbitrary = [ typeof<ThreeGenerator> ] }
设三个倍数=
{FsCheckConfig.defaultConfig与
任意=[typeof]}
并且可以在您的测试中使用

testPropertyWithConfig multipleOfThree "test with your generator "
          <| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"
testPropertyWithConfig multipleOfThree“使用生成器进行测试”
Expect.equal(测试x下的函数)“Expected”错误消息

我找到了自己的answare。用于在Expecto中注册发电机

    let multipleOfThree =
    { FsCheckConfig.defaultConfig with
          arbitrary = [ typeof<ThreeGenerator> ] }
设三个倍数=
{FsCheckConfig.defaultConfig与
任意=[typeof]}
并且可以在您的测试中使用

testPropertyWithConfig multipleOfThree "test with your generator "
          <| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"
testPropertyWithConfig multipleOfThree“使用生成器进行测试”
Expect.equal(测试x下的函数)“Expected”错误消息

您可以使用
PositiveInt
而不是使用
Gen.filter(fun->n>0)
非负性Int
,您可以使用
PositiveInt
而不是使用
Gen.filter(fun->n>0)
非负性Int