summaryrefslogtreecommitdiff
path: root/domain/tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-24 08:57:21 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-24 08:57:21 +0200
commit0d61f98434b95c754f46c918af5152eda82077cb (patch)
treeb7908f53bcaabf4002cfb52daa461789b59fc9a5 /domain/tests
parentcd855825de415111c55f16bf05a57f1191d97c76 (diff)
downloadturns-0d61f98434b95c754f46c918af5152eda82077cb.tar.xz
turns-0d61f98434b95c754f46c918af5152eda82077cb.zip
domain/turn_order: fix a round underflow bug
Diffstat (limited to 'domain/tests')
-rw-r--r--domain/tests/turn_order_bugs.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/domain/tests/turn_order_bugs.cpp b/domain/tests/turn_order_bugs.cpp
new file mode 100644
index 0000000..418a36c
--- /dev/null
+++ b/domain/tests/turn_order_bugs.cpp
@@ -0,0 +1,42 @@
+#include "turns/domain/participant.hpp"
+#include "turns/domain/turn_order.hpp"
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <giomm/liststore.h>
+
+namespace turns::domain::tests
+{
+ /**
+ * Bug description:
+ *
+ * After having stepped according to the step pattern below, tt was possible to step backward often enough to underflow the round number:
+ * - forward
+ * - backward
+ * - forward
+ */
+ SCENARIO("Can step back infinitely", "[turn_order][bug]")
+ {
+ GIVEN("a non-empty turn_order")
+ {
+ auto instance = turn_order::create();
+
+ instance->add("A", 0, disposition::neutral);
+
+ WHEN("it is started and then stepped forward, backward, forward")
+ {
+ instance->start();
+ instance->next();
+ instance->previous();
+ instance->next();
+
+ THEN("it is not possible to step backwards more than once")
+ {
+ instance->previous();
+ instance->previous();
+ REQUIRE(instance->round_number() == 0);
+ }
+ }
+ }
+ }
+} // namespace turns::domain::tests \ No newline at end of file