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
F# 失败[可测试](可测试属性) C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0):at Tests.Multi。。 1次通过,1次失败,0次跳过,耗时0.82秒(xUnit.net 2.1.0构建3179)。 < /代码>_F#_Fscheck - Fatal编程技术网

F# 失败[可测试](可测试属性) C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0):at Tests.Multi。。 1次通过,1次失败,0次跳过,耗时0.82秒(xUnit.net 2.1.0构建3179)。 < /代码>

F# 失败[可测试](可测试属性) C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0):at Tests.Multi。。 1次通过,1次失败,0次跳过,耗时0.82秒(xUnit.net 2.1.0构建3179)。 < /代码>,f#,fscheck,F#,Fscheck,如果您愿意,那么您也可以考虑使用纯FsCheck并完全去除fsChek.xUng: module Tests open FsCheck let [<Xunit.Fact>] ``Multiply Identity (passing)`` () = Arb.Default.DoNotSizeInt64 () |> Prop.forAll <| fun (DoNotSize x) -> x * 1L = x |&g

如果您愿意,那么您也可以考虑使用纯FsCheck并完全去除fsChek.xUng:

module Tests

open FsCheck

let [<Xunit.Fact>] ``Multiply Identity (passing)`` () = 
    Arb.Default.DoNotSizeInt64 ()
    |> Prop.forAll
    <| fun (DoNotSize x) ->
        x * 1L = x
    |> Check.QuickThrowOnFailure

let [<Xunit.Fact>] ``Multiply Identity (failing)`` () = 
    Arb.Default.DoNotSizeInt64 ()
    |> Prop.forAll
    <| fun (DoNotSize x) ->
        x * 1L = -1L |@ sprintf "(%A should equal %A)" (x * 1L) x
    |> Check.QuickThrowOnFailure
模块测试
开放式FsCheck
让[]`Multiply Identity(passing)``()=
Arb.Default.DoNotSizeInt64()
|>道具
x*1L=x
|>检查。快速排除故障
让[]``乘法标识(失败)``()=
Arb.Default.DoNotSizeInt64()
|>道具
x*1L=-1L |@sprintf“(%A应等于%A)”(x*1L)x
|>检查。快速排除故障
xUnit.net testrunner输出:

------ Test started: Assembly: Library1.dll ------

Test 'Tests.Multiply Identity (failing)' failed: System.Exception:
    Falsifiable, after 1 test (2 shrinks) (StdGen (2100552947,296238694)):

Label of failing property: (0L should equal 0L)
Original:
DoNotSize -23143L
Shrunk:
DoNotSize 0L

    at <StartupCode$FsCheck>.$Runner.get_throwingRunner@365-1.Invoke(String me..
    at <StartupCode$FsCheck>.$Runner.get_throwingRunner@355.FsCheck-IRunner-On..
    at FsCheck.Runner.check[a](Config config, a p)
    at FsCheck.Check.QuickThrowOnFailure[Testable](Testable property)
    C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0): at Tests.Multi..

1 passed, 1 failed, 0 skipped, took 0.82 seconds (xUnit.net 2.1.0 build 3179).
----测试已启动:程序集:Library1.dll------
测试“Tests.Multiply Identity(failing)”失败:系统。异常:
可伪造,在1次试验(2次收缩)后(StdGen(2100552947296238694)):
失败属性的标签:(0L应等于0L)
原件:
DoNotSize-23143L
缩小:
DoNotSize 0L
$Runner.get_throwingRunner@365-1.调用(字符串me.)。。
$Runner.get_throwingRunner@355.FsCheck-伊鲁纳在。。
在FsCheck.Runner.check[a](配置,一个p)
在FsCheck.Check.QuickThrowOnFailure[可测试](可测试属性)
C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0):at Tests.Multi。。
1次通过,1次失败,0次跳过,耗时0.82秒(xUnit.net 2.1.0构建3179)。


如此简单?因此没有继承、属性等?尝试…(编辑:尝试,立即生效,谢谢!)感谢您的额外解释,这是有意义的。但是,
静态成员m()
从未被调用(我尝试使用
printfn
语句来确定)。这很可能是一个FsCheck错误(更可能是我的错误;),但如上所述,它从未命中。我找到了它。我需要打开
DoNotSize
类型,它没有被识别为所审查函数的请求类型。即,现在的定义是
Arb.Default.DoNotSizeInt64().Generator |>Gen.map DoNotSize.Unwrap |>Arb.fromGen
。这么简单?所以没有继承、属性等?尝试…(编辑:尝试,立即生效,谢谢!)感谢您的额外解释,这很有意义。但是,
静态成员m()
从未被调用(我尝试使用
printfn
语句只是为了确保)。这很可能是一个FsCheck错误(更可能是我的错误;),但如上所述,它从未出现过。我找到了它。我需要打开
DoNotSize
类型,它没有被识别为所审查函数的请求类型。即,现在的定义是
Arb.Default.DoNotSizeInt64().Generator |>Gen.map DoNotSize.Unwrap |>Arb.fromGen
。我喜欢它。只是尝试了一下。我担心测试是
单元
,冗长不起作用(但它起作用了,我看到了随机的int64)。尽管我仍然好奇如何解决最初的问题(Fyodor使它可以运行,但没有调用该方法),从几个角度来看,这似乎是一个更好的方法,谢谢。顺便说一句,有趣的是,100个测试中只有5个测试使用了肯定的
int64
,其余的都是否定的。这会持续几次运行。这是设计的吗?(顺便说一句,原来的问题解决了,我忘了打开,你的类型安全提示帮助了)@Abel现在你问了,这个生成器看起来确实有点歪斜。我不知道为什么,但我提出了一个问题,问这个问题:+1我也喜欢这种方法,它也更接近所有其他基于快速检查的克隆。你甚至可以去掉
[]
属性,并使用测试中的
检查
模块中的函数。
[]
是xUnit.net发现基于属性的测试所需的全部内容,那么。:@NikosBaxevanis不需要将整个属性导入
检查.QuickThrowOnFailure
?上次我尝试这种方法时,我觉得有点尴尬,但已经有一段时间了。。。考虑在这里增加你的选择作为答案;我喜欢。我试过了。我担心测试是
unit
,冗长的代码不起作用(但它起作用了,我看到了随机的int64)。虽然我仍然对如何解决最初的问题感到好奇(Fyodor使其可运行,但没有调用该方法),但从多个角度来看,这似乎是一个更好的方法,谢谢。顺便说一句,有趣的是,100个测试中只有大约5个使用肯定的
int64
,其余都是否定的。这种情况持续了好几次。这是故意的吗?(顺便说一句,原来的问题解决了,我忘记打开了,你的类型安全提示帮了忙)@Abel现在你问了,那个生成器看起来确实是歪斜的。我不知道为什么会这样,但我已经提出了一个问题,询问这一点:+1我也更喜欢这种方法,它也更接近所有其他基于快速检查的克隆。您甚至可以去掉
[]
属性,在测试中使用
检查
模块中的函数<代码>[]
是xUnit.net发现基于属性的测试所需的全部内容,然后:@NikosBaxevanis不要求您将整个属性导入
Check.QuickThrowOnFailure
?上次我尝试这种方法时,我觉得有点尴尬,但已经有一段时间了。。。考虑在这里增加你的选择作为答案;实际上,我运行了一个NUnit+FsCheck,但希望与
属性
相结合,以使其更易于配置,并在我的测试运行程序中获得更有意义的输出(OT:而且xUnit对我的场景没有用,它不做开箱即用的stdout和stderr编写,声称它是以多线程的方式(事实上是这样的)另一方面,管道方法在NUnit runner中有一个奇怪的副作用(仅是NUnit的标准方法,而不是NCrunch):它报告它在0.12s内运行测试,但仅在10+秒后返回(或更长时间,从10秒起开始明显)
 System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.Exception : No instances found on type Tests.Arithmetic.MyArb. Check that the type is public and has public static members with the right signature.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at FsCheck.Runner.checkMethod(Config config, MethodInfo m, FSharpOption`1 target) in C:\Users\Kurt\Projects\FsCheck\FsCheck\src\FsCheck\Runner.fs:line 318
   at FsCheck.NUnit.Addin.FsCheckTestMethod.runTestMethod(TestResult testResult) in C:\Users\Kurt\Projects\FsCheck\FsCheck\src\FsCheck.NUnit.Addin\FsCheckTestMethod.fs:line 100
