1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include "turns/domain/disposition.hpp"
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <compare>
#include <format>
#include <limits>
#include <utility>
#include <glibmm/i18n.h>
#include <glibmm/init.h>
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<disposition::values>(std::numeric_limits<std::underlying_type_t<disposition::values>>::max()),
_("Unknown disposition value")});
SECTION(std::format("the presentation name for '{}' is '{}'", static_cast<std::underlying_type_t<disposition::values>>(value), name))
{
REQUIRE(disposition{value}.get_presentation_name() == name);
}
}
} // namespace turns::domain::tests
|