๐Ÿ“ฆ sleepyfran / duets

๐Ÿ“„ Drink.Interactions.Test.fs ยท 117 lines
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117module Duets.Simulation.Tests.Interactions.Drink

open FsUnit
open NUnit.Framework
open Test.Common.Generators

open Duets.Common
open Duets.Entities
open Duets
open Duets.Simulation
open Duets.Simulation.Interactions

let state = State.generateOne State.defaultOptions

let character = Queries.Characters.playableCharacter state

[<Test>]
let ``Drinking a beer of 500ml and 4.4 in alcohol increases drunkenness by 6``
    ()
    =
    let effects =
        Items.perform
            state
            (fst Data.Items.Drink.Beer.pilsnerUrquellPint)
            ItemInteraction.Drink
        |> Result.unwrap

    effects
    |> List.item 0
    |> should
        equal
        (CharacterAttributeChanged(
            character.Id,
            CharacterAttribute.Drunkenness,
            Diff(0, 6)
        ))

[<Test>]
let ``Drinking a beer of 500ml and 5.4 in alcohol increases drunkenness by 8``
    ()
    =
    let effects =
        Items.perform
            state
            (fst Data.Items.Drink.Beer.matushkaPint)
            ItemInteraction.Drink
        |> Result.unwrap

    effects
    |> List.item 0
    |> should
        equal
        (CharacterAttributeChanged(
            character.Id,
            CharacterAttribute.Drunkenness,
            Diff(0, 8)
        ))

[<Test>]
let ``Drinking two beers of 500ml and 5.4 in alcohol increases drunkenness by 16``
    ()
    =
    let effects =
        Items.perform
            state
            (fst Data.Items.Drink.Beer.matushkaPint)
            ItemInteraction.Drink
        |> Result.unwrap

    let updatedState =
        Simulation.State.Root.applyEffect state (effects |> List.item 0)

    let updatedEffects =
        Items.perform
            updatedState
            (fst Data.Items.Drink.Beer.matushkaPint)
            ItemInteraction.Drink
        |> Result.unwrap

    let updatedCharacter = Queries.Characters.playableCharacter updatedState

    updatedEffects
    |> List.item 0
    |> should
        equal
        (CharacterAttributeChanged(
            updatedCharacter.Id,
            CharacterAttribute.Drunkenness,
            Diff(8, 16)
        ))

[<Test>]
let ``Drinking an item should remove it from the inventory if it was there``
    ()
    =
    let item = fst Data.Items.Drink.Beer.pilsnerUrquellPint

    let state = state |> State.Inventory.addToCharacter item

    let effects =
        Items.perform state item ItemInteraction.Drink |> Result.unwrap

    effects
    |> List.filter (function
        | ItemRemovedFromCharacterInventory _ -> true
        | _ -> false)
    |> List.head
    |> should equal (ItemRemovedFromCharacterInventory item)

[<Test>]
let ``Drinking non-drink items should not be allowed`` () =
    let item = Data.Items.Food.Czech.all |> List.head |> fst

    Items.perform state item ItemInteraction.Drink
    |> Result.unwrapError
    |> should be (ofCase <@@ Items.ActionNotPossible @@>)