为什么我的先决条件在我的基于属性的测试中被忽略?
我的测试的前提条件如下:
fun rowCount -> rowCount >= 0
因此,我的实际测试是:
[<Fact>]
let ``number of cells in grid equals rowcount squared`` () =
Check.QuickThrowOnFailure <|
fun rowCount -> rowCount >= 0 ==>
fun rowCount -> rowCount |> createGrid
|> Map.toList
|> List.length = rowCount * rowCount
但是,我的测试仍然失败:
结果消息:System.Exception:可证伪,经过 3 次测试(1 次收缩)(StdGen(985619705,296133555)):原始:1 -1 收缩:0 -1
领域:
let createGrid rowCount =
[for x in 0..rowCount-1 do
for y in 0..rowCount-1 do
yield { X=x; Y=y; State=Dead }
]|> List.map (fun c -> (c.X, c.Y), { X=c.X; Y=c.Y; State=Dead })
|> Map.ofList
[更新]
我也试过:
let precondition rowCount =
rowCount >= 0
let ``some property`` rowCount =
precondition rowCount ==> rowCount |> createGrid
|> Map.toList
|> List.length = rowCount * rowCount
[<Fact>]
let ``number of cells in grid equals rowcount squared`` () =
Check.QuickThrowOnFailure <| ``some property``
但是,我收到以下错误:
类型不匹配。期望一个属性 -> 'a 但给定一个 int -> Map<(int * int),Cell> 类型'Property'与类型'int'不匹配