Store a lot less state
This commit is contained in:
parent
3507385d6c
commit
3913522cc3
3 changed files with 49 additions and 70 deletions
|
|
@ -36,12 +36,17 @@ let doesLightHavePowerAfterInteractions light interactions =
|
|||
|> Seq.tryLast
|
||||
|> Option.defaultValue false
|
||||
|
||||
let tryGetLastRemoteInteraction interactions =
|
||||
let tryGetLastBedroomRemoteInteraction interactions =
|
||||
interactions
|
||||
|> Seq.indexed
|
||||
|> Seq.choose (fun interaction ->
|
||||
|> Seq.choose (fun (index, interaction) ->
|
||||
match interaction with
|
||||
| index, Interaction.RemoteInteraction remoteInteraction -> Some(index, remoteInteraction)
|
||||
| Interaction.RemoteInteraction remoteInteraction ->
|
||||
match remoteInteraction with
|
||||
| RemotePressedOnButton
|
||||
| RemotePressedOffButton
|
||||
| RemotePressedLeftButton -> Some(index, remoteInteraction)
|
||||
| RemotePressedRightButton -> None
|
||||
| _ -> None)
|
||||
|> Seq.tryLast
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ type NightLightTests() =
|
|||
|> Prop.label fakeHome.Label
|
||||
|> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0)
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |])>]
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |], MaxTest = 500)>]
|
||||
let ``All lights should either be off or have a brightness that fits its color`` (interactions: Interaction list) =
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
let time = getTimeAfterInteractions interactions |> _.TimeOfDay
|
||||
|
||||
let alarm =
|
||||
hasNewDayStartedSince interactions (tryGetLastRemoteInteraction interactions)
|
||||
hasNewDayStartedSince interactions (tryGetLastBedroomRemoteInteraction interactions)
|
||||
&& startOfDay <= time
|
||||
&& time <= endOfAlarm
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ type NightLightTests() =
|
|||
|> Prop.label fakeHome.Label
|
||||
|> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0)
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |])>]
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |], MaxTest = 500)>]
|
||||
let ``All lights with power should have the correct state`` (interactions: Interaction list) =
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
|
||||
|
|
@ -90,19 +90,7 @@ type NightLightTests() =
|
|||
|> Seq.filter (fun (light, _) -> doesLightHavePowerAfterInteractions light interactions)
|
||||
|> Seq.toList
|
||||
|
||||
let lastBedroomRemoteInteraction =
|
||||
interactions
|
||||
|> Seq.indexed
|
||||
|> Seq.choose (fun (index, interaction) ->
|
||||
match interaction with
|
||||
| Interaction.RemoteInteraction remoteInteraction ->
|
||||
match remoteInteraction with
|
||||
| RemotePressedOnButton
|
||||
| RemotePressedOffButton
|
||||
| RemotePressedLeftButton -> Some(index, remoteInteraction)
|
||||
| RemotePressedRightButton -> None
|
||||
| _ -> None)
|
||||
|> Seq.tryLast
|
||||
let lastBedroomRemoteInteraction = tryGetLastBedroomRemoteInteraction interactions
|
||||
|
||||
let newDayStartedSinceBedroomRemote =
|
||||
hasNewDayStartedSince interactions lastBedroomRemoteInteraction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue