top10: 1.1.3 - (RED) Formulated expectations for `Ranking.equals()`
authorKai Moritz <kai@juplo.de>
Tue, 28 May 2024 18:29:18 +0000 (20:29 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 30 May 2024 10:07:33 +0000 (12:07 +0200)
pom.xml
src/test/java/de/juplo/kafka/wordcount/top10/RankingTest.java

diff --git a/pom.xml b/pom.xml
index 86b4290..a8abbc8 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
        </parent>
        <groupId>de.juplo.kafka.wordcount</groupId>
        <artifactId>top10</artifactId>
-       <version>1.1.2</version>
+       <version>1.1.3</version>
        <name>Wordcount-Top-10</name>
        <description>Top-10 stream-processor of the multi-user wordcount-example</description>
        <properties>
index e92d87c..26749e9 100644 (file)
@@ -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<Entry> 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<Entry> 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<Entry> entryList)
   {