How can I Property-based Test a Function that takes a list of functions?
Take the following function:
let handleAll handlers item =
handlers |> List.collect(fun handler -> handler item)
Additional context is as follows:
let handleAll handlers item =
handlers |> List.collect(fun handler -> handler item)
let handlers = [
handleShipping
handleRoyalty
handleCommission
handleVideo
handleEmail]
(*Client*)
let result = (handlers , Book) ||> handleAll
I tried the following test and then realized that none of my predefined functions get used (obviously) because arbitrary functions are being generated at run-time:
Example:
[handleShipping
handleRoyalty
handleCommission
handleVideo
handleEmail]
My property test is the following:
(*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
Is the handleAll function Property-based testable?