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
94
95
96module Duets.Simulation.Tests.Interactions.Read
open FsUnit
open NUnit.Framework
open Test.Common
open Duets.Common
open Duets.Entities
open Duets.Data
open Duets.Simulation.Interactions
let private read item =
Items.perform dummyState item ItemInteraction.Read
let private createBookItem readProgress =
{ Brand = "Boo"
Name = "Book"
Properties =
{ Title = "Random Book"
Author = "Random Author"
BookEffects =
[ SkillGain(SkillId.Barista, 10)
MoodletGain(MoodletType.JetLagged, MoodletExpirationTime.Never) ]
ReadProgress = readProgress }
|> Book
|> Readable
|> List.singleton }
let private unwrapBook (item: Item) =
let mainProperty = item.Properties |> List.head
match mainProperty with
| Readable(Book book) -> book
| _ -> failwith "Unexpected item type"
[<Test>]
let ``reading something else than a book returns an error`` () =
(fst Items.Drink.Beer.alhambra)
|> read
|> Result.unwrapError
|> should be (ofCase <@ Items.ActionNotPossible @>)
[<Test>]
let ``reading updates the inventory item`` () =
createBookItem 0<percent>
|> read
|> Result.unwrap
|> List.filter (function
| ItemChangedInCharacterInventory _ -> true
| _ -> false)
|> should haveLength 1
[<Test>]
let ``reading adds 20% progress when read`` () =
let updateEffect =
createBookItem 0<percent>
|> read
|> Result.unwrap
|> List.item 1 (* Head is TimeAdvanced *)
match updateEffect with
| ItemChangedInCharacterInventory(Diff(prev, curr)) ->
let prevBook = unwrapBook prev
let currBook = unwrapBook curr
prevBook.ReadProgress |> should equal 0<percent>
currBook.ReadProgress |> should equal 20<percent>
| _ -> failwith "Unexpected effect"
[<Test>]
let ``reading applies the book's effect when finishing it`` () =
createBookItem 80<percent>
|> read
|> Result.unwrap
|> List.filter (function
| SkillImproved(_, Diff((_, prevLevel), (_, currLevel))) when
prevLevel < currLevel
->
true
| CharacterMoodletsChanged _ -> true
| _ -> false)
|> should haveLength 2
[<Test>]
let ``reading on an already finished book does not re-apply effects`` () =
createBookItem 100<percent>
|> read
|> Result.unwrap
|> List.filter (function
| SkillImproved(_, Diff((_, prevLevel), (_, currLevel))) when
prevLevel < currLevel
->
true
| _ -> false)
|> should haveLength 0