我有这个 fscheck nunit 测试,它生成两条记录,然后我必须更新这些记录,以便两条记录始终具有不同的 Direction 属性值
[<Property( Verbose = true )>]
let ``calculate Net Worth 2`` (first:Bill,second:Bill) =
let owing = { first with Direction = Out }
let payCheck = { second with Direction = In }
let compositeBill = {
Bills = [| owing; payCheck |]
}
let netWorth = calculateNetWorth compositeBill
Assert.AreEqual(payCheck.Amount - owing.Amount,netWorth)
我不想手动设置 Direction = In 或 Direction = In ,我想使用生成器来指定它。
这样的发电机会是什么样子?
我想留下这样的代码
[<Property( Verbose = true )>]
let ``calculate Net Worth 2`` (first:Bill,second:Bill) =
let compositeBill = {
Bills = [| owing; payCheck |]
}
let netWorth = calculateNetWorth compositeBill
Assert.AreEqual(payCheck.Amount - owing.Amount,netWorth)
这是我没有运气的尝试
type BillsGen =
static member Bill () =
let debit =
Arb.generate<Bill>
|> Gen.map (fun dt -> { dt with Direction = Out} )
let credit =
Arb.generate<Bill>
|> Gen.map (fun dt -> { dt with Direction = In} )
Gen.oneof[ debit; credit ]
[<SetUp>]
let setup () =
do Arb.register<BillsGen>() |> ignore
谢谢
这是我的一些类型
type Direction =
| In
| Out
type Bill = {
Direction : Direction
}
type CompositeBill = {
Bills : Bill []
}