Re-write tests to avoid ==>

This commit is contained in:
Sven van Heugten 2026-01-05 19:49:06 +01:00
parent 4c22b27805
commit f787c2aa4e
5 changed files with 73 additions and 61 deletions

View file

@ -1,31 +1,9 @@
namespace NightLight.Core.Tests
open System
open NightLight.Core.Core
open NightLight.Core.Tests.ArbitraryInteractionLists
open FsCheck.Xunit
open FsCheck.FSharp
module InteractionsHelpers =
let getTimeAfter interactions =
interactions
|> Seq.choose (fun interaction ->
match interaction with
| TimeChanged time -> Some time
| _ -> None)
|> Seq.tryLast
|> function
| Some time -> time
| None -> failwith "Time wasn't changed"
let isDayAfter interactions =
let time = getTimeAfter interactions
time.TimeOfDay >= TimeSpan.FromHours 5.5
&& time.TimeOfDay < TimeSpan.FromHours 20.5
let isNightAfter = not << isDayAfter
[<Properties(Arbitrary = [| typeof<Arbitraries> |])>]
type NightLightTests() =
let createFakeHomeWithNightLightAndInteract (interactions: Interaction list) =
let mutable nightLightStateMachine = NightLightStateMachine()
@ -43,16 +21,12 @@ type NightLightTests() =
fakeHome
[<Property>]
[<Property(Arbitrary = [| typeof<ArbitraryInteractionsListThatEndsDuringTheNight> |])>]
let ``Lights should be red during the night`` (interactions: Interaction list) =
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
InteractionsHelpers.isNightAfter interactions
==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
[<Property>]
[<Property(Arbitrary = [| typeof<ArbitraryInteractionsListThatEndsDuringTheDay> |])>]
let ``Lights should be white or yellow during the day`` (interactions: Interaction list) =
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
InteractionsHelpers.isDayAfter interactions
==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)