Get rid of the [...]AndEndWith helper
I introduced this to test a very specific edge case right after initialization, but it made all tests harder to read.
This commit is contained in:
parent
c74238e105
commit
2da1972b06
2 changed files with 16 additions and 19 deletions
|
|
@ -24,18 +24,12 @@ let genInitialInteractions biasTowardsLight =
|
||||||
Gen.listOf <| genInteraction biasTowardsLight ]
|
Gen.listOf <| genInteraction biasTowardsLight ]
|
||||||
|> concatGens
|
|> concatGens
|
||||||
|
|
||||||
let genInitialInteractionsAndEndWith biasTowardsLight (endsWith: Interaction) =
|
|
||||||
let genNonTrivialList =
|
|
||||||
genInitialInteractions biasTowardsLight
|
|
||||||
|> Gen.map (fun lst -> lst @ [ endsWith ])
|
|
||||||
|
|
||||||
match endsWith with
|
|
||||||
| Interaction.TimeChanged _ ->
|
|
||||||
let genTrivialList = Gen.constant <| List.singleton endsWith
|
|
||||||
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
|
|
||||||
| _ -> genNonTrivialList
|
|
||||||
|
|
||||||
let genInteractionsExcept biasTowardsLight disqualifier =
|
let genInteractionsExcept biasTowardsLight disqualifier =
|
||||||
genInteraction biasTowardsLight
|
genInteraction biasTowardsLight
|
||||||
|> Gen.filter (not << disqualifier)
|
|> Gen.filter (not << disqualifier)
|
||||||
|> Gen.listOf
|
|> Gen.listOf
|
||||||
|
|
||||||
|
let genInitialInteractionsExcept biasTowardsLight disqualifier =
|
||||||
|
[ genTimeChanged |> Gen.map List.singleton
|
||||||
|
genInteractionsExcept biasTowardsLight disqualifier ]
|
||||||
|
|> concatGens
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ type NightLightTests() =
|
||||||
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
||||||
let ``All lights should be either off, white or yellow during the day`` (light: Light) =
|
let ``All lights should be either off, white or yellow during the day`` (light: Light) =
|
||||||
concatGens
|
concatGens
|
||||||
[ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomDayTime
|
[ genInitialInteractions light
|
||||||
|
genTimeChangedToRandomDayTime |> Gen.map List.singleton
|
||||||
genInteractionsExcept light isTimeChangedToAnyNightTime ]
|
genInteractionsExcept light isTimeChangedToAnyNightTime ]
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|> Prop.forAll
|
|> Prop.forAll
|
||||||
|
|
@ -52,7 +53,8 @@ type NightLightTests() =
|
||||||
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
[<Property(Arbitrary = [| typeof<ArbitraryLight> |])>]
|
||||||
let ``All lights should be either off or red during the night`` (light: Light) =
|
let ``All lights should be either off or red during the night`` (light: Light) =
|
||||||
concatGens
|
concatGens
|
||||||
[ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomNightTime
|
[ genInitialInteractions light
|
||||||
|
genTimeChangedToRandomNightTime |> Gen.map List.singleton
|
||||||
genInteractionsExcept light isTimeChangedToAnyDayTime ]
|
genInteractionsExcept light isTimeChangedToAnyDayTime ]
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|> Prop.forAll
|
|> Prop.forAll
|
||||||
|
|
@ -75,9 +77,7 @@ type NightLightTests() =
|
||||||
let ``All remote controlled lights with power should be on if the 'Off' button on the remote was never pressed``
|
let ``All remote controlled lights with power should be on if the 'Off' button on the remote was never pressed``
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
genInitialInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton))
|
||||||
[ genTimeChanged |> Gen.map List.singleton
|
|
||||||
genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ]
|
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|> Prop.forAll
|
|> Prop.forAll
|
||||||
<| fun interactions ->
|
<| fun interactions ->
|
||||||
|
|
@ -91,7 +91,8 @@ type NightLightTests() =
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
concatGens
|
||||||
[ genInitialInteractionsAndEndWith light (HumanInteraction RemotePressedOnButton)
|
[ genInitialInteractions light
|
||||||
|
HumanInteraction RemotePressedOnButton |> List.singleton |> Gen.constant
|
||||||
genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ]
|
genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ]
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|> Prop.forAll
|
|> Prop.forAll
|
||||||
|
|
@ -106,7 +107,8 @@ type NightLightTests() =
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
concatGens
|
||||||
[ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomNightTime
|
[ genInitialInteractions light
|
||||||
|
genTimeChangedToRandomNightTime |> Gen.map List.singleton
|
||||||
genInteractionsExcept light isTimeChangedToAnyDayTime
|
genInteractionsExcept light isTimeChangedToAnyDayTime
|
||||||
genTimeChangedToRandomDayTime |> Gen.map List.singleton
|
genTimeChangedToRandomDayTime |> Gen.map List.singleton
|
||||||
genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ]
|
genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ]
|
||||||
|
|
@ -123,7 +125,8 @@ type NightLightTests() =
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
concatGens
|
||||||
[ genInitialInteractionsAndEndWith light (HumanInteraction RemotePressedOffButton)
|
[ genInitialInteractions light
|
||||||
|
HumanInteraction RemotePressedOffButton |> List.singleton |> Gen.constant
|
||||||
genInteractionsExcept light (fun interaction ->
|
genInteractionsExcept light (fun interaction ->
|
||||||
interaction = HumanInteraction RemotePressedOnButton
|
interaction = HumanInteraction RemotePressedOnButton
|
||||||
|| interaction |> isTimeChangedToAnyDayTime) ]
|
|| interaction |> isTimeChangedToAnyDayTime) ]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue