diff options
Diffstat (limited to 'lib/tests/turns-turn-order.cpp')
| -rw-r--r-- | lib/tests/turns-turn-order.cpp | 64 |
1 files changed, 64 insertions, 0 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 |
