You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/09/03 04:11:45 UTC

[isis] branch master updated: ISIS-2774: testing Can.unique(..)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 9aeb0a3  ISIS-2774: testing Can<T>.unique(..)
9aeb0a3 is described below

commit 9aeb0a3a90f598e09ff2ab256c0b4eafbbae6ee1
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Sep 3 06:11:23 2021 +0200

    ISIS-2774: testing Can<T>.unique(..)
---
 .../apache/isis/commons/collections/CanTest.java   | 64 ++++++++++++++++++++--
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/commons/src/test/java/org/apache/isis/commons/collections/CanTest.java b/commons/src/test/java/org/apache/isis/commons/collections/CanTest.java
index ed3311e..b07344c 100644
--- a/commons/src/test/java/org/apache/isis/commons/collections/CanTest.java
+++ b/commons/src/test/java/org/apache/isis/commons/collections/CanTest.java
@@ -20,17 +20,18 @@ package org.apache.isis.commons.collections;
 
 import java.io.IOException;
 import java.util.Set;
+import java.util.function.BiPredicate;
 import java.util.stream.Stream;
 
 import org.junit.jupiter.api.Test;
 
-import org.apache.isis.commons.internal.collections._Sets;
-import org.apache.isis.commons.internal.testing._SerializationTester;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import org.apache.isis.commons.internal.collections._Sets;
+import org.apache.isis.commons.internal.testing._SerializationTester;
+
 import lombok.val;
 
 class CanTest {
@@ -187,9 +188,64 @@ class CanTest {
                 Can.<String>of("a", "b", "c").pickByIndex(0, 1, -2, 0, 5));
     }
 
+    // -- UNIQUE
+
+    @Test
+    void uniqueByEquals() {
+
+        assertEquals(
+                Can.empty(),
+                Can.empty().unique());
+
+        assertEquals(
+                Can.of("a"),
+                Can.of("a").unique());
+
+        assertEquals(
+                Can.of("a"),
+                Can.of("a", "a", "a").unique());
+
+        assertEquals(
+                Can.of("a", "b", "c"),
+                Can.of("a", "b", "c").unique());
+
+        assertEquals(
+                Can.of("a", "b"),
+                Can.of("a", "b", "a").unique());
+    }
+
+    @Test
+    void uniqueByEqualityRelation() {
+
+        final BiPredicate<String, String> firstCharEquility =
+                (left, right) -> left.charAt(0) == right.charAt(0);
+
+        assertEquals(
+                Can.empty(),
+                Can.<String>empty().unique(firstCharEquility));
+
+        assertEquals(
+                Can.of("a"),
+                Can.of("a").unique(firstCharEquility));
+
+        assertEquals(
+                Can.of("aDog"),
+                Can.of("aDog", "aCat", "aMonkey").unique(firstCharEquility));
+
+        assertEquals(
+                Can.of("aDog", "bCat", "cMonkey"),
+                Can.of("aDog", "bCat", "cMonkey").unique(firstCharEquility));
+
+        assertEquals(
+                Can.of("aDog", "bCat"),
+                Can.of("aDog", "bCat", "aMonkey").unique(firstCharEquility));
+
+    }
+
+
     // -- HEPER
 
-    private static <T> void assertSetEquals(Set<T> a, Set<T> b) {
+    private static <T> void assertSetEquals(final Set<T> a, final Set<T> b) {
         assertTrue(_Sets.minus(a, b).isEmpty());
         assertTrue(_Sets.minus(b, a).isEmpty());
     }