22import static org.junit.jupiter.api.Assertions.assertEquals;
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.HashSet;
30import org.junit.jupiter.api.Test;
45 List<Set<Integer>> list =
new ArrayList<Set<Integer>>();
46 list.add(
new HashSet<Integer>(Arrays.asList(1,2,3)));
47 list.add(
new HashSet<Integer>(Arrays.asList(7,9)));
48 list.add(
new HashSet<Integer>(Arrays.asList(8,10)));
49 list.add(
new HashSet<Integer>(Arrays.asList(2,3,4)));
50 list.add(
new HashSet<Integer>(Arrays.asList(4,5,6)));
51 list.add(
new HashSet<Integer>(Arrays.asList(7,8)));
52 list.add(
new HashSet<Integer>(Arrays.asList(1)));
53 list.add(
new HashSet<Integer>(Arrays.asList(10)));
54 list.add(
new HashSet<Integer>(Arrays.asList(11)));
55 list.add(
new HashSet<Integer>(Arrays.asList(11)));
56 list.add(
new HashSet<Integer>(Arrays.asList(7,8)));
57 list.add(
new HashSet<Integer>(Arrays.asList(11)));
59 Set<Integer> expectedOne =
new HashSet<Integer>(Arrays.asList(
61 Set<Integer> expectedTwo =
new HashSet<Integer>(Arrays.asList(
63 Set<Integer> expectedThree =
new HashSet<Integer>(Arrays.asList(
67 assertEquals(3,list.size(),
"Number of united sets");
68 assertEquals(expectedOne,list.get(0),
"Elements in first set");
69 assertEquals(expectedTwo,list.get(1),
"Elements in second set");
70 assertEquals(expectedThree,list.get(2),
"Elements in third set");
static< T > void unionOfIntersectingSets(List< Set< T > > list)
Takes the union of any two sets in this list that intersect.