summaryrefslogtreecommitdiff
path: root/domain/src/turn_order.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-17 15:59:41 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-17 15:59:41 +0200
commit79c06fc454b91bc14b4a85dd6ec0c870c8ab6da8 (patch)
treebe40741f637981b1e07b620c77cb2b34c67fc8c3 /domain/src/turn_order.cpp
parent631a8065aa9753c27f84c08bee49334c1b473bdc (diff)
downloadturns-79c06fc454b91bc14b4a85dd6ec0c870c8ab6da8.tar.xz
turns-79c06fc454b91bc14b4a85dd6ec0c870c8ab6da8.zip
domain/tests: improve turn_order tests
Diffstat (limited to 'domain/src/turn_order.cpp')
-rw-r--r--domain/src/turn_order.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/domain/src/turn_order.cpp b/domain/src/turn_order.cpp
index 595b55d..61ccdca 100644
--- a/domain/src/turn_order.cpp
+++ b/domain/src/turn_order.cpp
@@ -40,7 +40,7 @@ namespace turns::domain
turn_order::turn_order()
: Glib::ObjectBase{typeid(turn_order)}
, m_model{Gio::ListStore<participant>::create()}
- , m_active_participant(*this, "active_participant", std::numeric_limits<active_participant_type>::max())
+ , 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}
@@ -62,7 +62,7 @@ namespace turns::domain
auto position = m_model->insert_sorted(participant, comparator);
participant->property_priority().signal_changed().connect([this] { m_model->sort(comparator); });
- if (m_active_participant != std::numeric_limits<active_participant_type>::max() && position <= m_active_participant)
+ if (m_active_participant != invalid_participant_index && position <= m_active_participant)
{
m_active_participant = m_active_participant + 1;
}
@@ -72,7 +72,7 @@ namespace turns::domain
auto turn_order::clear() -> void
{
m_model->remove_all();
- m_active_participant = std::numeric_limits<active_participant_type>::max();
+ m_active_participant = invalid_participant_index;
m_has_next = false;
m_has_previous = false;
m_running = false;
@@ -113,18 +113,21 @@ namespace turns::domain
m_model->remove(index);
if (empty())
{
- m_active_participant = std::numeric_limits<active_participant_type>::max();
+ m_active_participant = invalid_participant_index;
m_has_next = false;
m_has_previous = false;
m_running = false;
}
- else if (m_active_participant >= size() - 1)
+ else if (m_active_participant != invalid_participant_index)
{
- m_active_participant = size() - 1;
- }
- else if (index <= m_active_participant)
- {
- m_active_participant = m_active_participant - 1;
+ if (m_active_participant > size() - 1)
+ {
+ m_active_participant = size() - 1;
+ }
+ else if (index <= m_active_participant)
+ {
+ m_active_participant = m_active_participant - 1;
+ }
}
}
@@ -136,7 +139,7 @@ namespace turns::domain
auto turn_order::start() -> void
{
- if (m_active_participant == std::numeric_limits<active_participant_type>::max())
+ if (m_active_participant == invalid_participant_index)
{
m_active_participant = 0;
}