summaryrefslogtreecommitdiff
path: root/lib/tests/turnsmm/turn-order.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/turnsmm/turn-order.cpp')
-rw-r--r--lib/tests/turnsmm/turn-order.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/lib/tests/turnsmm/turn-order.cpp b/lib/tests/turnsmm/turn-order.cpp
index 21c75d3..fcb7727 100644
--- a/lib/tests/turnsmm/turn-order.cpp
+++ b/lib/tests/turnsmm/turn-order.cpp
@@ -7,6 +7,7 @@
#include <turnsmm/enums.hpp>
#include <cstddef>
+#include <tuple>
SCENARIO("Creating a turn order", "[lib][object][lifetime]")
{
@@ -41,6 +42,11 @@ SCENARIO("Creating a turn order", "[lib][object][lifetime]")
REQUIRE(instance.get_object(0) == nullptr);
REQUIRE(instance.get_typed_object<Turns::Participant>(0) == nullptr);
}
+
+ THEN("its sort mode is descending")
+ {
+ REQUIRE(instance.get_sort_mode() == Turns::SortMode::Descending);
+ }
}
}
@@ -78,6 +84,129 @@ SCENARIO("Modifying a turn order", "[lib][object][data]")
REQUIRE(cnt > 0);
REQUIRE(obj == participant);
}
+
+ THEN("its sort mode is descending")
+ {
+ REQUIRE(instance.get_sort_mode() == Turns::SortMode::Descending);
+ }
}
}
}
+
+SCENARIO("Sorting a turn order")
+{
+ GIVEN("A turn order with two participants - A/10/H and B/20/N")
+ {
+ auto instance = Turns::TurnOrder{};
+ auto participant_a = Turns::Participant::create("A", 10, Turns::Disposition::Hostile);
+ auto participant_b = Turns::Participant::create("B", 20, Turns::Disposition::Neutral);
+
+ instance.add(participant_a);
+ instance.add(participant_b);
+
+ THEN("B is the first and A the second element")
+ {
+ auto first = instance.get_typed_object<Turns::Participant>(0);
+ auto second = instance.get_typed_object<Turns::Participant>(1);
+
+ REQUIRE(first == participant_b);
+ REQUIRE(second == participant_a);
+ }
+
+ WHEN("the priority of A is changed to 30")
+ {
+ participant_a->set_priority(30);
+
+ THEN("A is the first and B the second element")
+ {
+ auto first = instance.get_typed_object<Turns::Participant>(0);
+ auto second = instance.get_typed_object<Turns::Participant>(1);
+
+ REQUIRE(first == participant_a);
+ REQUIRE(second == participant_b);
+ }
+ }
+
+ WHEN("the priority of A is changed to 0")
+ {
+ participant_a->set_priority(0);
+
+ THEN("B is the first and A the second element")
+ {
+ auto first = instance.get_typed_object<Turns::Participant>(0);
+ auto second = instance.get_typed_object<Turns::Participant>(1);
+
+ REQUIRE(first == participant_b);
+ REQUIRE(second == participant_a);
+ }
+ }
+
+ WHEN("the priority of B is changed to 0")
+ {
+ participant_b->set_priority(0);
+
+ THEN("A is the first and B the second element")
+ {
+ auto first = instance.get_typed_object<Turns::Participant>(0);
+ auto second = instance.get_typed_object<Turns::Participant>(1);
+
+ REQUIRE(first == participant_a);
+ REQUIRE(second == participant_b);
+ }
+ }
+
+ WHEN("the sort mode is changed to ascending")
+ {
+ instance.set_sort_mode(Turns::SortMode::Ascending);
+
+ THEN("A is the first and B the second element")
+ {
+ auto first = instance.get_typed_object<Turns::Participant>(0);
+ auto second = instance.get_typed_object<Turns::Participant>(1);
+
+ REQUIRE(first == participant_a);
+ REQUIRE(second == participant_b);
+ }
+ }
+
+ WHEN("a signal handler is registered for the 'items-changed' signal")
+ {
+ auto notified = false;
+ auto data = std::tuple{0u, 0u, 0u};
+ auto callback = [&](auto position, auto removed, auto added) {
+ notified = true, data = std::tie(position, removed, added);
+ };
+ instance.signal_items_changed().connect(callback);
+
+ AND_WHEN("the sort mode is changed to ascending")
+ {
+ instance.set_sort_mode(Turns::SortMode::Ascending);
+
+ THEN("the signal is notified")
+ {
+ REQUIRE(notified);
+ }
+
+ THEN("all items were removed and added again at position 0")
+ {
+ auto [position, removed, added] = data;
+
+ REQUIRE(position == 0);
+ REQUIRE(removed == 2);
+ REQUIRE(added == 2);
+ }
+ }
+
+ AND_WHEN("the sort mode is set to the current value")
+ {
+ auto current_sort_mode = instance.get_sort_mode();
+ instance.set_sort_mode(current_sort_mode);
+
+ THEN("the signal is not notified")
+ {
+ REQUIRE_FALSE(notified);
+ }
+ }
+ }
+ }
+} \ No newline at end of file