Verify that non-remotely controlled lights are on if they have power
This commit is contained in:
parent
d57ca23822
commit
d7fac9c3d0
3 changed files with 21 additions and 6 deletions
|
|
@ -19,14 +19,14 @@ let private genHumanInteraction biasTowardsLight =
|
|||
let private genInteraction biasTowardsLight =
|
||||
Gen.oneof [ genTimeChanged; genHumanInteraction biasTowardsLight ]
|
||||
|
||||
let private genInteractionsListThatStartsWithTimeChanged biasTowardsLight =
|
||||
let genInitialInteractions biasTowardsLight =
|
||||
[ genTimeChanged |> Gen.map List.singleton
|
||||
Gen.listOf <| genInteraction biasTowardsLight ]
|
||||
|> concatGens
|
||||
|
||||
let genInitialInteractionsAndEndWith biasTowardsLight (endsWith: Interaction) =
|
||||
let genNonTrivialList =
|
||||
genInteractionsListThatStartsWithTimeChanged biasTowardsLight
|
||||
genInitialInteractions biasTowardsLight
|
||||
|> Gen.map (fun lst -> lst @ [ endsWith ])
|
||||
|
||||
match endsWith with
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ open FsCheck.FSharp
|
|||
type ArbitraryLight =
|
||||
static member Light() = lights |> Gen.elements |> Arb.fromGen
|
||||
|
||||
type ArbitraryNonRemotelyControlledLight =
|
||||
static member Light() =
|
||||
lights
|
||||
|> Seq.filter (not << _.ControlledWithRemote)
|
||||
|> Gen.elements
|
||||
|> Arb.fromGen
|
||||
|
||||
type ArbitraryRemotelyControlledLight =
|
||||
static member Light() =
|
||||
lights |> Seq.filter _.ControlledWithRemote |> Gen.elements |> Arb.fromGen
|
||||
|
|
|
|||
|
|
@ -63,8 +63,16 @@ type NightLightTests() =
|
|||
| Off -> true
|
||||
| On(_, color) -> color = Red)
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
||||
let ``After pressing 'On' on the remote, all lights with power should be on, as long as the 'Off' button isn't pressed``
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryNonRemotelyControlledLight> |])>]
|
||||
let ``All non-remotely controlled lights should be on *if and only if* they have power`` (light: Light) =
|
||||
genInitialInteractions light |> Arb.fromGen |> Prop.forAll
|
||||
<| fun interactions ->
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
|
||||
doesLightHavePowerAfter light interactions = fakeHome.LightShouldHaveState light _.IsOn
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryRemotelyControlledLight> |])>]
|
||||
let ``After pressing 'On' on the remote, all remotely controlled lights with power should be on, as long as the 'Off' button isn't pressed``
|
||||
(light: Light)
|
||||
=
|
||||
concatGens
|
||||
|
|
@ -78,8 +86,8 @@ type NightLightTests() =
|
|||
doesLightHavePowerAfter light interactions
|
||||
==> fakeHome.LightShouldHaveState light _.IsOn
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
||||
let ``After a new day starts, all lights with power should be on, as long as the 'Off' button isn't pressed``
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryRemotelyControlledLight> |])>]
|
||||
let ``After a new day starts, all remotely controlled lights with power should be on, as long as the 'Off' button isn't pressed``
|
||||
(light: Light)
|
||||
=
|
||||
concatGens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue