1

プロパティ ベースのテストで前提条件が無視されるのはなぜですか?

私のテストの前提条件は次のとおりです。

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 : Falsifiable、3 回のテスト後 (1 回の縮小) (StdGen (985619705,296133555)): Original: 1 -1 Shrunk: 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' と一致しません

4

1 に答える 1