diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-16 20:47:07 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-16 20:47:07 +0200 |
| commit | d0b647c3156b07c70e9831aa86ef76ee40413d0c (patch) | |
| tree | 0908404f80ea28db00962c8eeb26b042dad98cb9 /lib/tests | |
| parent | 9e1280599c322df6e5f3e8bac2a56915bf8531f2 (diff) | |
| download | turns-d0b647c3156b07c70e9831aa86ef76ee40413d0c.tar.xz turns-d0b647c3156b07c70e9831aa86ef76ee40413d0c.zip | |
lib: react to priority changes
Diffstat (limited to 'lib/tests')
| -rw-r--r-- | lib/tests/turns-turn-order.cpp | 64 | ||||
| -rw-r--r-- | lib/tests/turnsmm/turn-order.cpp | 2 |
2 files changed, 65 insertions, 1 deletions
diff --git a/lib/tests/turns-turn-order.cpp b/lib/tests/turns-turn-order.cpp index 05e3b07..9f4d5d6 100644 --- a/lib/tests/turns-turn-order.cpp +++ b/lib/tests/turns-turn-order.cpp @@ -85,4 +85,68 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") } } } +} + +SCENARIO("Sorting a turn order") +{ + GIVEN("A turn order with two participants - A/10/H and B/20/N") + { + g_autoptr(TurnsTurnOrder) instance = turns_turn_order_new(); + g_autoptr(TurnsParticipant) participant_a = turns_participant_new_with("A", 10, TURNS_DISPOSITION_HOSTILE); + g_autoptr(TurnsParticipant) participant_b = turns_participant_new_with("B", 20, TURNS_DISPOSITION_NEUTRAL); + + turns_turn_order_add(instance, participant_a); + turns_turn_order_add(instance, participant_b); + + THEN("B is the first and A the second element") + { + g_autoptr(TurnsParticipant) first = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 0)); + g_autoptr(TurnsParticipant) second = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 1)); + + REQUIRE(first == participant_b); + REQUIRE(second == participant_a); + } + + WHEN("the priority of A is changed to 30") + { + turns_participant_set_priority(participant_a, 30); + + THEN("A is the first and B the second element") + { + g_autoptr(TurnsParticipant) first = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 0)); + g_autoptr(TurnsParticipant) second = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 1)); + + REQUIRE(first == participant_a); + REQUIRE(second == participant_b); + } + } + + WHEN("the priority of A is changed to 0") + { + turns_participant_set_priority(participant_a, 0); + + THEN("B is the first and A the second element") + { + g_autoptr(TurnsParticipant) first = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 0)); + g_autoptr(TurnsParticipant) second = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 1)); + + REQUIRE(first == participant_b); + REQUIRE(second == participant_a); + } + } + + WHEN("the priority of B is changed to 0") + { + turns_participant_set_priority(participant_b, 0); + + THEN("A is the first and B the second element") + { + g_autoptr(TurnsParticipant) first = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 0)); + g_autoptr(TurnsParticipant) second = TURNS_PARTICIPANT(g_list_model_get_object(G_LIST_MODEL(instance), 1)); + + REQUIRE(first == participant_a); + REQUIRE(second == participant_b); + } + } + } }
\ No newline at end of file diff --git a/lib/tests/turnsmm/turn-order.cpp b/lib/tests/turnsmm/turn-order.cpp index 089e6eb..21c75d3 100644 --- a/lib/tests/turnsmm/turn-order.cpp +++ b/lib/tests/turnsmm/turn-order.cpp @@ -80,4 +80,4 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") } } } -}
\ No newline at end of file +} |
