Stop propagating parse errors throughout the tests
This commit is contained in:
parent
109ebde64a
commit
a741938f89
3 changed files with 22 additions and 25 deletions
|
|
@ -59,13 +59,11 @@ type FakeHome(now: DateTime) =
|
||||||
|
|
||||||
member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState
|
member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState
|
||||||
|
|
||||||
member _.Interact(interaction: Interaction) : Result<unit, ParseEventError> =
|
member _.Interact(interaction: Interaction) =
|
||||||
result {
|
|
||||||
match interaction with
|
match interaction with
|
||||||
| HumanInteraction(LightTurnedOn light) ->
|
| HumanInteraction(LightTurnedOn light) ->
|
||||||
friendlyNameToFakeLight[light.FriendlyName].TurnOn()
|
friendlyNameToFakeLight[light.FriendlyName].TurnOn()
|
||||||
|
|
||||||
do!
|
|
||||||
{ Topic = "zigbee2mqtt/bridge/event"
|
{ Topic = "zigbee2mqtt/bridge/event"
|
||||||
Payload =
|
Payload =
|
||||||
$@"{{
|
$@"{{
|
||||||
|
|
@ -74,8 +72,7 @@ type FakeHome(now: DateTime) =
|
||||||
}}" }
|
}}" }
|
||||||
|> nightLightStateMachine.SendMessage
|
|> nightLightStateMachine.SendMessage
|
||||||
| HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff()
|
| HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff()
|
||||||
| TimeChanged time -> do! nightLightStateMachine.ChangeTime time
|
| TimeChanged time -> nightLightStateMachine.ChangeTime time
|
||||||
|
|
||||||
nightLightStateMachine.TransmittedCommands |> Seq.iter processCommand
|
nightLightStateMachine.TransmittedCommands |> Seq.iter processCommand
|
||||||
nightLightStateMachine.ClearTransmittedCommands()
|
nightLightStateMachine.ClearTransmittedCommands()
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,18 @@ type NightLightStateMachine(now: DateTime) =
|
||||||
|
|
||||||
let transmittedCommands = new List<Message>()
|
let transmittedCommands = new List<Message>()
|
||||||
|
|
||||||
|
let assertIsOk (result: Result<unit, 'a>) : unit =
|
||||||
|
match result with
|
||||||
|
| Ok() -> ()
|
||||||
|
| Error error -> failwith $"Expected Ok, got Error {error}"
|
||||||
|
|
||||||
let sendEvent event =
|
let sendEvent event =
|
||||||
result {
|
result {
|
||||||
let! newState, commands = onEventReceived state event
|
let! newState, commands = onEventReceived state event
|
||||||
state <- newState
|
state <- newState
|
||||||
transmittedCommands.AddRange commands
|
transmittedCommands.AddRange commands
|
||||||
}
|
}
|
||||||
|
|> assertIsOk
|
||||||
|
|
||||||
member _.TransmittedCommands = transmittedCommands.AsReadOnly()
|
member _.TransmittedCommands = transmittedCommands.AsReadOnly()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,9 @@ module NightLight.Core.Tests.NightLightTests
|
||||||
|
|
||||||
open FsCheck.Xunit
|
open FsCheck.Xunit
|
||||||
|
|
||||||
let private assertIsOk (result: Result<unit, 'a>) : unit =
|
|
||||||
match result with
|
|
||||||
| Ok() -> ()
|
|
||||||
| Error error -> failwith $"Expected Ok, got Error {error}"
|
|
||||||
|
|
||||||
[<Property(Arbitrary = [| typeof<Arbitraries> |])>]
|
[<Property(Arbitrary = [| typeof<Arbitraries> |])>]
|
||||||
let ``Brightness should always be under 255`` (fakeHome: FakeHome) (interactions: Interaction list) =
|
let ``Brightness should always be under 255`` (fakeHome: FakeHome) (interactions: Interaction list) =
|
||||||
interactions
|
interactions |> Seq.iter (fun interaction -> fakeHome.Interact interaction)
|
||||||
|> Seq.iter (fun interaction -> fakeHome.Interact interaction |> assertIsOk)
|
|
||||||
|
|
||||||
fakeHome.LightStates
|
fakeHome.LightStates
|
||||||
|> Seq.choose (fun (_, state) ->
|
|> Seq.choose (fun (_, state) ->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue