summaryrefslogtreecommitdiff
path: root/domain
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-23 15:08:19 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-23 15:08:19 +0200
commit4ec6a2ae12b6adb843c0777649ff45a741ca6cbc (patch)
tree93dc2ba99dbcb42b2af73f0a3c4cd4f0c0f091c4 /domain
parent5f4249a37ce816b8deceb299bc841190fbb15983 (diff)
downloadturns-4ec6a2ae12b6adb843c0777649ff45a741ca6cbc.tar.xz
turns-4ec6a2ae12b6adb843c0777649ff45a741ca6cbc.zip
domain: redesign turn_order
Diffstat (limited to 'domain')
-rw-r--r--domain/CMakeLists.txt2
-rw-r--r--domain/include/turns/domain/participant.hpp46
-rw-r--r--domain/include/turns/domain/turn_order.hpp111
-rw-r--r--domain/src/participant.cpp76
-rw-r--r--domain/src/turn_order.cpp237
-rw-r--r--domain/tests/participant.cpp90
-rw-r--r--domain/tests/register_types.cpp13
-rw-r--r--domain/tests/turn_order.cpp434
8 files changed, 335 insertions, 674 deletions
diff --git a/domain/CMakeLists.txt b/domain/CMakeLists.txt
index 58a7900..ec9eb62 100644
--- a/domain/CMakeLists.txt
+++ b/domain/CMakeLists.txt
@@ -37,6 +37,8 @@ target_link_options("domain" PRIVATE
# Tests
add_executable("domain-tests"
+ "tests/register_types.cpp"
+
"tests/disposition.cpp"
"tests/participant.cpp"
"tests/turn_order.cpp"
diff --git a/domain/include/turns/domain/participant.hpp b/domain/include/turns/domain/participant.hpp
index d845c77..b51425d 100644
--- a/domain/include/turns/domain/participant.hpp
+++ b/domain/include/turns/domain/participant.hpp
@@ -13,34 +13,44 @@
namespace turns::domain
{
-
struct participant : Glib::Object
{
auto static create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr<participant>;
+ participant();
participant(Glib::ustring name, float priority, disposition disposition);
auto operator<=>(participant const & other) const noexcept -> std::partial_ordering;
- auto property_disposition() -> Glib::PropertyProxy<disposition>;
- auto property_disposition() const -> Glib::PropertyProxy_ReadOnly<disposition>;
- auto get_disposition() const noexcept -> disposition;
- auto set_disposition(disposition value) -> void;
-
- auto property_name() -> Glib::PropertyProxy<Glib::ustring>;
- auto property_name() const -> Glib::PropertyProxy_ReadOnly<Glib::ustring>;
- auto get_name() const -> Glib::ustring;
- auto set_name(Glib::ustring value) -> void;
-
- auto property_priority() -> Glib::PropertyProxy<float>;
- auto property_priority() const -> Glib::PropertyProxy_ReadOnly<float>;
- auto get_priority() const noexcept -> float;
- auto set_priority(float value) -> void;
+ template<typename Self>
+ auto disposition(this Self && self)
+ {
+ return self.m_disposition.get_proxy();
+ }
+
+ template<typename Self>
+ auto is_active(this Self && self)
+ {
+ return self.m_is_active.get_proxy();
+ }
+
+ template<typename Self>
+ auto name(this Self && self)
+ {
+ return self.m_name.get_proxy();
+ }
+
+ template<typename Self>
+ auto priority(this Self && self)
+ {
+ return self.m_priority.get_proxy();
+ }
private:
- Glib::Property<disposition> m_disposition;
- Glib::Property<Glib::ustring> m_name;
- Glib::Property<float> m_priority;
+ Glib::Property<domain::disposition> m_disposition{*this, "disposition", domain::disposition::neutral};
+ Glib::Property<bool> m_is_active{*this, "active", false};
+ Glib::Property<Glib::ustring> m_name{*this, "name", ""};
+ Glib::Property<float> m_priority{*this, "priority", 0.0f};
};
} // namespace turns::domain
diff --git a/domain/include/turns/domain/turn_order.hpp b/domain/include/turns/domain/turn_order.hpp
index 3b42562..ca44b62 100644
--- a/domain/include/turns/domain/turn_order.hpp
+++ b/domain/include/turns/domain/turn_order.hpp
@@ -4,9 +4,12 @@
#include "turns/domain/disposition.hpp"
#include "turns/domain/participant.hpp"
+#include <initializer_list>
#include <limits>
+#include <optional>
+#include <vector>
-#include <giomm/liststore.h>
+#include <giomm/listmodel.h>
#include <glibmm/property.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
@@ -14,91 +17,67 @@
namespace turns::domain
{
- struct turn_order : Glib::Object
+ struct turn_order : Gio::ListModel,
+ Glib::Object
{
+ using value_type = Glib::RefPtr<participant>;
+ using container_type = std::vector<value_type>;
+ using iterator = container_type::iterator;
+ using const_iterator = container_type::const_iterator;
+
using active_participant_type = unsigned int;
- using empty_type = bool;
+ using is_empty_type = bool;
using has_next_type = bool;
using has_previous_type = bool;
- using running_type = bool;
- using round_type = unsigned int;
+ using is_running_type = bool;
+ using round_number_type = unsigned int;
auto static constexpr invalid_participant_index = std::numeric_limits<active_participant_type>::max();
+ auto static constexpr invalid_round_number = std::numeric_limits<round_number_type>::max();
- auto static create() -> Glib::RefPtr<turn_order>;
-
+ /** Life-time */
turn_order();
- /** Modifiers */
+ auto static create() -> Glib::RefPtr<turn_order>;
+
+ /** Properties */
+ auto is_empty() const -> Glib::PropertyProxy_ReadOnly<is_empty_type>;
+ auto has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>;
+ auto has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>;
+ auto is_running() const -> Glib::PropertyProxy_ReadOnly<is_running_type>;
+ auto round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>;
+ /** Element Modifications */
auto add(Glib::ustring const & name, float priority, disposition disposition) -> void;
auto clear() -> void;
+ auto remove(unsigned index) -> void;
+
+ /** Turn Modification */
auto next() -> void;
auto previous() -> void;
- auto remove(unsigned int index) -> void;
- auto reset() -> void;
auto start() -> void;
auto stop() -> void;
- /** Querries */
-
- /**
- * Get the index of the currently active participant of this turn order, if any.
- *
- * @returns an unsigned integer in the range [0, size()) if there is an active participant, or turn_order::invalid_participant_index otherwise.
- */
- auto active_participant() const noexcept -> active_participant_type;
-
- /**
- * Check if this turn order is empty.
- */
- auto empty() const noexcept -> empty_type;
-
- /**
- * Get the actor at the specified position in this turn order.
- *
- * @return a valid pointer to a participant object if the index was valid, nullptr otherwise.
- */
- auto get(unsigned int index) const noexcept -> Glib::RefPtr<participant>;
-
- /**
- * Get the underlying list model, to be used with list views.
- */
- auto list_model() -> Glib::RefPtr<Gio::ListModel>;
-
- /**
- * Get the current round.
- */
- auto round() const noexcept -> round_type;
-
- /**
- * Check if this turn order is currently running.
- */
- auto running() const noexcept -> running_type;
-
- /**
- * Get the size of this turn order
- */
- auto size() const noexcept -> unsigned int;
+ private:
+ auto get_item_type_vfunc() -> GType override;
+ auto get_n_items_vfunc() -> unsigned override;
+ auto get_item_vfunc(unsigned position) -> void * override;
- /** Properties */
+ /** Signal handlers */
+ auto handle_priority_changed(value_type entry) -> void;
- auto property_active_participant() const -> Glib::PropertyProxy_ReadOnly<active_participant_type>;
- auto property_empty() const -> Glib::PropertyProxy_ReadOnly<empty_type>;
- auto property_has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>;
- auto property_has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>;
- auto property_running() const -> Glib::PropertyProxy_ReadOnly<running_type>;
- auto property_round() const -> Glib::PropertyProxy_ReadOnly<round_type>;
+ /** Data management */
+ auto find(value_type entry) const -> const_iterator;
+ auto insert(value_type entry) -> const_iterator;
- private:
- Glib::RefPtr<Gio::ListStore<participant>> m_model;
-
- Glib::Property<active_participant_type> m_active_participant;
- Glib::Property<empty_type> m_empty;
- Glib::Property<has_next_type> m_has_next;
- Glib::Property<has_previous_type> m_has_previous;
- Glib::Property<running_type> m_running;
- Glib::Property<round_type> m_round;
+ container_type m_data{};
+ std::optional<unsigned> m_active{};
+
+ Glib::Property<has_next_type> m_has_next{*this, "has-next", false};
+ Glib::Property<has_previous_type> m_has_previous{*this, "has-previous", false};
+ Glib::Property<is_empty_type> m_is_empty{*this, "is-empty", true};
+ Glib::Property<is_running_type> m_is_running{*this, "is-running", false};
+ Glib::Property<round_number_type> m_round_number{*this, "round-number", invalid_round_number};
};
} // namespace turns::domain
diff --git a/domain/src/participant.cpp b/domain/src/participant.cpp
index 5265eb3..6f0efb1 100644
--- a/domain/src/participant.cpp
+++ b/domain/src/participant.cpp
@@ -3,87 +3,33 @@
#include <typeinfo>
#include <utility>
+#include <glibmm/class.h>
#include <glibmm/refptr.h>
namespace turns::domain
{
-
- auto participant::create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr<participant>
+ auto participant::create(Glib::ustring name, float priority, domain::disposition disposition) -> Glib::RefPtr<participant>
{
return Glib::make_refptr_for_instance(new participant{name, priority, disposition});
}
- participant::participant(Glib::ustring name, float priority, disposition disposition)
+ participant::participant()
: Glib::ObjectBase{typeid(participant)}
- , m_disposition{*this, "disposition", disposition}
- , m_name{*this, "name", name}
- , m_priority{*this, "priority", priority}
- {
- }
-
- auto participant::operator<=>(participant const & other) const noexcept -> std::partial_ordering
- {
- return m_priority <=> other.m_priority;
- }
-
- auto participant::get_disposition() const noexcept -> disposition
- {
- return m_disposition;
- }
-
- auto participant::set_disposition(disposition value) -> void
- {
- m_disposition = value;
- }
-
- auto participant::get_name() const -> Glib::ustring
- {
- return m_name;
- }
-
- auto participant::set_name(Glib::ustring value) -> void
- {
- m_name = value;
- }
-
- auto participant::get_priority() const noexcept -> float
- {
- return m_priority;
- }
-
- auto participant::set_priority(float value) -> void
+ , Glib::Object{}
{
- m_priority = value;
}
- auto participant::property_disposition() -> Glib::PropertyProxy<disposition>
+ participant::participant(Glib::ustring name, float priority, domain::disposition disposition)
+ : participant()
{
- return m_disposition.get_proxy();
+ m_name = name;
+ m_priority = priority;
+ m_disposition = disposition;
}
- auto participant::property_disposition() const -> Glib::PropertyProxy_ReadOnly<disposition>
- {
- return m_disposition.get_proxy();
- }
-
- auto participant::property_name() -> Glib::PropertyProxy<Glib::ustring>
- {
- return m_name.get_proxy();
- }
-
- auto participant::property_name() const -> Glib::PropertyProxy_ReadOnly<Glib::ustring>
- {
- return m_name.get_proxy();
- }
-
- auto participant::property_priority() -> Glib::PropertyProxy<float>
- {
- return m_priority.get_proxy();
- }
-
- auto participant::property_priority() const -> Glib::PropertyProxy_ReadOnly<float>
+ auto participant::operator<=>(participant const & other) const noexcept -> std::partial_ordering
{
- return m_priority.get_proxy();
+ return m_priority <=> other.m_priority;
}
} // namespace turns::domain \ No newline at end of file
diff --git a/domain/src/turn_order.cpp b/domain/src/turn_order.cpp
index 61ccdca..0f8b6e8 100644
--- a/domain/src/turn_order.cpp
+++ b/domain/src/turn_order.cpp
@@ -2,11 +2,11 @@
#include "turns/domain/participant.hpp"
+#include <algorithm>
#include <compare>
#include <limits>
#include <typeinfo>
-#include <glibmm/binding.h>
#include <glibmm/refptr.h>
namespace turns::domain
@@ -32,194 +32,203 @@ namespace turns::domain
};
} // namespace
+ /** Construction */
+
+ turn_order::turn_order()
+ : Glib::ObjectBase{typeid(turn_order)}
+ , Gio::ListModel{}
+ {
+ }
+
auto turn_order::create() -> Glib::RefPtr<turn_order>
{
return Glib::make_refptr_for_instance(new turn_order{});
}
- turn_order::turn_order()
- : Glib::ObjectBase{typeid(turn_order)}
- , m_model{Gio::ListStore<participant>::create()}
- , m_active_participant(*this, "active_participant", invalid_participant_index)
- , m_empty{*this, "empty", true}
- , m_has_next{*this, "has-next", false}
- , m_has_previous{*this, "has-previous", false}
- , m_running{*this, "running", false}
- , m_round{*this, "round", 0}
+ /** Queries */
+
+ auto turn_order::is_empty() const -> Glib::PropertyProxy_ReadOnly<is_empty_type>
+ {
+ return m_is_empty.get_proxy();
+ }
+
+ auto turn_order::has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>
+ {
+ return m_has_next.get_proxy();
+ }
+
+ auto turn_order::has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>
+ {
+ return m_has_previous.get_proxy();
+ }
+
+ auto turn_order::is_running() const -> Glib::PropertyProxy_ReadOnly<is_running_type>
{
- Glib::Binding::bind_property(m_model->property_n_items(), m_empty.get_proxy(), Glib::Binding::Flags::DEFAULT, [](auto n) {
- return n == 0;
- });
+ return m_is_running.get_proxy();
+ }
+
+ auto turn_order::round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>
+ {
+ return m_round_number.get_proxy();
}
/** Modifiers */
auto turn_order::add(Glib::ustring const & name, float priority, disposition disposition) -> void
{
- auto participant = participant::create(name, priority, disposition);
- if (auto [found, index] = m_model->find(participant, equal_comparator); !found)
- {
- auto position = m_model->insert_sorted(participant, comparator);
- participant->property_priority().signal_changed().connect([this] { m_model->sort(comparator); });
+ auto entry = participant::create(name, priority, disposition);
+ entry->priority().signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &turn_order::handle_priority_changed), entry));
+ auto position = std::distance(m_data.cbegin(), insert(entry));
+ items_changed(position, 0, 1);
- if (m_active_participant != invalid_participant_index && position <= m_active_participant)
- {
- m_active_participant = m_active_participant + 1;
- }
+ if (get_n_items() == 1)
+ {
+ m_is_empty = false;
+ m_has_next = true;
}
}
auto turn_order::clear() -> void
{
- m_model->remove_all();
- m_active_participant = invalid_participant_index;
+ m_is_running = false;
+ m_is_empty = true;
m_has_next = false;
m_has_previous = false;
- m_running = false;
+ m_active.reset();
+ m_round_number = invalid_round_number;
+
+ auto old_size = get_n_items();
+ m_data.clear();
+ items_changed(0, old_size, 0);
}
auto turn_order::next() -> void
{
- m_active_participant = (m_active_participant + 1) % size();
- if (!m_active_participant)
+ auto old_active = *m_active;
+ m_active = m_active.transform([this](auto index) { return (index + 1) % get_n_items(); });
+
+ m_has_previous = true;
+ m_data[old_active]->is_active() = false;
+ m_data[*m_active]->is_active() = true;
+
+ if (m_active == 0)
{
- m_round = round() + 1;
+ m_round_number = m_round_number + 1;
}
- m_has_previous = m_active_participant || m_round;
}
auto turn_order::previous() -> void
{
- if (!m_has_previous)
+ if (!(m_has_previous && m_is_running))
{
return;
}
- if (m_active_participant)
- {
- m_active_participant = m_active_participant - 1;
- }
- else if (m_round)
+ auto old_active = *m_active;
+ m_active = m_active.transform([this](auto index) { return index ? index - 1 : get_n_items() - 1; });
+
+ m_has_previous = m_round_number > 0 || m_active > 0;
+ m_data[old_active]->is_active() = false;
+ m_data[*m_active]->is_active() = true;
+
+ if (m_active == 0)
{
- m_round = round() - 1;
- m_active_participant = size() - 1;
+ m_round_number = m_round_number - 1;
}
-
- m_has_previous = m_active_participant || m_round;
}
- auto turn_order::remove(unsigned int index) -> void
+ auto turn_order::remove(unsigned index) -> void
{
- m_model->remove(index);
- if (empty())
+ if (index >= get_n_items())
{
- m_active_participant = invalid_participant_index;
- m_has_next = false;
- m_has_previous = false;
- m_running = false;
+ return;
}
- else if (m_active_participant != invalid_participant_index)
+
+ auto position = m_data.begin() + index;
+ m_data.erase(position);
+ items_changed(index, 1, 0);
+ if (get_n_items() == 0)
{
- if (m_active_participant > size() - 1)
- {
- m_active_participant = size() - 1;
- }
- else if (index <= m_active_participant)
- {
- m_active_participant = m_active_participant - 1;
- }
+ m_is_empty = true;
+ m_is_running = false;
+ m_has_next = false;
}
}
- auto turn_order::reset() -> void
- {
- m_running = false;
- m_active_participant = 0;
- }
-
auto turn_order::start() -> void
{
- if (m_active_participant == invalid_participant_index)
+ if (!m_active)
{
- m_active_participant = 0;
+ m_active = 0;
+ m_data[*m_active]->is_active() = true;
}
- m_running = true;
- m_has_next = true;
+ if (m_round_number == invalid_round_number)
+ {
+ m_round_number = 0;
+ }
+ m_is_running = true;
}
auto turn_order::stop() -> void
{
- m_running = false;
- m_has_next = false;
- }
-
- /** Querries */
-
- auto turn_order::active_participant() const noexcept -> active_participant_type
- {
- return m_active_participant;
- }
-
- auto turn_order::empty() const noexcept -> bool
- {
- return m_empty;
- }
-
- auto turn_order::get(unsigned int index) const noexcept -> Glib::RefPtr<participant>
- {
- return m_model->get_item(index);
+ m_is_running = false;
}
- auto turn_order::list_model() -> Glib::RefPtr<Gio::ListModel>
- {
- return m_model;
- }
+ /** ListModel implementation */
- auto turn_order::round() const noexcept -> round_type
+ auto turn_order::get_item_type_vfunc() -> GType
{
- return m_round;
+ return participant::get_type();
}
- auto turn_order::running() const noexcept -> running_type
+ auto turn_order::get_n_items_vfunc() -> unsigned
{
- return m_running;
+ return m_data.size();
}
- auto turn_order::size() const noexcept -> unsigned int
+ auto turn_order::get_item_vfunc(unsigned position) -> void *
{
- return m_model->get_n_items();
+ if (position >= get_n_items())
+ {
+ return nullptr;
+ }
+ auto item = m_data[position];
+ item->reference();
+ return item->gobj();
}
- /** Properties */
+ /** Signal handlers */
- auto turn_order::property_active_participant() const -> Glib::PropertyProxy_ReadOnly<active_participant_type>
+ auto turn_order::handle_priority_changed(value_type entry) -> void
{
- return m_active_participant.get_proxy();
- }
-
- auto turn_order::property_empty() const -> Glib::PropertyProxy_ReadOnly<bool>
- {
- return m_empty.get_proxy();
- }
+ auto original_position = find(entry);
+ auto original_index = distance(m_data.cbegin(), original_position);
+ auto target_position = std::ranges::upper_bound(m_data, entry, comparator);
+ if (original_position == target_position)
+ {
+ return;
+ }
- auto turn_order::property_has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>
- {
- return m_has_next.get_proxy();
+ m_data.erase(original_position);
+ auto inserted_position = insert(entry);
+ items_changed(0, get_n_items(), get_n_items());
+ if (m_active == original_index)
+ {
+ m_active = distance(m_data.cbegin(), inserted_position);
+ m_has_previous = m_round_number > 0 || m_active > 0;
+ }
}
- auto turn_order::property_has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>
- {
- return m_has_previous.get_proxy();
- }
+ /** Data management */
- auto turn_order::property_running() const -> Glib::PropertyProxy_ReadOnly<running_type>
+ auto turn_order::find(value_type entry) const -> const_iterator
{
- return m_running.get_proxy();
+ return std::ranges::find(m_data, entry);
}
- auto turn_order::property_round() const -> Glib::PropertyProxy_ReadOnly<round_type>
+ auto turn_order::insert(value_type entry) -> const_iterator
{
- return m_round.get_proxy();
+ return m_data.insert(std::ranges::upper_bound(m_data, entry, comparator), entry);
}
} // namespace turns::domain \ No newline at end of file
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 fa