値が判別共用体の特定のケースであることを確認したいのですが、含まれているデータも確認する必要はありません。私の動機は、各単体テストで 1 つのことだけをテストすることです。
例は次のとおりです (最後の 2 行でコンパイル エラーが発生します)。
module MyState
open NUnit.Framework
open FsUnit
type MyState =
| StateOne of int
| StateTwo of int
let increment state =
match state with
| StateOne n when n = 10 -> StateTwo 0
| StateOne n -> StateOne (n + 1)
| StateTwo n -> StateTwo (n + 1)
[<Test>]
let ``incrementing StateOne 10 produces a StateTwo`` ()=
let state = StateOne 10
(increment state) |> should equal (StateTwo 0) // works fine
(increment state) |> should equal (StateTwo _) // I would like to write this...
(increment state) |> should be instanceOfType<StateTwo> // ...or this
これは FsUnit で実行できますか?
私はこの答えを知っていますが、ケースごとに一致する関数を記述する必要はありません (私の実際のコードでは、2 つ以上あります)。