diff options
| -rw-r--r-- | domain/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | domain/src/turn_order.cpp | 2 | ||||
| -rw-r--r-- | domain/tests/turn_order_bugs.cpp | 42 |
3 files changed, 44 insertions, 1 deletions
diff --git a/domain/CMakeLists.txt b/domain/CMakeLists.txt index ec9eb62..6c54e31 100644 --- a/domain/CMakeLists.txt +++ b/domain/CMakeLists.txt @@ -41,6 +41,7 @@ add_executable("domain-tests" "tests/disposition.cpp" "tests/participant.cpp" + "tests/turn_order_bugs.cpp" "tests/turn_order.cpp" ) diff --git a/domain/src/turn_order.cpp b/domain/src/turn_order.cpp index e3a1e23..d3140b1 100644 --- a/domain/src/turn_order.cpp +++ b/domain/src/turn_order.cpp @@ -122,7 +122,7 @@ namespace turns::domain m_data[old_active]->is_active() = false; m_data[*m_active]->is_active() = true; - if (m_active == 0) + if (m_active == 0 && m_round_number > 0) { m_round_number = m_round_number - 1; } 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 |
