add static intersection method for sorted lists
This commit is contained in:
@@ -1032,4 +1032,31 @@ public class IntListTest {
|
||||
list.replaceAll(v -> 2); // replace all with 2 -> [2,2,2,2]
|
||||
Assert.assertFalse("unsorted list stays unsorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectionSortedLists() {
|
||||
{
|
||||
final IntList a = IntList.of(0, 1, 2, 3, 4);
|
||||
final IntList b = IntList.of(2, 4, 5);
|
||||
final IntList actual = IntList.intersection(a, b);
|
||||
Assert.assertEquals(IntList.of(2, 4), actual);
|
||||
}
|
||||
|
||||
/*
|
||||
* cardinality of elements that occur multiple time is equal to the minimum
|
||||
* cardinality in either list
|
||||
*/
|
||||
{
|
||||
final IntList a = IntList.of(3, 3, 3);
|
||||
final IntList b = IntList.of(3, 3);
|
||||
final IntList actual = IntList.intersection(a, b);
|
||||
Assert.assertEquals(IntList.of(3, 3), actual);
|
||||
}
|
||||
{
|
||||
final IntList a = IntList.of(4);
|
||||
final IntList b = IntList.of(4, 4, 4);
|
||||
final IntList actual = IntList.intersection(a, b);
|
||||
Assert.assertEquals(IntList.of(4), actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user