如何基于属性测试采用函数列表的函数?
采取以下功能:
let handleAll handlers item =
handlers |> List.collect(fun handler -> handler item)
附加上下文如下:
let handleAll handlers item =
handlers |> List.collect(fun handler -> handler item)
let handlers = [
handleShipping
handleRoyalty
handleCommission
handleVideo
handleEmail]
(*Client*)
let result = (handlers , Book) ||> handleAll
我尝试了以下测试,然后意识到我的预定义函数都没有被使用(显然),因为在运行时生成了任意函数:
例子:
[handleShipping
handleRoyalty
handleCommission
handleVideo
handleEmail]
我的属性测试如下:
(*Property Tests*)
open FsCheck
open FsCheck.Xunit
[<Property(MaxTest = 1000, QuietOnSuccess = true)>]
let ``handleAll always returns elements for at least (1) handler`` () =
(Arb.generate<(Item -> Command list) list>
|> Gen.filter(List.isEmpty >> not) , Arb.generate<Item>)
||>Gen.map2(fun handlers item -> handlers , item)
|> Arb.fromGen
|> Prop.forAll
<| fun (handlers , item) ->
(handlers , item)
||> handleAll
|> List.isEmpty |> not
handleAll函数是基于属性的可测试的吗?