InclusionDependencyUtil { public List<InclusionDependency> getMax(final Collection<InclusionDependency> toMinify) { final List<InclusionDependency> ind = new LinkedList<>(toMinify); ind.sort(Comparator.comparing(this::degreeOf).reversed()); final List<InclusionDependency> maxInd = new ArrayList<>(); while (!ind.isEmpty()) { final InclusionDependency current = ind.remove(0); ind.removeAll(containedOf(current, ind)); maxInd.add(current); } return maxInd; }  static ImmutableSet<InclusionDependency> sortIndAttributes(Collection<InclusionDependency> inds); List<InclusionDependency> getMax(final Collection<InclusionDependency> toMinify);  }
@Test void maxInd_unrelatedColumns() { final List<InclusionDependency> toCheck = asList( ind("wx", "yz"), a_b(TABLE)); final List<InclusionDependency> expected = new ArrayList<>(toCheck); assertThat(util.getMax(toCheck)).hasSameElementsAs(expected); }
@Test void maxInd_sharedColumn_contained() { final List<InclusionDependency> toCheck = asList( ind("wx", "yz"), ind("w", "y")); assertThat(util.getMax(toCheck)).containsOnly(ind("wx", "yz")); }
@Test void maxInd_sharedColumns_notContained() { final List<InclusionDependency> toCheck = asList( ind("wx", "yz"), ind("x", "y")); final List<InclusionDependency> expected = new ArrayList<>(toCheck); assertThat(util.getMax(toCheck)).hasSameElementsAs(expected); }
@Test void maxInd_shift_notContained() { final List<InclusionDependency> toCheck = asList( ind("klm", "nop"), ind("lmk", "pno")); final List<InclusionDependency> expected = new ArrayList<>(toCheck); assertThat(util.getMax(toCheck)).hasSameElementsAs(expected); }
@Test void maxInd_crossOver() { final List<InclusionDependency> toCheck = asList( ind("wx", "yz"), ind("xw", "zy")); assertThat(util.getMax(toCheck)).hasSize(1); }
@Test void maxInd_ofDifferentTables() { final List<InclusionDependency> toCheck = asList(a_b(TABLE), a_b("other")); final List<InclusionDependency> expected = new ArrayList<>(toCheck); assertThat(util.getMax(toCheck)).hasSameElementsAs(expected); }
@Test void maxInd_largestContainsAll() { final List<InclusionDependency> toCheck = asList( ind("abc", "def"), ind("a", "d"), ind("b", "e"), ind("c", "f"), ind("ab", "de"), ind("bc", "ef")); assertThat(util.getMax(toCheck)).containsOnly(ind("abc", "def")); }
@Test void maxInd_emptyInput() { assertThat(util.getMax(emptyList())).isEmpty(); }
@Test void maxInd_trivialRetained() { final List<InclusionDependency> toCheck = asList(ind("a", "a"), ind("xy", "xy")); final List<InclusionDependency> expected = new ArrayList<>(toCheck); assertThat(util.getMax(toCheck)).hasSameElementsAs(expected); }
@Test void maxInd_sortingProperty() { final List<InclusionDependency> toCheck = asList(ind("a", "b"), ind("xa", "xb")); assertThat(util.getMax(toCheck)).containsOnly(ind("xa", "xb")); }
@Test void maxInd_withRepeatedColumns() { final List<InclusionDependency> toCheck = asList(ind("aaa", "bbb"), ind("aa", "bb")); assertThat(util.getMax(toCheck)).containsOnly(ind("aaa", "bbb")); }