Files
raft-fable/Raft.Test/TestNetworkAction.fs
Smaug123 590e123573
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
Modernise
2025-09-08 23:52:47 +01:00

39 lines
1.1 KiB
Forth

namespace Raft.Test
open FsCheck.FSharp
open Raft
open System.Collections.Generic
open NUnit.Framework
open FsCheck
open FsUnitTyped
[<TestFixture>]
module TestNetworkAction =
[<Test>]
let ``Generator hits all cases`` () =
let populate (cases : HashSet<_>) (a : NetworkAction<'a>) : bool =
cases.Add (a.GetType ()) |> ignore
true
let authoritativeCases = HashSet ()
Check.QuickThrowOnFailure (populate authoritativeCases)
let authoritativeCases =
authoritativeCases |> Seq.map (fun ty -> ty.FullName) |> Set.ofSeq
let ourCases = HashSet ()
populate ourCases
|> Prop.forAll (Arb.fromGen (NetworkAction.generate 5))
|> Check.QuickThrowOnFailure
let ourCases = ourCases |> Seq.map (fun ty -> ty.FullName) |> Set.ofSeq
Set.difference authoritativeCases ourCases |> shouldBeEmpty
// Sanity check that we are actually measuring what we think we're measuring
ourCases
|> Seq.map (fun name -> name.Split ('[') |> Array.head)
|> Set.ofSeq
|> shouldContain "Raft.NetworkAction`1+DropMessage"