diff --git a/NightLight.Core.Tests/FakeHome.fs b/NightLight.Core.Tests/FakeHome.fs index c7bffd9..54bcb7a 100644 --- a/NightLight.Core.Tests/FakeHome.fs +++ b/NightLight.Core.Tests/FakeHome.fs @@ -44,8 +44,6 @@ type FakeLight(light: Light) = color <- newColor type FakeHome(now: DateTime) = - let mutable time = now - let mutable nightLightStateMachine = NightLightStateMachine now let assertIsOkAndGet result = @@ -95,8 +93,6 @@ type FakeHome(now: DateTime) = commands |> Seq.iter processCommand nightLightStateMachine <- newState - member _.Time = time - member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState member _.Interact(interaction: Interaction) = @@ -113,9 +109,7 @@ type FakeHome(now: DateTime) = |> ReceivedZigbeeEvent |> sendEvent | HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff() - | TimeChanged newTime -> - time <- newTime - newTime |> Event.TimeChanged |> sendEvent + | TimeChanged newTime -> newTime |> Event.TimeChanged |> sendEvent type FakeHome with member this.Interact(interactions: Interaction seq) = interactions |> Seq.iter this.Interact @@ -127,9 +121,3 @@ type FakeHome with | On(brightness, color) -> Some(light, brightness, color) | Off -> None) |> Seq.forall condition - - member this.IsDay() = - this.Time.TimeOfDay >= TimeSpan.FromHours 5.5 - && this.Time.TimeOfDay < TimeSpan.FromHours 20.5 - - member this.IsNight() = not (this.IsDay()) diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index e74a2a0..e1243ba 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -4,6 +4,26 @@ open System 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 + [ |])>] type NightLightTests() = [] @@ -17,7 +37,7 @@ type NightLightTests() = let fakeHome = FakeHome now fakeHome.Interact interactions - fakeHome.IsNight() + InteractionsHelpers.isNightAfter interactions ==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red) [] @@ -25,5 +45,5 @@ type NightLightTests() = let fakeHome = FakeHome now fakeHome.Interact interactions - fakeHome.IsDay() + InteractionsHelpers.isDayAfter interactions ==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)