diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-23 14:04:27 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-23 14:04:27 +0200 |
| commit | 5d8f799a1171f92054d4b45ba130cd7fdad0bd01 (patch) | |
| tree | 0f51290b3a60d71d25d7a49b66d5bd54dd7a4156 /core/tests | |
| parent | c45004b73bb045328a724d1d860df6d1515af6d4 (diff) | |
| download | turns-5d8f799a1171f92054d4b45ba130cd7fdad0bd01.tar.xz turns-5d8f799a1171f92054d4b45ba130cd7fdad0bd01.zip | |
app: prepare restructuring
Diffstat (limited to 'core/tests')
| -rw-r--r-- | core/tests/disposition.cpp | 32 | ||||
| -rw-r--r-- | core/tests/glib_test_init.cpp | 28 | ||||
| -rw-r--r-- | core/tests/participant.cpp | 310 | ||||
| -rw-r--r-- | core/tests/single_participant.trns | 11 | ||||
| -rw-r--r-- | core/tests/turn_order_bugs.cpp | 40 | ||||
| -rw-r--r-- | core/tests/turn_order_model.cpp | 314 |
6 files changed, 0 insertions, 735 deletions
diff --git a/core/tests/disposition.cpp b/core/tests/disposition.cpp deleted file mode 100644 index fadf476..0000000 --- a/core/tests/disposition.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "turns/core/disposition.hpp" - -#include <catch2/catch_test_macros.hpp> -#include <catch2/generators/catch_generators.hpp> - -#include <glibmm/i18n.h> -#include <glibmm/ustring.h> - -#include <format> -#include <limits> -#include <type_traits> -#include <utility> - -namespace turns::core::tests -{ - - TEST_CASE("to_presentation_name returns the correct string for the current language", "[disposition]") - { - auto [value, name] = GENERATE(std::pair{Disposition::Neutral, Glib::ustring{_("Neutral")}}, - std::pair{Disposition::Friendly, Glib::ustring{_("Friendly")}}, - std::pair{Disposition::Hostile, Glib::ustring{_("Hostile")}}, - std::pair{Disposition::Secret, Glib::ustring{_("Secret")}}, - std::pair{static_cast<Disposition>(std::numeric_limits<std::underlying_type_t<Disposition>>::max()), - Glib::ustring{_("Unknown disposition value")}}); - - SECTION(std::format("the presentation name for '{}' is '{}'", static_cast<std::underlying_type_t<Disposition>>(value), name.c_str())) - { - REQUIRE(presentation_name_for(value) == name); - } - } - -} // namespace turns::core::tests
\ No newline at end of file diff --git a/core/tests/glib_test_init.cpp b/core/tests/glib_test_init.cpp deleted file mode 100644 index b521189..0000000 --- a/core/tests/glib_test_init.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "turns/core/init.hpp" - -#include <catch2/reporters/catch_reporter_event_listener.hpp> -#include <catch2/reporters/catch_reporter_registrars.hpp> - -#include <glibmm/init.h> - -#include <giomm/init.h> - -namespace turns::core::tests -{ - - struct glib_test_init : Catch::EventListenerBase - { - using Catch::EventListenerBase::EventListenerBase; - - auto testRunStarting(Catch::TestRunInfo const &) -> void override - { - Gio::init(); - Glib::init(); - - register_types(); - } - }; - - CATCH_REGISTER_LISTENER(glib_test_init); - -} // namespace turns::core::tests
\ No newline at end of file diff --git a/core/tests/participant.cpp b/core/tests/participant.cpp deleted file mode 100644 index b417e36..0000000 --- a/core/tests/participant.cpp +++ /dev/null @@ -1,310 +0,0 @@ -#include "turns/core/participant.hpp" - -#include "turns/core/disposition.hpp" - -#include <catch2/catch_approx.hpp> -#include <catch2/catch_test_macros.hpp> - -#include <nlohmann/json.hpp> - -#include <compare> - -namespace turns::core::tests -{ - - TEST_CASE("Constructing a participant", "[core][construction]") - { - auto constexpr name = "Participant #1"; - auto constexpr priority = 17; - auto constexpr disposition = Disposition::Friendly; - - auto json = nlohmann::json::parse(R"( - { - "name": "Participant #1", - "priority": 17, - "disposition": 1, - "is-active": false, - "is-defeated": false - } - )"); - - SECTION("Can be constructed using default ctor") - { - auto instance = Participant{}; - REQUIRE(instance.property_name() == ""); - REQUIRE(instance.property_priority() == 0); - REQUIRE(instance.property_disposition() == Disposition::Neutral); - REQUIRE(!instance.property_is_active()); - REQUIRE(!instance.property_is_defeated()); - } - - SECTION("Can be constructed using ctor") - { - auto instance = Participant{name, priority, disposition}; - REQUIRE(instance.property_name() == name); - REQUIRE(instance.property_priority() == priority); - REQUIRE(instance.property_disposition() == disposition); - REQUIRE(!instance.property_is_active()); - REQUIRE(!instance.property_is_defeated()); - } - - SECTION("Can be constructed using factory") - { - auto instance = Participant::create(name, priority, disposition); - REQUIRE(instance->property_name() == name); - REQUIRE(instance->property_priority() == priority); - REQUIRE(instance->property_disposition() == disposition); - REQUIRE(!instance->property_is_active()); - REQUIRE(!instance->property_is_defeated()); - } - - SECTION("Can be constructed using JSON factory", "[json]") - { - auto instance = Participant::create(json); - REQUIRE(instance->property_name() == name); - REQUIRE(instance->property_priority() == priority); - REQUIRE(instance->property_disposition() == disposition); - REQUIRE(!instance->property_is_active()); - REQUIRE(!instance->property_is_defeated()); - } - } - - TEST_CASE("Setting properties on participant", "[core][properties]") - { - auto constexpr name = "Participant #2"; - auto constexpr priority = 10; - auto constexpr disposition = Disposition::Hostile; - - auto instance = Participant{name, priority, disposition}; - - SECTION("Setting '::disposition' via proxy changes the 'disposition' value") - { - auto old = instance.property_disposition().get_value(); - instance.property_disposition() = static_cast<core::Disposition>(static_cast<int>(disposition) - 1); - REQUIRE(instance.property_disposition() != old); - } - - SECTION("Setting '::disposition' via glib changes the 'disposition' value") - { - auto old = instance.property_disposition().get_value(); - instance.set_property("disposition", static_cast<core::Disposition>(static_cast<int>(disposition) - 1)); - REQUIRE(instance.property_disposition() != old); - } - - SECTION("Setting '::is-active' via proxy changes the 'is_active' value") - { - auto old = instance.property_is_active().get_value(); - instance.property_is_active() = !old; - REQUIRE(instance.property_is_active() != old); - } - - SECTION("Setting '::is-active' via glib changes the 'is_active' value") - { - auto old = instance.property_is_active().get_value(); - instance.set_property("is-active", !old); - REQUIRE(instance.property_is_active() != old); - } - - SECTION("Setting '::is-defeated' via proxy changes the 'is_defeated' value") - { - auto old = instance.property_is_defeated().get_value(); - instance.property_is_defeated() = !old; - REQUIRE(instance.property_is_defeated() != old); - } - - SECTION("Setting '::is-defeated' via glib changes the 'is_defeated' value") - { - auto old = instance.property_is_defeated().get_value(); - instance.set_property("is-defeated", !old); - REQUIRE(instance.property_is_defeated() != old); - } - - SECTION("Setting '::name' via proxy changes the 'name' value") - { - auto old = instance.property_name().get_value(); - instance.property_name() = old + " Changed"; - REQUIRE(instance.property_name().get_value() != old); - } - - SECTION("Setting '::name' via glib changes the 'name' value") - { - auto old = instance.property_name().get_value(); - instance.set_property("name", old + " Changed"); - REQUIRE(instance.property_name().get_value() != old); - } - - SECTION("Setting '::priority' via proxy changes the 'priority' value") - { - auto old = instance.property_priority().get_value(); - instance.property_priority() = old + 1; - REQUIRE(instance.property_priority() != old); - } - - SECTION("Setting '::priority' via glib changes the 'priority' value") - { - auto old = instance.property_priority().get_value(); - instance.set_property("priority", old + 1); - REQUIRE(instance.property_priority() != old); - } - } - - TEST_CASE("A freshly constructed participant") - { - auto constexpr constructed_name = "Vana Thistletop"; - auto constexpr constructed_priority = 17; - auto constexpr constructed_disposition = Disposition::Friendly; - auto instance = Participant{constructed_name, constructed_priority, constructed_disposition}; - - SECTION("can be created") - { - REQUIRE(Participant::create(constructed_name, constructed_priority, constructed_disposition)); - } - - SECTION("allows access to its disposition") - { - SECTION("allowing to get it") - { - REQUIRE(instance.property_disposition() == constructed_disposition); - } - - SECTION("allowing to get it via a constant object") - { - auto const & cref = instance; - REQUIRE(cref.property_disposition() == constructed_disposition); - } - - SECTION("allowing to set it") - { - instance.property_disposition() = Disposition::Hostile; - REQUIRE(instance.property_disposition() == Disposition::Hostile); - } - } - - SECTION("allows access to its name") - { - SECTION("allowing to get it") - { - REQUIRE(instance.property_name() == constructed_name); - } - - SECTION("allowing to get it via a constant object") - { - auto const & cref = instance; - REQUIRE(cref.property_name() == constructed_name); - } - - SECTION("allowing to set it") - { - instance.property_name() = "replaced"; - REQUIRE(instance.property_name() == "replaced"); - } - } - - SECTION("allows access to its priority") - { - SECTION("allowing to get it") - { - REQUIRE(instance.property_priority() == constructed_priority); - } - - SECTION("allowing to get it via a constant object") - { - auto const & cref = instance; - REQUIRE(cref.property_priority() == constructed_priority); - } - - SECTION("allowing to set it") - { - instance.property_priority() = 4; - REQUIRE(instance.property_priority() == 4); - } - } - - SECTION("can be compared with another participant") - { - auto equivalent_instance = Participant{"Equivalent", constructed_priority, constructed_disposition}; - auto lesser_instance = Participant{"Lesser", constructed_priority - 1, constructed_disposition}; - auto greater_instance = Participant{"Greater", constructed_priority + 1, constructed_disposition}; - - SECTION("yielding std::partial_ordering::equivalent for itself") - { - REQUIRE((instance <=> equivalent_instance) == std::partial_ordering::equivalent); - } - - SECTION("yielding std::partial_ordering::equivalent for an equivalent participant") - { - REQUIRE((instance <=> equivalent_instance) == std::partial_ordering::equivalent); - } - - SECTION("yielding std::partial_ordering::greater for a lesser participant") - { - REQUIRE((instance <=> lesser_instance) == std::partial_ordering::greater); - } - - SECTION("yielding std::partial_ordering::less for a greater participant") - { - REQUIRE((instance <=> greater_instance) == std::partial_ordering::less); - } - } - } - - TEST_CASE("Serializing a participant") - { - auto instance = Participant::create("Participant #0", 17.2, Disposition::Friendly); - auto serialized = instance->serialize(); - - SECTION("the active state is serialized correctly") - { - REQUIRE_FALSE(serialized.at("is-active")); - } - - SECTION("the disposition is serialized correctly") - { - REQUIRE(serialized.at("disposition") == Disposition::Friendly); - } - - SECTION("the name is serialized correctly") - { - REQUIRE(serialized.at("name") == "Participant #0"); - } - - SECTION("the priority is serialized correctly") - { - REQUIRE(serialized.at("priority") == Catch::Approx{17.2}); - } - } - - TEST_CASE("De-Serializing a participant") - { - auto serialized = nlohmann::json::parse(R"( - { - "name": "Participant #1", - "priority": -2.3, - "disposition": 2, - "is-active": true - } - )"); - auto instance = Participant::create(serialized); - - SECTION("the active state is de-serialized correctly") - { - REQUIRE(instance->property_is_active()); - } - - SECTION("the disposition is de-serialized correctly") - { - REQUIRE(instance->property_disposition() == Disposition::Hostile); - } - - SECTION("the name is de-serialized correctly") - { - REQUIRE(instance->property_name() == "Participant #1"); - } - - SECTION("the priority is de-serialized correctly") - { - REQUIRE(instance->property_priority() == Catch::Approx{-2.3}); - } - } - -} // namespace turns::core::tests
\ No newline at end of file diff --git a/core/tests/single_participant.trns b/core/tests/single_participant.trns deleted file mode 100644 index bcce137..0000000 --- a/core/tests/single_participant.trns +++ /dev/null @@ -1,11 +0,0 @@ -{ - "participants": [ - { - "disposition": 0, - "is-active": false, - "is-defeated": false, - "name": "Riamin", - "priority": 0.0 - } - ] -}
\ No newline at end of file diff --git a/core/tests/turn_order_bugs.cpp b/core/tests/turn_order_bugs.cpp deleted file mode 100644 index 7bfde78..0000000 --- a/core/tests/turn_order_bugs.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "turns/core/disposition.hpp" -#include "turns/core/turn_order_model.hpp" - -#include <catch2/catch_test_macros.hpp> - -namespace turns::core::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 = TurnOderModel::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::core::tests
\ No newline at end of file diff --git a/core/tests/turn_order_model.cpp b/core/tests/turn_order_model.cpp deleted file mode 100644 index 1cd3633..0000000 --- a/core/tests/turn_order_model.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "turns/core/turn_order_model.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" - -#include <catch2/catch_test_macros.hpp> - -#include <giomm/resource.h> - -#include <nlohmann/json.hpp> - -#include <string_view> - -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<Participant>(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<Participant>(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<Participant>(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<Participant>(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<Participant>(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<char const *>(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<Participant>(0); - REQUIRE_FALSE(participant->get_name().empty()); - } - - AND_THEN("adding another participant with a higher priority") - { - auto participant = instance.get_typed_object<Participant>(0); - instance.add("Higher Priority", 100.0f, Disposition::Neutral); - - THEN("the index of the test participant is 1") - { - CHECK(instance.get_typed_object<Participant>(0) != participant); - REQUIRE(instance.get_typed_object<Participant>(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<Participant>(0)->get_name() == "A"); - REQUIRE(instance.get_typed_object<Participant>(1)->get_name() == "B"); - REQUIRE(instance.get_typed_object<Participant>(2)->get_name() == "C"); - } - - WHEN("changing the priority of the B to 50") - { - instance.get_typed_object<Participant>(1)->set_priority(50); - - THEN("the order stays the same") - { - REQUIRE(instance.get_typed_object<Participant>(0)->get_name() == "A"); - REQUIRE(instance.get_typed_object<Participant>(1)->get_name() == "B"); - REQUIRE(instance.get_typed_object<Participant>(2)->get_name() == "C"); - } - } - } - } - -} // namespace turns::core::tests
\ No newline at end of file |
