diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-07-25 22:59:30 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-07-25 22:59:30 +0200 |
| commit | d734f1e7803a756822524e0580ec8e9c93b821c6 (patch) | |
| tree | 28daa14da0ec330adaa87f1316167cf18274cfe4 /lib/tests | |
| parent | fb2fbeca028d7a854df1c4b23bd0395d11e1f724 (diff) | |
| download | turns-d734f1e7803a756822524e0580ec8e9c93b821c6.tar.xz turns-d734f1e7803a756822524e0580ec8e9c93b821c6.zip | |
lib: make Turns.Participant comparablemain
Diffstat (limited to 'lib/tests')
| -rw-r--r-- | lib/tests/turns-participant.cpp | 47 | ||||
| -rw-r--r-- | lib/tests/turnsmm/participant.cpp | 47 |
2 files changed, 94 insertions, 0 deletions
diff --git a/lib/tests/turns-participant.cpp b/lib/tests/turns-participant.cpp index e9cc62e..fc76c4b 100644 --- a/lib/tests/turns-participant.cpp +++ b/lib/tests/turns-participant.cpp @@ -550,4 +550,51 @@ SCENARIO("Reading a participant", "[lib][object][data]") } } } +} + +SCENARIO("Comparing two participants", "[lib][object][logic]") +{ + auto name_lhs = "LHS"; + auto name_rhs = "RHS"; + auto disposition = TurnsParticipantDisposition::TURNS_PARTICIPANT_DISPOSITION_NEUTRAL; + + GIVEN("A participant with priority 0") + { + g_autoptr(TurnsParticipant) lhs = turns_participant_new_with(name_lhs, 0.0f, disposition); + + THEN("the it compares equal to itself") + { + REQUIRE(turns_participant_compare(lhs, lhs) == 0); + } + + AND_GIVEN("A participant with priority 10") + { + g_autoptr(TurnsParticipant) rhs = turns_participant_new_with(name_rhs, 10.0f, disposition); + + THEN("the first compares less than the second") + { + REQUIRE(turns_participant_compare(lhs, rhs) < 0); + } + + THEN("the second compares greater than the first") + { + REQUIRE(turns_participant_compare(rhs, lhs) > 0); + } + } + + AND_GIVEN("A participant with priority -10") + { + g_autoptr(TurnsParticipant) rhs = turns_participant_new_with(name_rhs, -10.0f, disposition); + + THEN("the first compares greater than the second") + { + REQUIRE(turns_participant_compare(lhs, rhs) > 0); + } + + THEN("the second compares less than the first") + { + REQUIRE(turns_participant_compare(rhs, lhs) < 0); + } + } + } }
\ No newline at end of file diff --git a/lib/tests/turnsmm/participant.cpp b/lib/tests/turnsmm/participant.cpp index 47cf867..0cac20d 100644 --- a/lib/tests/turnsmm/participant.cpp +++ b/lib/tests/turnsmm/participant.cpp @@ -523,3 +523,50 @@ SCENARIO("Modifying a participant", "[lib][object][data]") } } } + +SCENARIO("Comparing two participants", "[lib][object][logic]") +{ + auto name_lhs = "LHS"; + auto name_rhs = "RHS"; + auto disposition = Turns::Participant::Disposition::Neutral; + + GIVEN("A participant with priority 0") + { + auto lhs = Turns::Participant{name_lhs, 0.0f, disposition}; + + THEN("the it compares equal to itself") + { + REQUIRE(lhs == lhs); + } + + AND_GIVEN("A participant with priority 10") + { + auto rhs = Turns::Participant{name_rhs, 10.0f, disposition}; + + THEN("the first compares less than the second") + { + REQUIRE(lhs < rhs); + } + + THEN("the second compares greater than the first") + { + REQUIRE(rhs > lhs); + } + } + + AND_GIVEN("A participant with priority -10") + { + auto rhs = Turns::Participant{name_rhs, -10.0f, disposition}; + + THEN("the first compares greater than the second") + { + REQUIRE(lhs > rhs); + } + + THEN("the second compares less than the first") + { + REQUIRE(rhs < lhs); + } + } + } +}
\ No newline at end of file |
