summaryrefslogtreecommitdiff
path: root/domain/tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-15 22:26:12 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-15 22:26:12 +0200
commit3262b3a337759439f3049b9299be12baf8420750 (patch)
tree53d2e71a390662894bca3eb5c9345a59f08fc806 /domain/tests
parent7758fbc7522b39bad768abfa728b37c97007ffb6 (diff)
downloadturns-3262b3a337759439f3049b9299be12baf8420750.tar.xz
turns-3262b3a337759439f3049b9299be12baf8420750.zip
turns: add more tests
Diffstat (limited to 'domain/tests')
-rw-r--r--domain/tests/participant.cpp12
-rw-r--r--domain/tests/turn_order.cpp141
2 files changed, 147 insertions, 6 deletions
diff --git a/domain/tests/participant.cpp b/domain/tests/participant.cpp
index e9e7c46..268b395 100644
--- a/domain/tests/participant.cpp
+++ b/domain/tests/participant.cpp
@@ -22,24 +22,24 @@ namespace turns::domain::tests
SECTION("the name can be read")
{
- REQUIRE(instance.property_name() == constructed_name);
+ REQUIRE(instance.get_name() == constructed_name);
}
SECTION("the name can be changed")
{
- instance.property_name() = "replaced";
- REQUIRE(instance.property_name() == "replaced");
+ instance.set_name("replaced");
+ REQUIRE(instance.get_name() == "replaced");
}
SECTION("the priority can be read")
{
- REQUIRE(instance.property_priority() == constructed_priority);
+ REQUIRE(instance.get_priority() == constructed_priority);
}
SECTION("the priority can be changed")
{
- instance.property_priority() = 8;
- REQUIRE(instance.property_priority() == 8);
+ instance.set_priority(8);
+ REQUIRE(instance.get_priority() == 8);
}
SECTION("can be compared with another participant")
diff --git a/domain/tests/turn_order.cpp b/domain/tests/turn_order.cpp
new file mode 100644
index 0000000..7172ffc
--- /dev/null
+++ b/domain/tests/turn_order.cpp
@@ -0,0 +1,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{};
+
+ SECTION("can be created")
+ {
+ REQUIRE(turn_order::create());
+ }
+
+ SECTION("has 0 items")
+ {
+ REQUIRE(instance.get_n_items() == 0);
+ }
+
+ SECTION("accepts a new participant in form of a refptr")
+ {
+ instance.append(participant::create("Honey Bunches of Oats", 12));
+ REQUIRE(instance.get_n_items() == 1);
+ }
+
+ SECTION("accepts a new participant in form of components")
+ {
+ instance.append("River along the Field", 14);
+ REQUIRE(instance.get_n_items() == 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));
+ REQUIRE(instance.get_n_items() == 0);
+ }
+
+ SECTION("does nothing when trying to remove an item by index if no items were added beforehand")
+ {
+ instance.remove(5);
+ REQUIRE(instance.get_n_items() == 0);
+ }
+
+ SECTION("allows the removal of an item by refptr if the same item was added beforehand")
+ {
+ auto item = participant::create("Blank Canvas", 23);
+ instance.append(item);
+ instance.remove(item);
+ REQUIRE(instance.get_n_items() == 0);
+ }
+
+ SECTION("does nothing when trying to remove an item by refptr that was not added beforehand")
+ {
+ auto item = participant::create("Blank Canvas", 23);
+ instance.append(item);
+ instance.remove(participant::create("Spell of Rain", 6));
+ REQUIRE(instance.get_n_items() == 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));
+ instance.append(participant::create("Bees behind the Cottage", 8));
+ REQUIRE(instance.get_item(0)->get_name() == "Bees behind the Cottage");
+ }
+
+ SECTION("when appending the higher one first")
+ {
+ instance.append(participant::create("Bees behind the Cottage", 8));
+ instance.append(participant::create("Snow on the Field", 2));
+ REQUIRE(instance.get_item(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));
+ instance.append(participant::create("Bees behind the Cottage", 8));
+ REQUIRE(instance.get_item(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);
+ instance.append("Fish in the River", 12);
+ REQUIRE(instance.get_item(0)->get_name() == "Fish in the River");
+ }
+
+ SECTION("when appending the higher one first")
+ {
+ instance.append("Fish in the River", 12);
+ instance.append("Tree Blossom", 6);
+ REQUIRE(instance.get_item(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);
+ instance.append("Tree Blossom", 6);
+ REQUIRE(instance.get_item(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);
+ instance.append(item);
+ instance.append(item);
+ REQUIRE(instance.get_n_items() == 1);
+ }
+
+ SECTION("does not accept the same item twice by different refptrs")
+ {
+ auto item_one = participant::create("Misty Meadow", 14.2);
+ auto item_two = participant::create("Misty Meadow", 14.2);
+ instance.append(item_one);
+ instance.append(item_two);
+ REQUIRE(instance.get_n_items() == 1);
+ }
+
+ SECTION("does not accept the same item twice by components")
+ {
+ instance.append("Frozen Apple Tree", 2.1);
+ instance.append("Frozen Apple Tree", 2.1);
+ REQUIRE(instance.get_n_items() == 1);
+ }
+ }
+
+} // namespace turns::domain::tests \ No newline at end of file