From 71fe1d395a3c1d94dac68469826118e357f7086d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 9 May 2025 10:48:30 +0200 Subject: core: rename turn_order to TurnOderModel --- core/tests/turn_order.cpp | 314 ---------------------------------------- core/tests/turn_order_bugs.cpp | 4 +- core/tests/turn_order_model.cpp | 314 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 316 deletions(-) delete mode 100644 core/tests/turn_order.cpp create mode 100644 core/tests/turn_order_model.cpp (limited to 'core/tests') diff --git a/core/tests/turn_order.cpp b/core/tests/turn_order.cpp deleted file mode 100644 index a7633cd..0000000 --- a/core/tests/turn_order.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "turns/core/turn_order.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" - -#include - -#include - -#include - -#include - -namespace turns::core::tests -{ - SCENARIO("Queries on a fresh turn_order instance", "[turn_order]") - { - GIVEN("an empty turn_order") - { - auto instance = turn_order::create(); - - THEN("get_n_items() returns 0") - { - REQUIRE(instance->get_n_items() == 0); - } - - THEN("get_type() returns participant::get_type()") - { - REQUIRE(instance->get_item_type() == Participant::get_type()); - } - - THEN("get_typed_object(0) returns nullptr") - { - REQUIRE(instance->get_typed_object(0) == nullptr); - } - - THEN("has_next() returns false") - { - REQUIRE_FALSE(instance->has_next()); - } - - THEN("has_previous() returns false") - { - REQUIRE_FALSE(instance->has_previous()); - } - - THEN("is_empty() returns true") - { - REQUIRE(instance->is_empty()); - } - - THEN("is_running() returns false") - { - REQUIRE_FALSE(instance->is_running()); - } - - THEN("round_number() returns invalid_round_number") - { - REQUIRE(instance->round_number() == turn_order::invalid_round_number); - } - } - } - - SCENARIO("Adding participants") - { - auto instance = turn_order::create(); - - GIVEN("a participant has been added to a turn_order") - { - instance->add("Participant #0", 0, Disposition::Neutral); - - THEN("get_n_items() returns 1") - { - REQUIRE(instance->get_n_items() == 1); - } - - THEN("get_typed_object(0) returns a non-null pointer") - { - REQUIRE(instance->get_typed_object(0) != nullptr); - } - - THEN("has_next() returns true") - { - REQUIRE(instance->has_next()); - } - - THEN("has_previous() returns false") - { - REQUIRE_FALSE(instance->has_previous()); - } - - THEN("is_empty() returns false") - { - REQUIRE_FALSE(instance->is_empty()); - } - - THEN("is_running() returns false") - { - REQUIRE_FALSE(instance->is_running()); - } - - THEN("round_number() returns invalid_round_number") - { - REQUIRE(instance->round_number() == turn_order::invalid_round_number); - } - - WHEN("the turn_order is start()ed") - { - instance->start(); - - THEN("get_n_items() still returns 1") - { - REQUIRE(instance->get_n_items() == 1); - } - - THEN("get_typed_object(0) still returns a non-null pointer") - { - REQUIRE(instance->get_typed_object(0) != nullptr); - } - - THEN("has_next() still returns true") - { - REQUIRE(instance->has_next()); - } - - THEN("has_previous() still returns false") - { - REQUIRE_FALSE(instance->has_previous()); - } - - THEN("is_empty() still returns false") - { - REQUIRE_FALSE(instance->is_empty()); - } - - THEN("is_running() returns true") - { - REQUIRE(instance->is_running()); - } - - THEN("round_number() returns 0") - { - REQUIRE(instance->round_number() == 0); - } - - AND_WHEN("invoking previous()") - { - instance->previous(); - - THEN("get_n_items() still returns 1") - { - REQUIRE(instance->get_n_items() == 1); - } - - THEN("get_typed_object(0) still returns a non-null pointer") - { - REQUIRE(instance->get_typed_object(0) != nullptr); - } - - THEN("has_next() still returns true") - { - REQUIRE(instance->has_next()); - } - - THEN("has_previous() still returns false") - { - REQUIRE_FALSE(instance->has_previous()); - } - - THEN("is_empty() still returns false") - { - REQUIRE_FALSE(instance->is_empty()); - } - - THEN("is_running() returns true") - { - REQUIRE(instance->is_running()); - } - - THEN("round_number() returns 0") - { - REQUIRE(instance->round_number() == 0); - } - } - - AND_WHEN("invoking next()") - { - instance->next(); - - THEN("get_n_items() still returns 1") - { - REQUIRE(instance->get_n_items() == 1); - } - - THEN("get_typed_object(0) still returns a non-null pointer") - { - REQUIRE(instance->get_typed_object(0) != nullptr); - } - - THEN("has_next() still returns true") - { - REQUIRE(instance->has_next()); - } - - THEN("has_previous() returns true") - { - REQUIRE(instance->has_previous()); - } - - THEN("is_empty() still returns false") - { - REQUIRE_FALSE(instance->is_empty()); - } - - THEN("is_running() returns true") - { - REQUIRE(instance->is_running()); - } - - THEN("round_number() returns 1") - { - REQUIRE(instance->round_number() == 1); - } - } - } - } - } - - SCENARIO("Loading from json data") - { - GIVEN("an empty turn order") - { - auto instance = turn_order{}; - CHECK(instance.is_empty()); - - WHEN("loading a serialized turn order with one named participant") - { - auto data = Gio::Resource::lookup_data_global("/ch/arknet/Turns/core-tests/single_participant.trns"); - auto size = 0uz; - instance.load(nlohmann::json::parse(std::string_view{static_cast(data->get_data(size)), data->get_size()})); - - THEN("it is no longer empty") - { - REQUIRE_FALSE(instance.is_empty()); - } - - THEN("it has 1 element") - { - REQUIRE(instance.get_n_items() == 1); - } - - THEN("the single participant's name is set") - { - auto participant = instance.get_typed_object(0); - REQUIRE_FALSE(participant->get_name().empty()); - } - - AND_THEN("adding another participant with a higher priority") - { - auto participant = instance.get_typed_object(0); - instance.add("Higher Priority", 100.0f, Disposition::Neutral); - - THEN("the index of the test participant is 1") - { - CHECK(instance.get_typed_object(0) != participant); - REQUIRE(instance.get_typed_object(1) == participant); - } - } - - AND_WHEN("calling clear") - { - instance.clear(); - - THEN("it is empty") - { - REQUIRE(instance.is_empty()); - } - } - } - } - } - - SCENARIO("Sorting of participants") - { - GIVEN("A turn order with 3 participants (A,B,C) of priorities 100, 0, and -100 respectively") - { - auto instance = turn_order{}; - - instance.add("A", 100, Disposition::Friendly); - instance.add("B", 0, Disposition::Friendly); - instance.add("C", -100, Disposition::Friendly); - - THEN("A comes before B comes before C") - { - REQUIRE(instance.get_typed_object(0)->get_name() == "A"); - REQUIRE(instance.get_typed_object(1)->get_name() == "B"); - REQUIRE(instance.get_typed_object(2)->get_name() == "C"); - } - - WHEN("changing the priority of the B to 50") - { - instance.get_typed_object(1)->set_priority(50); - - THEN("the order stays the same") - { - REQUIRE(instance.get_typed_object(0)->get_name() == "A"); - REQUIRE(instance.get_typed_object(1)->get_name() == "B"); - REQUIRE(instance.get_typed_object(2)->get_name() == "C"); - } - } - } - } - -} // namespace turns::core::tests \ No newline at end of file diff --git a/core/tests/turn_order_bugs.cpp b/core/tests/turn_order_bugs.cpp index a79e9b4..7bfde78 100644 --- a/core/tests/turn_order_bugs.cpp +++ b/core/tests/turn_order_bugs.cpp @@ -1,5 +1,5 @@ #include "turns/core/disposition.hpp" -#include "turns/core/turn_order.hpp" +#include "turns/core/turn_order_model.hpp" #include @@ -17,7 +17,7 @@ namespace turns::core::tests { GIVEN("a non-empty turn_order") { - auto instance = turn_order::create(); + auto instance = TurnOderModel::create(); instance->add("A", 0, Disposition::Neutral); diff --git a/core/tests/turn_order_model.cpp b/core/tests/turn_order_model.cpp new file mode 100644 index 0000000..1cd3633 --- /dev/null +++ b/core/tests/turn_order_model.cpp @@ -0,0 +1,314 @@ +#include "turns/core/turn_order_model.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" + +#include + +#include + +#include + +#include + +namespace turns::core::tests +{ + SCENARIO("Queries on a fresh turn_order instance", "[turn_order]") + { + GIVEN("an empty turn_order") + { + auto instance = TurnOderModel::create(); + + THEN("get_n_items() returns 0") + { + REQUIRE(instance->get_n_items() == 0); + } + + THEN("get_type() returns participant::get_type()") + { + REQUIRE(instance->get_item_type() == Participant::get_type()); + } + + THEN("get_typed_object(0) returns nullptr") + { + REQUIRE(instance->get_typed_object(0) == nullptr); + } + + THEN("has_next() returns false") + { + REQUIRE_FALSE(instance->has_next()); + } + + THEN("has_previous() returns false") + { + REQUIRE_FALSE(instance->has_previous()); + } + + THEN("is_empty() returns true") + { + REQUIRE(instance->is_empty()); + } + + THEN("is_running() returns false") + { + REQUIRE_FALSE(instance->is_running()); + } + + THEN("round_number() returns invalid_round_number") + { + REQUIRE(instance->round_number() == TurnOderModel::invalid_round_number); + } + } + } + + SCENARIO("Adding participants") + { + auto instance = TurnOderModel::create(); + + GIVEN("a participant has been added to a turn_order") + { + instance->add("Participant #0", 0, Disposition::Neutral); + + THEN("get_n_items() returns 1") + { + REQUIRE(instance->get_n_items() == 1); + } + + THEN("get_typed_object(0) returns a non-null pointer") + { + REQUIRE(instance->get_typed_object(0) != nullptr); + } + + THEN("has_next() returns true") + { + REQUIRE(instance->has_next()); + } + + THEN("has_previous() returns false") + { + REQUIRE_FALSE(instance->has_previous()); + } + + THEN("is_empty() returns false") + { + REQUIRE_FALSE(instance->is_empty()); + } + + THEN("is_running() returns false") + { + REQUIRE_FALSE(instance->is_running()); + } + + THEN("round_number() returns invalid_round_number") + { + REQUIRE(instance->round_number() == TurnOderModel::invalid_round_number); + } + + WHEN("the turn_order is start()ed") + { + instance->start(); + + THEN("get_n_items() still returns 1") + { + REQUIRE(instance->get_n_items() == 1); + } + + THEN("get_typed_object(0) still returns a non-null pointer") + { + REQUIRE(instance->get_typed_object(0) != nullptr); + } + + THEN("has_next() still returns true") + { + REQUIRE(instance->has_next()); + } + + THEN("has_previous() still returns false") + { + REQUIRE_FALSE(instance->has_previous()); + } + + THEN("is_empty() still returns false") + { + REQUIRE_FALSE(instance->is_empty()); + } + + THEN("is_running() returns true") + { + REQUIRE(instance->is_running()); + } + + THEN("round_number() returns 0") + { + REQUIRE(instance->round_number() == 0); + } + + AND_WHEN("invoking previous()") + { + instance->previous(); + + THEN("get_n_items() still returns 1") + { + REQUIRE(instance->get_n_items() == 1); + } + + THEN("get_typed_object(0) still returns a non-null pointer") + { + REQUIRE(instance->get_typed_object(0) != nullptr); + } + + THEN("has_next() still returns true") + { + REQUIRE(instance->has_next()); + } + + THEN("has_previous() still returns false") + { + REQUIRE_FALSE(instance->has_previous()); + } + + THEN("is_empty() still returns false") + { + REQUIRE_FALSE(instance->is_empty()); + } + + THEN("is_running() returns true") + { + REQUIRE(instance->is_running()); + } + + THEN("round_number() returns 0") + { + REQUIRE(instance->round_number() == 0); + } + } + + AND_WHEN("invoking next()") + { + instance->next(); + + THEN("get_n_items() still returns 1") + { + REQUIRE(instance->get_n_items() == 1); + } + + THEN("get_typed_object(0) still returns a non-null pointer") + { + REQUIRE(instance->get_typed_object(0) != nullptr); + } + + THEN("has_next() still returns true") + { + REQUIRE(instance->has_next()); + } + + THEN("has_previous() returns true") + { + REQUIRE(instance->has_previous()); + } + + THEN("is_empty() still returns false") + { + REQUIRE_FALSE(instance->is_empty()); + } + + THEN("is_running() returns true") + { + REQUIRE(instance->is_running()); + } + + THEN("round_number() returns 1") + { + REQUIRE(instance->round_number() == 1); + } + } + } + } + } + + SCENARIO("Loading from json data") + { + GIVEN("an empty turn order") + { + auto instance = TurnOderModel{}; + CHECK(instance.is_empty()); + + WHEN("loading a serialized turn order with one named participant") + { + auto data = Gio::Resource::lookup_data_global("/ch/arknet/Turns/core-tests/single_participant.trns"); + auto size = 0uz; + instance.load(nlohmann::json::parse(std::string_view{static_cast(data->get_data(size)), data->get_size()})); + + THEN("it is no longer empty") + { + REQUIRE_FALSE(instance.is_empty()); + } + + THEN("it has 1 element") + { + REQUIRE(instance.get_n_items() == 1); + } + + THEN("the single participant's name is set") + { + auto participant = instance.get_typed_object(0); + REQUIRE_FALSE(participant->get_name().empty()); + } + + AND_THEN("adding another participant with a higher priority") + { + auto participant = instance.get_typed_object(0); + instance.add("Higher Priority", 100.0f, Disposition::Neutral); + + THEN("the index of the test participant is 1") + { + CHECK(instance.get_typed_object(0) != participant); + REQUIRE(instance.get_typed_object(1) == participant); + } + } + + AND_WHEN("calling clear") + { + instance.clear(); + + THEN("it is empty") + { + REQUIRE(instance.is_empty()); + } + } + } + } + } + + SCENARIO("Sorting of participants") + { + GIVEN("A turn order with 3 participants (A,B,C) of priorities 100, 0, and -100 respectively") + { + auto instance = TurnOderModel{}; + + instance.add("A", 100, Disposition::Friendly); + instance.add("B", 0, Disposition::Friendly); + instance.add("C", -100, Disposition::Friendly); + + THEN("A comes before B comes before C") + { + REQUIRE(instance.get_typed_object(0)->get_name() == "A"); + REQUIRE(instance.get_typed_object(1)->get_name() == "B"); + REQUIRE(instance.get_typed_object(2)->get_name() == "C"); + } + + WHEN("changing the priority of the B to 50") + { + instance.get_typed_object(1)->set_priority(50); + + THEN("the order stays the same") + { + REQUIRE(instance.get_typed_object(0)->get_name() == "A"); + REQUIRE(instance.get_typed_object(1)->get_name() == "B"); + REQUIRE(instance.get_typed_object(2)->get_name() == "C"); + } + } + } + } + +} // namespace turns::core::tests \ No newline at end of file -- cgit v1.2.3