Introduce ArbitraryInteractions
This commit is contained in:
parent
d278b5d8ea
commit
8866053172
2 changed files with 33 additions and 33 deletions
|
|
@ -95,3 +95,7 @@ let ensureLastRemoteInteractionIs
|
||||||
interactions
|
interactions
|
||||||
else
|
else
|
||||||
interactions @ [ RemoteInteraction desiredLastRemoteInteraction ])
|
interactions @ [ RemoteInteraction desiredLastRemoteInteraction ])
|
||||||
|
|
||||||
|
type ArbitraryInteractions() =
|
||||||
|
static member Interactions() =
|
||||||
|
genInteractions |> ensureStartsWithTimeChanged |> Arb.fromGen
|
||||||
|
|
|
||||||
|
|
@ -25,42 +25,38 @@ type NightLightTests() =
|
||||||
|
|
||||||
fakeHome
|
fakeHome
|
||||||
|
|
||||||
[<Property>]
|
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |])>]
|
||||||
let ``All lights should either be off or have the right color`` () =
|
let ``All lights should either be off or have the right color`` (interactions: Interaction list) =
|
||||||
genInteractions |> ensureStartsWithTimeChanged |> Arb.fromGen |> Prop.forAll
|
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||||
<| fun interactions ->
|
let partOfDay = getPartOfDayAfterInteractions interactions
|
||||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
|
||||||
let partOfDay = getPartOfDayAfterInteractions interactions
|
|
||||||
|
|
||||||
|
fakeHome.LightStates
|
||||||
|
|> Seq.forall (function
|
||||||
|
| _, Off -> true
|
||||||
|
| _, On(_, color) ->
|
||||||
|
match partOfDay with
|
||||||
|
| Day -> color = White || color = Yellow
|
||||||
|
| Night -> color = Red)
|
||||||
|
|> Prop.classify (partOfDay = Day) "day"
|
||||||
|
|> Prop.classify (partOfDay = Night) "night"
|
||||||
|
|> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0)
|
||||||
|
|> Prop.collect $"{fakeHome.LightsThatAreOn.Length} light(s) on"
|
||||||
|
|
||||||
|
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |])>]
|
||||||
|
let ``All non-remotely controlled lights that have power should be on`` (interactions: Interaction list) =
|
||||||
|
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||||
|
|
||||||
|
let nonRemotelyControlledLightsWithPower =
|
||||||
fakeHome.LightStates
|
fakeHome.LightStates
|
||||||
|> Seq.forall (function
|
|> Seq.filter (fun (light, _) ->
|
||||||
| _, Off -> true
|
light.ControlledWithRemote = NonRemote
|
||||||
| _, On(_, color) ->
|
&& doesLightHavePowerAfterInteractions light interactions)
|
||||||
match partOfDay with
|
|> Seq.toList
|
||||||
| Day -> color = White || color = Yellow
|
|
||||||
| Night -> color = Red)
|
|
||||||
|> Prop.classify (partOfDay = Day) "day"
|
|
||||||
|> Prop.classify (partOfDay = Night) "night"
|
|
||||||
|> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0)
|
|
||||||
|> Prop.collect $"{fakeHome.LightsThatAreOn.Length} light(s) on"
|
|
||||||
|
|
||||||
[<Property>]
|
nonRemotelyControlledLightsWithPower
|
||||||
let ``All non-remotely controlled lights that have power should be on`` () =
|
|> Seq.forall (snd >> _.IsOn)
|
||||||
genInteractions |> ensureStartsWithTimeChanged |> Arb.fromGen |> Prop.forAll
|
|> Prop.trivial (nonRemotelyControlledLightsWithPower.Length = 0)
|
||||||
<| fun interactions ->
|
|> Prop.collect $"{nonRemotelyControlledLightsWithPower.Length} non-remotely controlled light(s) with power"
|
||||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
|
||||||
|
|
||||||
let nonRemotelyControlledLightsWithPower =
|
|
||||||
fakeHome.LightStates
|
|
||||||
|> Seq.filter (fun (light, _) ->
|
|
||||||
light.ControlledWithRemote = NonRemote
|
|
||||||
&& doesLightHavePowerAfterInteractions light interactions)
|
|
||||||
|> Seq.toList
|
|
||||||
|
|
||||||
nonRemotelyControlledLightsWithPower
|
|
||||||
|> Seq.forall (snd >> _.IsOn)
|
|
||||||
|> Prop.trivial (nonRemotelyControlledLightsWithPower.Length = 0)
|
|
||||||
|> Prop.collect $"{nonRemotelyControlledLightsWithPower.Length} non-remotely controlled light(s) with power"
|
|
||||||
|
|
||||||
[<Property(Arbitrary = [| typeof<ArbitraryRemotelyControlledLight> |])>]
|
[<Property(Arbitrary = [| typeof<ArbitraryRemotelyControlledLight> |])>]
|
||||||
let ``If the remote was never used, all remote controlled lights with power should be on`` (light: Light) =
|
let ``If the remote was never used, all remote controlled lights with power should be on`` (light: Light) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue