1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94module Duets.Simulation.Tests.Airport.BoardPlane
open Duets.Data.World
open NUnit.Framework
open FsUnit
open Test.Common
open Test.Common.Generators
open Duets
open Duets.Entities
open Duets.Entities.SituationTypes
open Duets.Simulation
open Duets.Simulation.Flights.Airport
let createTicket origin destination =
{ Id = Identity.create ()
Origin = origin
Destination = destination
Price = 100m<dd>
Date = dummyToday
DayMoment = Morning
AlreadyUsed = false }
let testTicket = createTicket Prague Madrid
let state =
State.generateOne State.defaultOptions
|> State.World.move Prague dummyAirport.Id Ids.Airport.securityControl
[<Test>]
let ``passSecurityCheck should move character to boarding gate`` () =
let effects = passSecurityCheck state
effects
|> List.head
|> should
equal
(WorldEnterRoom(
Diff(
(Prague, dummyAirport.Id, Ids.Airport.securityControl),
(Prague, dummyAirport.Id, Ids.Airport.boardingGate)
)
))
[<Test>]
let ``passSecurityCheck should drop all drinks from inventory`` () =
let item = fst Data.Items.Drink.Beer.pilsnerUrquellPint
let state =
state
|> State.Inventory.addToCharacter item
|> State.Inventory.addToCharacter item
let effects = passSecurityCheck state
effects |> should haveLength 4
effects
|> List.filter (function
| ItemRemovedFromCharacterInventory _ -> true
| _ -> false)
|> should haveLength 2
[<Test>]
let ``boardPlane should return an effect that sets the situation to flying``
()
=
let effect, _ = boardPlane testTicket
match effect.Head with
| SituationChanged(Airport(Flying flight)) ->
flight |> should equal testTicket
| _ -> failwith "Incorrect situation"
[<Test>]
let ``boardPlane should return an effect that marks the ticket as used`` () =
let effect, _ = boardPlane testTicket
match effect.Item 1 with
| FlightUpdated flight -> flight.AlreadyUsed |> should equal true
| _ -> failwith "Incorrect situation"
[<Test>]
let ``boardPlane should return the correct length of the flight in minutes``
()
=
[ Prague, Madrid, 237<minute>; Prague, London, 138<minute> ]
|> List.iter (fun (origin, destination, expected) ->
let ticket = createTicket origin destination
let _, flightTime = boardPlane ticket
flightTime |> should equal expected)