Make biasing towards a light optional
This commit is contained in:
parent
a9331853c0
commit
79405b3841
1 changed files with 11 additions and 5 deletions
|
|
@ -5,8 +5,10 @@ open NightLight.Core.Models
|
||||||
open NightLight.Core.Tests.TimeChangedGenerators
|
open NightLight.Core.Tests.TimeChangedGenerators
|
||||||
open FsCheck
|
open FsCheck
|
||||||
|
|
||||||
let private genHumanInteraction biasTowardsLight =
|
let private genHumanInteraction maybeBiasTowardsLight =
|
||||||
Gen.oneof [ Gen.constant biasTowardsLight; Gen.elements lights ]
|
match maybeBiasTowardsLight with
|
||||||
|
| Some biasTowardsLight -> Gen.oneof [ Gen.constant biasTowardsLight; Gen.elements lights ]
|
||||||
|
| None -> Gen.elements lights
|
||||||
|> Gen.bind (fun light -> Gen.elements [ LightPoweredOn light; LightPoweredOff light ])
|
|> Gen.bind (fun light -> Gen.elements [ LightPoweredOn light; LightPoweredOff light ])
|
||||||
|> Gen.map Interaction.HumanInteraction
|
|> Gen.map Interaction.HumanInteraction
|
||||||
|
|
||||||
|
|
@ -14,11 +16,15 @@ let private genRemoteInteraction =
|
||||||
Gen.elements [ RemotePressedOnButton; RemotePressedOffButton; RemotePressedLeftButton ]
|
Gen.elements [ RemotePressedOnButton; RemotePressedOffButton; RemotePressedLeftButton ]
|
||||||
|> Gen.map RemoteInteraction
|
|> Gen.map RemoteInteraction
|
||||||
|
|
||||||
let private genInteraction biasTowardsLight =
|
let private genInteraction maybeBiasTowardsLight =
|
||||||
Gen.oneof [ genTimeChanged; genHumanInteraction biasTowardsLight; genRemoteInteraction ]
|
Gen.oneof
|
||||||
|
[ genTimeChanged
|
||||||
|
genHumanInteraction maybeBiasTowardsLight
|
||||||
|
genRemoteInteraction ]
|
||||||
|
|
||||||
let genBiasedInteractionsExcept biasTowardsLight disqualifier =
|
let genBiasedInteractionsExcept biasTowardsLight disqualifier =
|
||||||
genInteraction biasTowardsLight
|
Some biasTowardsLight
|
||||||
|
|> genInteraction
|
||||||
|> Gen.filter (not << disqualifier)
|
|> Gen.filter (not << disqualifier)
|
||||||
|> Gen.listOf
|
|> Gen.listOf
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue