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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include "turns/domain/turn_order.hpp"
#include "turns/domain/participant.hpp"
#include <catch2/catch_test_macros.hpp>
#include <compare>
#include <glibmm/init.h>
namespace turns::domain::tests
{
TEST_CASE("A freshly constructed turn order")
{
auto instance = turn_order::create();
SECTION("can be created")
{
REQUIRE(instance);
}
SECTION("has 0 items")
{
REQUIRE(instance->n_participants() == 0);
}
SECTION("accepts a new participant in form of a refptr")
{
instance->append(participant::create("Honey Bunches of Oats", 12, disposition::friendly));
REQUIRE(instance->n_participants() == 1);
}
SECTION("accepts a new participant in form of components")
{
instance->append("River along the Field", 14, disposition::friendly);
REQUIRE(instance->n_participants() == 1);
}
SECTION("does nothing when trying to remove an item by refptr if no items were added beforehand")
{
instance->remove(participant::create("Patch in the Forest", 3, disposition::friendly));
REQUIRE(instance->n_participants() == 0);
}
SECTION("does nothing when trying to remove an item by index if no items were added beforehand")
{
instance->remove(5);
REQUIRE(instance->n_participants() == 0);
}
SECTION("allows the removal of an item by refptr if the same item was added beforehand")
{
auto item = participant::create("Blank Canvas", 23, disposition::friendly);
instance->append(item);
instance->remove(item);
REQUIRE(instance->n_participants() == 0);
}
SECTION("does nothing when trying to remove an item by refptr that was not added beforehand")
{
auto item = participant::create("Blank Canvas", 23, disposition::friendly);
instance->append(item);
instance->remove(participant::create("Spell of Rain", 6, disposition::friendly));
REQUIRE(instance->n_participants() == 1);
}
SECTION("automatically sorts appended refptrs in descending order of priority")
{
SECTION("when appending the higher one last")
{
instance->append(participant::create("Snow on the Field", 2, disposition::friendly));
instance->append(participant::create("Bees behind the Cottage", 8, disposition::friendly));
REQUIRE(instance->get_participant(0)->get_name() == "Bees behind the Cottage");
}
SECTION("when appending the higher one first")
{
instance->append(participant::create("Bees behind the Cottage", 8, disposition::friendly));
instance->append(participant::create("Snow on the Field", 2, disposition::friendly));
REQUIRE(instance->get_participant(0)->get_name() == "Bees behind the Cottage");
}
SECTION("keeping the insertion order when appending items with equal priority")
{
instance->append(participant::create("Snow on the Field", 8, disposition::friendly));
instance->append(participant::create("Bees behind the Cottage", 8, disposition::friendly));
REQUIRE(instance->get_participant(0)->get_name() == "Snow on the Field");
}
}
SECTION("automatically sorts elements appended by components in descending order of priority")
{
SECTION("when appending the higher one last")
{
instance->append("Tree Blossom", 6, disposition::friendly);
instance->append("Fish in the River", 12, disposition::friendly);
REQUIRE(instance->get_participant(0)->get_name() == "Fish in the River");
}
SECTION("when appending the higher one first")
{
instance->append("Fish in the River", 12, disposition::friendly);
instance->append("Tree Blossom", 6, disposition::friendly);
REQUIRE(instance->get_participant(0)->get_name() == "Fish in the River");
}
SECTION("keeping the insertion order when appending items with equal priority")
{
instance->append("Fish in the River", 6, disposition::friendly);
instance->append("Tree Blossom", 6, disposition::friendly);
REQUIRE(instance->get_participant(0)->get_name() == "Fish in the River");
}
}
SECTION("does not accept the same item twice by the same refptr")
{
auto item = participant::create("Angelic Berry", 9, disposition::friendly);
instance->append(item);
instance->append(item);
REQUIRE(instance->n_participants() == 1);
}
SECTION("does not accept the same item twice by different refptrs")
{
auto item_one = participant::create("Misty Meadow", 14.2, disposition::friendly);
auto item_two = participant::create("Misty Meadow", 14.2, disposition::friendly);
instance->append(item_one);
instance->append(item_two);
REQUIRE(instance->n_participants() == 1);
}
SECTION("does not accept the same item twice by components")
{
instance->append("Frozen Apple Tree", 2.1, disposition::friendly);
instance->append("Frozen Apple Tree", 2.1, disposition::friendly);
REQUIRE(instance->n_participants() == 1);
}
}
} // namespace turns::domain::tests
|