From 5845e43c503f306a653754303573af421207e90c Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 16 Jul 2024 00:35:35 +0200 Subject: domain: add disposition type --- domain/tests/disposition.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 domain/tests/disposition.cpp (limited to 'domain/tests/disposition.cpp') diff --git a/domain/tests/disposition.cpp b/domain/tests/disposition.cpp new file mode 100644 index 0000000..487bc5f --- /dev/null +++ b/domain/tests/disposition.cpp @@ -0,0 +1,125 @@ +#include "turns/domain/disposition.hpp" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace turns::domain::tests +{ + + TEST_CASE("A freshly constructed disposition", "[disposition]") + { + auto constexpr constructed_value = disposition::values::friendly; + auto instance = disposition{constructed_value}; + + SECTION("can be created") + { + REQUIRE(disposition::create(constructed_value)); + } + + SECTION("allows access to its value via the associated accessors") + { + SECTION("allowing to get it") + { + REQUIRE(instance.get_value() == constructed_value); + } + + SECTION("allowing to get it via a constant object") + { + auto const & cref = instance; + REQUIRE(cref.get_value() == constructed_value); + } + + SECTION("allowing to set it") + { + instance.set_value(disposition::values::hostile); + REQUIRE(instance.get_value() == disposition::values::hostile); + } + } + + SECTION("allows access to its value via the associated property") + { + SECTION("allowing to get it") + { + REQUIRE(instance.property_value() == constructed_value); + } + + SECTION("allowing to get it via a constant object") + { + auto const & cref = instance; + REQUIRE(cref.property_value() == constructed_value); + } + + SECTION("allowing to set it") + { + instance.property_value() = disposition::values::hostile; + REQUIRE(instance.get_value() == disposition::values::hostile); + } + } + + SECTION("allows access to its name via the associated accessors") + { + SECTION("allowing to get it") + { + REQUIRE(instance.get_presentation_name() == _("Friendly")); + } + + SECTION("allowing to get it via a constant object") + { + auto const & cref = instance; + REQUIRE(cref.get_presentation_name() == _("Friendly")); + } + } + + SECTION("can be compared with another disposition") + { + auto equal_instance = disposition{disposition::values::friendly}; + auto lesser_instance = disposition{disposition::values::neutral}; + auto greater_instance = disposition{disposition::values::hostile}; + + SECTION("yielding std::partial_ordering::equivalent for itself") + { + REQUIRE((instance <=> instance) == std::strong_ordering::equal); + } + + SECTION("yielding std::partial_ordering::equivalent for an equivalent participant") + { + REQUIRE((instance <=> equal_instance) == std::strong_ordering::equal); + } + + SECTION("yielding std::partial_ordering::greater for a lesser participant") + { + REQUIRE((instance <=> lesser_instance) == std::strong_ordering::greater); + } + + SECTION("yielding std::partial_ordering::less for a greater participant") + { + REQUIRE((instance <=> greater_instance) == std::strong_ordering::less); + } + } + } + + TEST_CASE("disposition::get_presentation_name returns the correct string", "[disposition]") + { + auto [value, name] = + GENERATE(std::pair{disposition::values::neutral, _("Neutral")}, + std::pair{disposition::values::friendly, _("Friendly")}, + std::pair{disposition::values::hostile, _("Hostile")}, + std::pair{disposition::values::secret, _("Secret")}, + std::pair{static_cast(std::numeric_limits>::max()), + _("Unknown disposition value")}); + + SECTION(std::format("the presentation name for '{}' is '{}'", static_cast>(value), name)) + { + REQUIRE(disposition{value}.get_presentation_name() == name); + } + } + +} // namespace turns::domain::tests \ No newline at end of file -- cgit v1.2.3