From 0ba8ce7bc6200db8ad2abe3aa611e6a66dd7ea44 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 28 May 2024 20:29:18 +0200 Subject: [PATCH] top10: 1.1.3 - (RED) Formulated expectations for `Ranking.equals()` --- pom.xml | 2 +- .../kafka/wordcount/top10/RankingTest.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 86b4290..a8abbc8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.juplo.kafka.wordcount top10 - 1.1.2 + 1.1.3 Wordcount-Top-10 Top-10 stream-processor of the multi-user wordcount-example diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/RankingTest.java b/src/test/java/de/juplo/kafka/wordcount/top10/RankingTest.java index e92d87c..26749e9 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/RankingTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/RankingTest.java @@ -137,6 +137,52 @@ public class RankingTest .isThrownBy(() -> ranking.add(Entry.of(entry.getWord(), entry.getCounter() - 1)))); } + @DisplayName("Identical rankings are considered equal") + @ParameterizedTest + @MethodSource("validRankingsProvider") + public void testIdenticalRankingsAreConsideredEaqual(List entryList) + { + assertThat(Ranking.of(toArray(entryList))).isEqualTo(Ranking.of(toArray(entryList))); + } + + @DisplayName("Two empty rankings are considered equal") + @Test + public void testTwoEmptyRankingsAreConsideredEaqual() + { + assertThat(Ranking.of()).isEqualTo(Ranking.of()); + } + + @DisplayName("A changed ranking is not considered equal to its unchanged counter-part") + @ParameterizedTest + @MethodSource("validRankingsProvider") + public void testChangedRankingsDoNotEaqualUnchangedOne(List entryList) + { + Ranking changed = Ranking.of(toArray(entryList)); + changed.add(Entry.of("devilish", 666l)); + assertThat(changed).isNotEqualTo(Ranking.of(toArray(entryList))); + } + + @DisplayName("Rankigs are considered equal, if only the order of words with the same count differ") + @Test + public void testRankingWithDifferentOrderForSameCountAreEqual() + { + assertThat( + Ranking.of( + Entry.of("a1",10l), + Entry.of("a2",10l), + Entry.of("b1", 9l), + Entry.of("b2",9l), + Entry.of("c1", 8l), + Entry.of("c2", 8l))) + .isEqualTo(Ranking.of( + Entry.of("a2",10l), + Entry.of("a1",10l), + Entry.of("b2", 9l), + Entry.of("b1",9l), + Entry.of("c2", 8l), + Entry.of("c1", 8l))); + } + Entry[] toArray(List entryList) { -- 2.20.1