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
92module Duets.Simulation.Tests.Social.LongTimeNoSee
open FsUnit
open NUnit.Framework
open Test.Common
open Duets.Entities
open Duets.Simulation
let private createRelationshipWithLevel lastInteractionTime level =
{ Character = dummyCharacter2.Id
MeetingCity = Prague
LastIterationDate = lastInteractionTime
RelationshipType = Friend
Level = level }
let createStateWithRelationship level lastInteractionTime =
RelationshipChanged(
dummyCharacter2,
Prague,
Some(createRelationshipWithLevel lastInteractionTime level)
)
|> State.Root.applyEffect dummyState
[<Test>]
let ``does nothing if character has no relationships`` () =
Social.LongTimeNoSee.applyIfNeeded dummyState |> should haveLength 0
[<Test>]
let ``does nothing if the last interaction was less than 14 days ago`` () =
[ 0..13 ]
|> List.iter (fun daysSince ->
dummyToday
|> Calendar.Ops.addDays -(daysSince * 1<days>)
|> createStateWithRelationship 10<relationshipLevel>
|> Social.LongTimeNoSee.applyIfNeeded
|> should haveLength 0)
[<Test>]
let ``reduces relationship level by 5 and sets last interaction time to today if interaction was more than 14 days ago``
()
=
let effects =
dummyToday
|> Calendar.Ops.addDays -15<days>
|> createStateWithRelationship 10<relationshipLevel>
|> Social.LongTimeNoSee.applyIfNeeded
let expectedRelationship =
createRelationshipWithLevel dummyToday 5<relationshipLevel>
effects |> should haveLength 1
effects
|> List.head
|> should
equal
(RelationshipChanged(dummyCharacter2, Prague, Some expectedRelationship))
[<Test>]
let ``removes relationship if interaction was more than 14 days ago and it was already 0``
()
=
let effects =
dummyToday
|> Calendar.Ops.addDays -15<days>
|> createStateWithRelationship 0<relationshipLevel>
|> Social.LongTimeNoSee.applyIfNeeded
effects |> should haveLength 1
effects
|> List.head
|> should equal (RelationshipChanged(dummyCharacter2, Prague, None))
[<Test>]
let ``gets applied every day in the morning`` () =
let state =
dummyToday
|> Calendar.Ops.addDays -15<days>
|> createStateWithRelationship 10<relationshipLevel>
dummyToday
|> Calendar.Transform.changeDayMoment Morning
|> TimeAdvanced
|> Simulation.tickOne state
|> fst
|> List.filter (function
| RelationshipChanged _ -> true
| _ -> false)
|> should haveLength 1