type TestArbitrary2 =
   static member NegativeDouble() =
       Arb.Default.Float()
       |> Arb.mapFilter (abs >> ((-) 0.0)) (fun t -> t <= 0.0)
 type MyArb() =
    static member m() = Arb.Default.DoNotSizeInt64()
type Eq<'a> = { eq: 'a -> 'a -> bool; neq: 'a -> 'a -> bool }

type EqInstances() =
   static member ForInt() : Eq<int> = 
      { eq = (=); neq = (<>) }

   static member ForMyCustomType() : Eq<MyCustomType> = 
      { eq = fun a b -> a.CompareTo(b) = 0
        neq = fun a b -> a.CompareTo(b) <> 0 }
open FsCheck
open FsCheck.Xunit

[<Property>]
let MultiplyIdentity () =
    Arb.Default.DoNotSizeInt64 () |> Prop.forAll <| fun (DoNotSize x) -> x * 1L = x
module Tests

open FsCheck

let [<Xunit.Fact>] ``Multiply Identity (passing)`` () = 
    Arb.Default.DoNotSizeInt64 ()
    |> Prop.forAll
    <| fun (DoNotSize x) ->
        x * 1L = x
    |> Check.QuickThrowOnFailure

let [<Xunit.Fact>] ``Multiply Identity (failing)`` () = 
    Arb.Default.DoNotSizeInt64 ()
    |> Prop.forAll
    <| fun (DoNotSize x) ->
        x * 1L = -1L |@ sprintf "(%A should equal %A)" (x * 1L) x
    |> Check.QuickThrowOnFailure
------ Test started: Assembly: Library1.dll ------

Test 'Tests.Multiply Identity (failing)' failed: System.Exception:
    Falsifiable, after 1 test (2 shrinks) (StdGen (2100552947,296238694)):

Label of failing property: (0L should equal 0L)
Original:
DoNotSize -23143L
Shrunk:
DoNotSize 0L

    at <StartupCode$FsCheck>.$Runner.get_throwingRunner@365-1.Invoke(String me..
    at <StartupCode$FsCheck>.$Runner.get_throwingRunner@355.FsCheck-IRunner-On..
    at FsCheck.Runner.check[a](Config config, a p)
    at FsCheck.Check.QuickThrowOnFailure[Testable](Testable property)
    C:\Users\Nikos\Desktop\Library1\Library1\Library1.fs(15,0): at Tests.Multi..

1 passed, 1 failed, 0 skipped, took 0.82 seconds (xUnit.net 2.1.0 build 3179).