diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-23 15:08:19 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-23 15:08:19 +0200 |
| commit | 4ec6a2ae12b6adb843c0777649ff45a741ca6cbc (patch) | |
| tree | 93dc2ba99dbcb42b2af73f0a3c4cd4f0c0f091c4 /domain/tests | |
| parent | 5f4249a37ce816b8deceb299bc841190fbb15983 (diff) | |
| download | turns-4ec6a2ae12b6adb843c0777649ff45a741ca6cbc.tar.xz turns-4ec6a2ae12b6adb843c0777649ff45a741ca6cbc.zip | |
domain: redesign turn_order
Diffstat (limited to 'domain/tests')
| -rw-r--r-- | domain/tests/participant.cpp | 90 | ||||
| -rw-r--r-- | domain/tests/register_types.cpp | 13 | ||||
| -rw-r--r-- | domain/tests/turn_order.cpp | 434 |
3 files changed, 126 insertions, 411 deletions
diff --git a/domain/tests/participant.cpp b/domain/tests/participant.cpp index dd244f4..e4e185c 100644 --- a/domain/tests/participant.cpp +++ b/domain/tests/participant.cpp @@ -22,123 +22,63 @@ namespace turns::domain::tests REQUIRE(participant::create(constructed_name, constructed_priority, constructed_disposition)); } - SECTION("allows access to its disposition via the associated accessors") + SECTION("allows access to its disposition") { SECTION("allowing to get it") { - REQUIRE(instance.get_disposition() == constructed_disposition); + REQUIRE(instance.disposition() == constructed_disposition); } SECTION("allowing to get it via a constant object") { auto const & cref = instance; - REQUIRE(cref.get_disposition() == constructed_disposition); + REQUIRE(cref.disposition() == constructed_disposition); } SECTION("allowing to set it") { - instance.set_disposition(disposition::hostile); - REQUIRE(instance.get_disposition() == disposition::hostile); + instance.disposition() = disposition::hostile; + REQUIRE(instance.disposition() == disposition::hostile); } } - SECTION("allows access to its disposition via the associated property") + SECTION("allows access to its name") { SECTION("allowing to get it") { - REQUIRE(instance.property_disposition() == constructed_disposition); + REQUIRE(instance.name() == constructed_name); } SECTION("allowing to get it via a constant object") { auto const & cref = instance; - REQUIRE(cref.property_disposition() == constructed_disposition); + REQUIRE(cref.name() == constructed_name); } SECTION("allowing to set it") { - instance.property_disposition() = disposition::hostile; - REQUIRE(instance.get_disposition() == disposition::hostile); + instance.name() = "replaced"; + REQUIRE(instance.name() == "replaced"); } } - SECTION("allows access to its name via the associated accessors") + SECTION("allows access to its priority") { SECTION("allowing to get it") { - REQUIRE(instance.get_name() == constructed_name); + REQUIRE(instance.priority() == constructed_priority); } SECTION("allowing to get it via a constant object") { auto const & cref = instance; - REQUIRE(cref.get_name() == constructed_name); + REQUIRE(cref.priority() == constructed_priority); } SECTION("allowing to set it") { - instance.set_name("replaced"); - REQUIRE(instance.get_name() == "replaced"); - } - } - - SECTION("allows access to its name via the associated property") - { - 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.get_name() == "replaced"); - } - } - - SECTION("allows access to its priority via the associated accessors") - { - SECTION("allowing to get it") - { - REQUIRE(instance.get_priority() == constructed_priority); - } - - SECTION("allowing to get it via a constant object") - { - auto const & cref = instance; - REQUIRE(cref.get_priority() == constructed_priority); - } - - SECTION("allowing to set it") - { - instance.set_priority(3); - REQUIRE(instance.get_priority() == 3); - } - } - - SECTION("allows access to its priority via the associated property") - { - 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.get_priority() == 4); + instance.priority() = 4; + REQUIRE(instance.priority() == 4); } } diff --git a/domain/tests/register_types.cpp b/domain/tests/register_types.cpp new file mode 100644 index 0000000..de8bb52 --- /dev/null +++ b/domain/tests/register_types.cpp @@ -0,0 +1,13 @@ +#include "turns/domain/participant.hpp" +#include "turns/domain/turn_order.hpp" + +namespace turns::tests +{ + + auto register_types() -> void + { + static_cast<void>(domain::participant{}); + static_cast<void>(domain::turn_order{}); + } + +} // namespace turns::tests
\ No newline at end of file diff --git a/domain/tests/turn_order.cpp b/domain/tests/turn_order.cpp index de1689c..eb05581 100644 --- a/domain/tests/turn_order.cpp +++ b/domain/tests/turn_order.cpp @@ -1,459 +1,221 @@ #include "turns/domain/turn_order.hpp" +#include "turns/domain/participant.hpp" + #include <catch2/catch_test_macros.hpp> -#include <glibmm/ustring.h> +#include <giomm/liststore.h> namespace turns::domain::tests { - SCENARIO("Queries on a fresh turn_order instance", "[turn_order]") { GIVEN("an empty turn_order") { auto instance = turn_order::create(); - THEN("active_participant() is turn_order::invalid_participant_index") + THEN("get_n_items() returns 0") { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); + auto str = Gio::ListStore<Glib::Object>::create(); + REQUIRE(instance->get_n_items() == str->get_n_items()); } - THEN("empty() is true") + THEN("get_type() returns participant::get_type()") { - REQUIRE(instance->empty()); + REQUIRE(instance->get_item_type() == participant::get_type()); } - THEN("get() returns a nullptr") + THEN("get_typed_object(0) returns nullptr") { - REQUIRE(instance->get(0) == nullptr); + REQUIRE(instance->get_typed_object<participant>(0) == nullptr); } - THEN("list_model() returns a non-null pointer") + THEN("has_next() returns false") { - REQUIRE(instance->list_model()); + REQUIRE_FALSE(instance->has_next()); } - THEN("round() returns 0") + THEN("has_previous() returns false") { - REQUIRE(instance->round() == 0); + REQUIRE_FALSE(instance->has_previous()); } - THEN("running() returns false") + THEN("is_empty() returns true") { - REQUIRE_FALSE(instance->running()); + REQUIRE(instance->is_empty()); } - THEN("size() returns 0") + THEN("is_running() returns false") { - REQUIRE(instance->size() == 0); + REQUIRE_FALSE(instance->is_running()); } - THEN("size() returns the same value as list_model()->get_n_item()") + THEN("round_number() returns invalid_round_number") { - REQUIRE(instance->size() == instance->list_model()->get_n_items()); + REQUIRE(instance->round_number() == turn_order::invalid_round_number); } + } + } - WHEN("accessing turn_order:active-participant") - { - THEN("get() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->property_active_participant().get_value() == turn_order::invalid_participant_index); - } + SCENARIO("Adding participants") + { + auto instance = turn_order::create(); - THEN("get_object() returns a pointer to the instance") - { - REQUIRE(instance->property_active_participant().get_object() == instance.get()); - } + GIVEN("a participant has been added to a turn_order") + { + instance->add("Participant #0", 0, disposition::neutral); - THEN("get_name() returns \"active-participant\"") - { - REQUIRE(instance->property_active_participant().get_name() == Glib::ustring{"active-participant"}); - } + THEN("get_n_items() returns 1") + { + REQUIRE(instance->get_n_items() == 1); } - WHEN("accessing turn_order:empty") + THEN("get_typed_object(0) returns a non-null pointer") { - THEN("get() returns true") - { - REQUIRE(instance->property_empty().get_value()); - } - - THEN("get_object() returns a pointer to the instance") - { - REQUIRE(instance->property_empty().get_object() == instance.get()); - } - - THEN("get_name() returns \"empty\"") - { - REQUIRE(instance->property_empty().get_name() == Glib::ustring{"empty"}); - } + REQUIRE(instance->get_typed_object<participant>(0) != nullptr); } - WHEN("accessing turn_order:has-next") + THEN("has_next() returns true") { - THEN("get() returns false") - { - REQUIRE_FALSE(instance->property_has_next().get_value()); - } - - THEN("get_object() returns a pointer to the instance") - { - REQUIRE(instance->property_has_next().get_object() == instance.get()); - } + REQUIRE(instance->has_next()); + } - THEN("get_name() returns \"has-next\"") - { - REQUIRE(instance->property_has_next().get_name() == Glib::ustring{"has-next"}); - } + THEN("has_previous() returns false") + { + REQUIRE_FALSE(instance->has_previous()); } - WHEN("accessing turn_order:has-previous") + THEN("is_empty() returns false") { - THEN("get() returns false") - { - REQUIRE_FALSE(instance->property_has_previous().get_value()); - } + REQUIRE_FALSE(instance->is_empty()); + } - THEN("get_object() returns a pointer to the instance") - { - REQUIRE(instance->property_has_previous().get_object() == instance.get()); - } + THEN("is_running() returns false") + { + REQUIRE_FALSE(instance->is_running()); + } - THEN("get_name() returns \"has-previous\"") - { - REQUIRE(instance->property_has_previous().get_name() == Glib::ustring{"has-previous"}); - } + THEN("round_number() returns invalid_round_number") + { + REQUIRE(instance->round_number() == turn_order::invalid_round_number); } - WHEN("accessing turn_order:running") + WHEN("the turn_order is start()ed") { - THEN("get() returns false") + instance->start(); + + THEN("get_n_items() still returns 1") { - REQUIRE_FALSE(instance->property_running().get_value()); + REQUIRE(instance->get_n_items() == 1); } - THEN("get_object() returns a pointer to the instance") + THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->property_running().get_object() == instance.get()); + REQUIRE(instance->get_typed_object<participant>(0) != nullptr); } - THEN("get_name() returns \"running\"") + THEN("has_next() still returns true") { - REQUIRE(instance->property_running().get_name() == Glib::ustring{"running"}); + REQUIRE(instance->has_next()); } - } - WHEN("accessing turn_order:running") - { - THEN("get() returns 0") + THEN("has_previous() still returns false") { - REQUIRE(instance->property_round().get_value() == 0); + REQUIRE_FALSE(instance->has_previous()); } - THEN("get_object() returns a pointer to the instance") + THEN("is_empty() still returns false") { - REQUIRE(instance->property_round().get_object() == instance.get()); + REQUIRE_FALSE(instance->is_empty()); } - THEN("get_name() returns \"round\"") + THEN("is_running() returns true") { - REQUIRE(instance->property_round().get_name() == Glib::ustring{"round"}); + REQUIRE(instance->is_running()); } - } - } - } - - SCENARIO("Modification of an empty turn_order", "[turn_order]") - { - auto instance = turn_order::create(); - - GIVEN("a single participant was added") - { - auto constexpr priority = 12.0f; - instance->add("Participant #0", priority, disposition::friendly); - AND_GIVEN("the turn_order was never started") - { - WHEN("no other modification occurs") + THEN("round_number() returns 0") { - THEN("active_participant() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); - } - - THEN("empty() returns false") - { - REQUIRE_FALSE(instance->empty()); - } - - THEN("get() returns a valid pointer for index 0") - { - REQUIRE(instance->get(0)); - } - - THEN("get() returns a nullptr for an index greater than 0") - { - REQUIRE(instance->get(1) == nullptr); - } - - THEN("round() returns 0") - { - REQUIRE(instance->round() == 0); - } - - THEN("running() returns false") - { - REQUIRE_FALSE(instance->running()); - } - - THEN("size() returns 1") - { - REQUIRE(instance->size() == 1); - } - - THEN("turn_order:has-next is false") - { - REQUIRE(instance->property_has_next() == false); - } - - THEN("turn_order:has-previous is false") - { - REQUIRE(instance->property_has_previous() == false); - } - - THEN("turn_order:running is false") - { - REQUIRE(instance->property_running() == false); - } + REQUIRE(instance->round_number() == 0); } - WHEN("the participant is removed again") + AND_WHEN("invoking previous()") { - instance->remove(0); - - THEN("active_participant() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); - } - - THEN("empty() returns true") - { - REQUIRE(instance->empty()); - } + instance->previous(); - THEN("get() returns a nullptr for index 0") + THEN("get_n_items() still returns 1") { - REQUIRE(instance->get(0) == nullptr); + REQUIRE(instance->get_n_items() == 1); } - THEN("round() returns 0") + THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->round() == 0); + REQUIRE(instance->get_typed_object<participant>(0) != nullptr); } - THEN("running() returns false") + THEN("has_next() still returns true") { - REQUIRE_FALSE(instance->running()); + REQUIRE(instance->has_next()); } - THEN("size() returns 0") + THEN("has_previous() still returns false") { - REQUIRE(instance->size() == 0); + REQUIRE_FALSE(instance->has_previous()); } - THEN("turn_order:has-next is false") + THEN("is_empty() still returns false") { - REQUIRE(instance->property_has_next() == false); + REQUIRE_FALSE(instance->is_empty()); } - THEN("turn_order:has-previous is false") + THEN("is_running() returns true") { - REQUIRE(instance->property_has_previous() == false); + REQUIRE(instance->is_running()); } - THEN("turn_order:running is false") + THEN("round_number() returns 0") { - REQUIRE(instance->property_running() == false); + REQUIRE(instance->round_number() == 0); } } - WHEN("another participant with the same priority is added") + AND_WHEN("invoking next()") { - instance->add("Participant #1", priority, disposition::friendly); - - THEN("active_participant() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); - } - - THEN("empty() returns false") - { - REQUIRE_FALSE(instance->empty()); - } - - THEN("get() returns a valid pointer for index 0") - { - REQUIRE(instance->get(0)); - } - - THEN("get() returns a valid pointer for index 1") - { - REQUIRE(instance->get(1)); - } - - THEN("get() returns a nullptr for an index greater than 1") - { - REQUIRE(instance->get(2) == nullptr); - } - - THEN("get(0) returns the participant that was added first") - { - REQUIRE(instance->get(0)->get_name() == "Participant #0"); - } - - THEN("get(1) returns the participant that was added second") - { - REQUIRE(instance->get(1)->get_name() == "Participant #1"); - } - - THEN("round() returns 0") - { - REQUIRE(instance->round() == 0); - } + instance->next(); - THEN("running() returns false") + THEN("get_n_items() still returns 1") { - REQUIRE_FALSE(instance->running()); + REQUIRE(instance->get_n_items() == 1); } - THEN("size() returns 2") + THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->size() == 2); + REQUIRE(instance->get_typed_object<participant>(0) != nullptr); } - THEN("turn_order:has-next is false") + THEN("has_next() still returns true") { - REQUIRE(instance->property_has_next() == false); + REQUIRE(instance->has_next()); } - THEN("turn_order:has-previous is false") + THEN("has_previous() returns true") { - REQUIRE(instance->property_has_previous() == false); + REQUIRE(instance->has_previous()); } - THEN("turn_order:running is false") + THEN("is_empty() still returns false") { - REQUIRE(instance->property_running() == false); + REQUIRE_FALSE(instance->is_empty()); } - AND_WHEN("the participant at index 0 is removed") + THEN("is_running() returns true") { - instance->remove(0); - - THEN("active_participant() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); - } - - THEN("empty() returns false") - { - REQUIRE_FALSE(instance->empty()); - } - - THEN("get() returns a valid pointer for index 0") - { - REQUIRE(instance->get(0)); - } - - THEN("get() returns a nullptr for an index greater than 0") - { - REQUIRE(instance->get(1) == nullptr); - } - - THEN("get(0) returns the participant that was added second") - { - REQUIRE(instance->get(0)->get_name() == "Participant #1"); - } - - THEN("round() returns 0") - { - REQUIRE(instance->round() == 0); - } - - THEN("running() returns false") - { - REQUIRE_FALSE(instance->running()); - } - - THEN("size() returns 1") - { - REQUIRE(instance->size() == 1); - } - - THEN("turn_order:has-next is false") - { - REQUIRE(instance->property_has_next() == false); - } - - THEN("turn_order:has-previous is false") - { - REQUIRE(instance->property_has_previous() == false); - } - - THEN("turn_order:running is false") - { - REQUIRE(instance->property_running() == false); - } + REQUIRE(instance->is_running()); } - AND_WHEN("the turn_order is cleared") + THEN("round_number() returns 1") { - instance->clear(); - - THEN("active_participant() returns turn_order::invalid_participant_index") - { - REQUIRE(instance->active_participant() == turn_order::invalid_participant_index); - } - - THEN("empty() returns true") - { - REQUIRE(instance->empty()); - } - - THEN("get() returns a nullptr pointer for index 0") - { - REQUIRE(instance->get(0) == nullptr); - } - - THEN("round() returns 0") - { - REQUIRE(instance->round() == 0); - } - - THEN("running() returns false") - { - REQUIRE_FALSE(instance->running()); - } - - THEN("size() returns 0") - { - REQUIRE(instance->size() == 0); - } - - THEN("turn_order:has-next is false") - { - REQUIRE(instance->property_has_next() == false); - } - - THEN("turn_order:has-previous is false") - { - REQUIRE(instance->property_has_previous() == false); - } - - THEN("turn_order:running is false") - { - REQUIRE(instance->property_running() == false); - } + REQUIRE(instance->round_number() == 1); } } } |
