如何基于属性测试一个带有函数列表的函数?
采取以下功能:
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 函数是否基于属性可测试?