### Question:
DisjointSet { public DisjointSet<R> merge(DisjointSet<R> other) { DisjointSet<R> result = new DisjointSet<>(this); for (Map.Entry<R, R> entry : other.matches.entrySet()) { result.union(entry.getKey(), entry.getValue()); } return result; } DisjointSet();  DisjointSet(Set<R> elements);  DisjointSet(DisjointSet<R> elements);  DisjointSet(DisjointSet<R> elements, R e1, R e2); int size(); DisjointSet<R> merge(DisjointSet<R> other); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testMerge() { DisjointSet<Integer> ds2 = new DisjointSet<>(); for (int i = 0; i < 8; i++) { ds2.union(i, i + 100); } ds2 = ds2.merge(ds); assertEquals(18, ds2.matches().size()); Set<Integer> treeRoots = new HashSet<>(); for (int element : ds2.matches().keySet()) { treeRoots.add(ds2.find(element)); } assertEquals(2, treeRoots.size()); }