summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--domain/include/turns/domain/participant.hpp6
-rw-r--r--domain/src/participant.cpp10
-rw-r--r--domain/tests/participant.cpp30
3 files changed, 46 insertions, 0 deletions
diff --git a/domain/include/turns/domain/participant.hpp b/domain/include/turns/domain/participant.hpp
index 760ba31..f6ceff7 100644
--- a/domain/include/turns/domain/participant.hpp
+++ b/domain/include/turns/domain/participant.hpp
@@ -1,6 +1,8 @@
#ifndef TURNS_DOMAIN_PARTICIPANT_HPP
#define TURNS_DOMAIN_PARTICIPANT_HPP
+#include <compare>
+
#include <glibmm/object.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
@@ -12,6 +14,8 @@ namespace turns::domain
{
auto static create(Glib::ustring name, float order_value) -> Glib::RefPtr<participant>;
+ auto operator<=>(participant const & other) const noexcept -> std::partial_ordering;
+
auto name() const noexcept -> Glib::ustring const &;
auto name(Glib::ustring value) -> participant &;
@@ -25,6 +29,8 @@ namespace turns::domain
float m_order_value;
};
+ auto operator<=>(Glib::RefPtr<participant> const & lhs, Glib::RefPtr<participant> const & rhs) -> std::partial_ordering;
+
} // namespace turns::domain
#endif \ No newline at end of file
diff --git a/domain/src/participant.cpp b/domain/src/participant.cpp
index 8302024..d7e6b30 100644
--- a/domain/src/participant.cpp
+++ b/domain/src/participant.cpp
@@ -16,6 +16,11 @@ namespace turns::domain
{
}
+ auto participant::operator<=>(participant const & other) const noexcept -> std::partial_ordering
+ {
+ return order() <=> other.order();
+ }
+
auto participant::name() const noexcept -> Glib::ustring const &
{
return m_name;
@@ -38,4 +43,9 @@ namespace turns::domain
return *this;
}
+ auto operator<=>(Glib::RefPtr<participant> const & lhs, Glib::RefPtr<participant> const & rhs) -> std::partial_ordering
+ {
+ return *lhs <=> *rhs;
+ }
+
} // namespace turns::domain \ No newline at end of file
diff --git a/domain/tests/participant.cpp b/domain/tests/participant.cpp
index b7429aa..ee8af74 100644
--- a/domain/tests/participant.cpp
+++ b/domain/tests/participant.cpp
@@ -1,8 +1,11 @@
#include "turns/domain/participant.hpp"
#include <catch2/catch_test_macros.hpp>
+
#include <glibmm/init.h>
+#include <compare>
+
namespace turns::domain::tests
{
@@ -38,6 +41,33 @@ namespace turns::domain::tests
instance->order(8);
REQUIRE(instance->order() == 8);
}
+
+ SECTION("can be compared with another participant")
+ {
+ auto equivalent_instance = participant::create("Equivalent", constructed_order);
+ auto lesser_instance = participant::create("Lesser", constructed_order - 1);
+ auto greater_instance = participant::create("Greater", constructed_order + 1);
+
+ 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);
+ }
+ }
}
} // namespace turns::domain::tests \ No newline at end of file