Generalize the genInteractionListThatEndsAtTime concept
This commit is contained in:
parent
9e97d9a37b
commit
14cfaaeed5
3 changed files with 24 additions and 20 deletions
|
|
@ -8,18 +8,18 @@ let private isDay (time: DateTime) =
|
|||
time.TimeOfDay >= TimeSpan.FromHours 5.5
|
||||
&& time.TimeOfDay < TimeSpan.FromHours 20.5
|
||||
|
||||
type ArbitraryInteractionsListThatEndsDuringTheDay =
|
||||
type ArbitraryInteractionListThatEndsDuringTheDay =
|
||||
static member InteractionsList() =
|
||||
ArbMap.defaults
|
||||
|> ArbMap.generate<DateTime>
|
||||
|> Gen.filter isDay
|
||||
|> Gen.bind genInteractionsListThatEndsAtTime
|
||||
|> Gen.bind genInteractionListThatEndsAtTime
|
||||
|> Arb.fromGen
|
||||
|
||||
type ArbitraryInteractionsListThatEndsDuringTheNight =
|
||||
type ArbitraryInteractionListThatEndsDuringTheNight =
|
||||
static member InteractionsList() =
|
||||
ArbMap.defaults
|
||||
|> ArbMap.generate<DateTime>
|
||||
|> Gen.filter (not << isDay)
|
||||
|> Gen.bind genInteractionsListThatEndsAtTime
|
||||
|> Gen.bind genInteractionListThatEndsAtTime
|
||||
|> Arb.fromGen
|
||||
|
|
|
|||
|
|
@ -17,25 +17,29 @@ let private genHumanInteraction =
|
|||
let private genInteraction =
|
||||
Gen.oneof [ genTimeChangedInteraction; genHumanInteraction ]
|
||||
|
||||
let private genInteractionsListThatStartsWithTimeChange =
|
||||
let private genInteractionsListThatStartsWithTimeChanged =
|
||||
gen {
|
||||
let! firstInteraction = genTimeChangedInteraction
|
||||
let! remainingInteractions = Gen.listOf genInteraction
|
||||
return firstInteraction :: remainingInteractions
|
||||
}
|
||||
|
||||
let private genInteractionsListWhere condition =
|
||||
Gen.listOf (genInteraction |> Gen.filter condition)
|
||||
let private genInteractionListContaining containingInteraction afterFilter =
|
||||
gen {
|
||||
let genNonTrivialList =
|
||||
gen {
|
||||
let! before = genInteractionsListThatStartsWithTimeChanged
|
||||
let! after = Gen.listOf (genInteraction |> Gen.filter afterFilter)
|
||||
return before @ containingInteraction :: after
|
||||
}
|
||||
|
||||
let genInteractionsListThatEndsAtTime time =
|
||||
let genTrivialList = Gen.constant <| List.singleton (Interaction.TimeChanged time)
|
||||
return!
|
||||
match containingInteraction with
|
||||
| Interaction.TimeChanged _ ->
|
||||
let genTrivialList = Gen.constant <| List.singleton containingInteraction
|
||||
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
|
||||
| _ -> genNonTrivialList
|
||||
}
|
||||
|
||||
let genNonTrivialList =
|
||||
gen {
|
||||
let! before = genInteractionsListThatStartsWithTimeChange
|
||||
let interactionThatSetsEndTime = Interaction.TimeChanged time
|
||||
let! after = genInteractionsListWhere (not << _.IsTimeChanged)
|
||||
return before @ interactionThatSetsEndTime :: after
|
||||
}
|
||||
|
||||
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
|
||||
let genInteractionListThatEndsAtTime time =
|
||||
genInteractionListContaining (Interaction.TimeChanged time) (not << _.IsTimeChanged)
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ type NightLightTests() =
|
|||
|
||||
fakeHome
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractionsListThatEndsDuringTheDay> |])>]
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractionListThatEndsDuringTheDay> |])>]
|
||||
let ``Lights should be white or yellow during the day`` (interactions: Interaction list) =
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)
|
||||
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractionsListThatEndsDuringTheNight> |])>]
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractionListThatEndsDuringTheNight> |])>]
|
||||
let ``Lights should be red during the night`` (interactions: Interaction list) =
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue