method2testcases
stringlengths
118
3.08k
### Question: IteratorUtils { public static <T> Optional<T> next(Iterator<T> it) { if (it.hasNext()) { T entry = it.next(); return Optional.of(entry); } return Optional.empty(); } static Optional<T> next(Iterator<T> it); static OptionalDouble next(OfDouble it); }### Answer: @Test public void testNext() { List<Integer> list = Collections.singletonList(1); Iterator<Integer> it = list.iterator(); assertThat(IteratorUtils.next(it)).hasValue(1); assertThat(IteratorUtils.next(it)).isEmpty(); } @Test public void testNextDouble() { DoubleList list = DoubleLists.singleton(1.0); OfDouble it = list.iterator(); assertThat(IteratorUtils.next(it).boxed()).hasValue(1.0); assertThat(IteratorUtils.next(it).boxed()).isEmpty(); }
### Question: SimpleColumnCombination implements Comparable<SimpleColumnCombination> { public int[] getColumns() { return columns; } SimpleColumnCombination(int table, int[] columns); private SimpleColumnCombination(int table, int[] columns, int additionalColumn); boolean isActive(); void setActive(boolean active); long getDistinctCount(); static SimpleColumnCombination create(int table, int... columns); SimpleColumnCombination flipOff(int position); int getTable(); int getColumn(int index); int[] getColumns(); boolean startsWith(SimpleColumnCombination other); SimpleColumnCombination combineWith(SimpleColumnCombination other, Map<SimpleColumnCombination, SimpleColumnCombination> columnCombinations); int lastColumn(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(SimpleColumnCombination o); @Override String toString(); int setIndex(); void setIndex(int index); }### Answer: @Test public void testGetColumns() throws Exception { SimpleColumnCombination a = SimpleColumnCombination.create(TABLE, 2,3,4); assertThat(a.getColumns(), equalTo(new int[]{2, 3, 4})); }
### Question: CollectionUtils { public static IntSet mutableSingleton(int i) { IntSet set = new IntOpenHashSet(); set.add(i); return set; } static List<T> asList(T obj); static IntSet mutableSingleton(int i); static Optional<Entry<V>> ceilingEntry(Double2ObjectSortedMap<V> sortedMap, double from); static Optional<V> ceilingValue(Double2ObjectSortedMap<V> sortedMap, double from); static Collection<Tuple2<T, T>> crossProduct(List<T> list); static OptionalDouble first(DoubleSortedSet set); static void forEach(Double2ObjectMap<V> map, DoubleObjectBiConsumer<V> action); static void forEach(Int2ObjectMap<V> map, IntObjectBiConsumer<V> action); static Optional<T> head(List<T> clusters); static Optional<IntCollection> intersection(Collection<IntCollection> clusters); static IntSet merge(IntSet left, IntCollection right); static IntCollection merge(IntCollection left, IntCollection right); static Collection<T> merge(Collection<T> left, Collection<T> right); static Predicate<Collection<T>> sizeBelow(int maxSize); static List<T> sort(Collection<T> collection, Comparator<T> comparator); static Collection<T> tail(List<T> clusters); static Collection<String> toString(Iterable<T> objects); }### Answer: @Test public void testAsSet() { IntSet set = mutableSingleton(1); assertThat(set).hasSize(1); assertThat(set).contains(1); set.add(2); assertThat(set).hasSize(2); assertThat(set).contains(1, 2); }
### Question: CollectionUtils { public static <V> Optional<V> ceilingValue(Double2ObjectSortedMap<V> sortedMap, double from) { return ceilingEntry(sortedMap, from) .map(Entry::getValue); } static List<T> asList(T obj); static IntSet mutableSingleton(int i); static Optional<Entry<V>> ceilingEntry(Double2ObjectSortedMap<V> sortedMap, double from); static Optional<V> ceilingValue(Double2ObjectSortedMap<V> sortedMap, double from); static Collection<Tuple2<T, T>> crossProduct(List<T> list); static OptionalDouble first(DoubleSortedSet set); static void forEach(Double2ObjectMap<V> map, DoubleObjectBiConsumer<V> action); static void forEach(Int2ObjectMap<V> map, IntObjectBiConsumer<V> action); static Optional<T> head(List<T> clusters); static Optional<IntCollection> intersection(Collection<IntCollection> clusters); static IntSet merge(IntSet left, IntCollection right); static IntCollection merge(IntCollection left, IntCollection right); static Collection<T> merge(Collection<T> left, Collection<T> right); static Predicate<Collection<T>> sizeBelow(int maxSize); static List<T> sort(Collection<T> collection, Comparator<T> comparator); static Collection<T> tail(List<T> clusters); static Collection<String> toString(Iterable<T> objects); }### Answer: @Test public void testCeilingValue() { Double2ObjectSortedMap<String> map = new Double2ObjectRBTreeMap<>(); map.put(0.1, "foo"); map.put(0.2, "bar"); assertThat(ceilingValue(map, 0.05)).hasValue("foo"); assertThat(ceilingValue(map, 0.1)).hasValue("foo"); assertThat(ceilingValue(map, 0.15)).hasValue("bar"); assertThat(ceilingValue(map, 0.2)).hasValue("bar"); assertThat(ceilingValue(map, 0.25)).isEmpty(); }
### Question: CollectionUtils { public static OptionalDouble first(DoubleSortedSet set) { if (set.isEmpty()) { return OptionalDouble.empty(); } double first = set.firstDouble(); return OptionalDouble.of(first); } static List<T> asList(T obj); static IntSet mutableSingleton(int i); static Optional<Entry<V>> ceilingEntry(Double2ObjectSortedMap<V> sortedMap, double from); static Optional<V> ceilingValue(Double2ObjectSortedMap<V> sortedMap, double from); static Collection<Tuple2<T, T>> crossProduct(List<T> list); static OptionalDouble first(DoubleSortedSet set); static void forEach(Double2ObjectMap<V> map, DoubleObjectBiConsumer<V> action); static void forEach(Int2ObjectMap<V> map, IntObjectBiConsumer<V> action); static Optional<T> head(List<T> clusters); static Optional<IntCollection> intersection(Collection<IntCollection> clusters); static IntSet merge(IntSet left, IntCollection right); static IntCollection merge(IntCollection left, IntCollection right); static Collection<T> merge(Collection<T> left, Collection<T> right); static Predicate<Collection<T>> sizeBelow(int maxSize); static List<T> sort(Collection<T> collection, Comparator<T> comparator); static Collection<T> tail(List<T> clusters); static Collection<String> toString(Iterable<T> objects); }### Answer: @Test public void testFirst() { assertThat(CollectionUtils.first(DoubleSortedSets.EMPTY_SET).boxed()).isEmpty(); assertThat( CollectionUtils.first(new DoubleRBTreeSet(Sets.newTreeSet(Arrays.asList(2.0, 1.0)))) .boxed()).hasValue(1.0); }
### Question: CollectionUtils { public static IntSet merge(IntSet left, IntCollection right) { left.addAll(right); return left; } static List<T> asList(T obj); static IntSet mutableSingleton(int i); static Optional<Entry<V>> ceilingEntry(Double2ObjectSortedMap<V> sortedMap, double from); static Optional<V> ceilingValue(Double2ObjectSortedMap<V> sortedMap, double from); static Collection<Tuple2<T, T>> crossProduct(List<T> list); static OptionalDouble first(DoubleSortedSet set); static void forEach(Double2ObjectMap<V> map, DoubleObjectBiConsumer<V> action); static void forEach(Int2ObjectMap<V> map, IntObjectBiConsumer<V> action); static Optional<T> head(List<T> clusters); static Optional<IntCollection> intersection(Collection<IntCollection> clusters); static IntSet merge(IntSet left, IntCollection right); static IntCollection merge(IntCollection left, IntCollection right); static Collection<T> merge(Collection<T> left, Collection<T> right); static Predicate<Collection<T>> sizeBelow(int maxSize); static List<T> sort(Collection<T> collection, Comparator<T> comparator); static Collection<T> tail(List<T> clusters); static Collection<String> toString(Iterable<T> objects); }### Answer: @Test public void testMerge() { IntSet set1 = mutableSingleton(1); IntSet set2 = mutableSingleton(2); IntSet merged = merge(set1, set2); assertThat(merged).hasSize(2); assertThat(merged).contains(1, 2); set1.add(3); assertThat(set1).hasSize(3); assertThat(set1).contains(1, 2, 3); }
### Question: BigDecimalUtils { public static BigDecimal valueOf(int number) { return 0 <= number && number < NUMBERS.length ? NUMBERS[number] : BigDecimal.valueOf(number); } static BigDecimal valueOf(int number); }### Answer: @Test public void test() { assertThat(BigDecimalUtils.valueOf(0).intValue()).isEqualTo(0); assertThat(BigDecimalUtils.valueOf(100).intValue()).isEqualTo(100); assertThat(BigDecimalUtils.valueOf(1000).intValue()).isEqualTo(1000); }
### Question: RowImpl extends AbstractRow { @Override public <T> Optional<T> get(Column<T> column) { return values.get(column) .map(CastUtils::as); } private RowImpl(Schema schema, Map<Column<?>, Object> values); @Override Optional<T> get(Column<T> column); }### Answer: @Test public void testGet() { Row row = createRow(); Optional<String> a = row.get(A); assertThat(a).hasValue("foo"); Optional<Integer> b = row.get(B); assertThat(b).hasValue(Integer.valueOf(0)); assertThat(row.get(C)).isEmpty(); } @Test public void testWrongType() { Row row = createRow(); Column<String> wrongB = Column.of("b", String.class); assertThat(row.get(wrongB)).isEmpty(); }
### Question: ColumnPair implements Serializable, Hashable { public Class<T> getType() { return left.getType(); } Class<T> getType(); @Override void hash(Hasher hasher); @Override String toString(); }### Answer: @Test public void test() { Column<Integer> left = Column.of("a", Integer.class); Column<Integer> right = Column.of("a", Integer.class); ColumnPair<Integer> pair = new ColumnPair<>(left, right); assertThat(pair.getType()).isEqualTo(Integer.class); assertThat(pair.getType()).isEqualTo(left.getType()); assertThat(pair.getType()).isEqualTo(right.getType()); }
### Question: ResultSetRelation implements Relation { @Override public RelationalInput open() throws InputOpenException { return open(query); } @Override Schema getSchema(); @Override long getSize(); @Override RelationalInput open(); @Override void hash(Hasher hasher); }### Answer: @Test public void testOpen() throws SQLException, InputCloseException, InputOpenException { try (Statement statement = connection.createStatement()) { String query = "SELECT * FROM Person"; Relation relation = new ResultSetRelation(statement, query); try (RelationalInput input = relation.open()) { Row bob = input.iterator().next(); assertThat(bob.get(NAME)).hasValue("Bob"); } try (RelationalInput input = relation.open()) { Row bob = input.iterator().next(); assertThat(bob.get(NAME)).hasValue("Bob"); } } }
### Question: ResultSetRelation implements Relation { @Override public long getSize() throws InputException { try (ResultSet resultSet = executeQuery("SELECT COUNT(*) FROM (" + query + ") rel")) { if (resultSet.next()) { return resultSet.getLong(1); } throw new IllegalStateException("No count returned"); } catch (SQLException e) { throw new InputOpenException(e); } } @Override Schema getSchema(); @Override long getSize(); @Override RelationalInput open(); @Override void hash(Hasher hasher); }### Answer: @Test public void testSize() throws SQLException, InputException { try (Statement statement = connection.createStatement()) { String query = "SELECT * FROM Person"; Relation relation = new ResultSetRelation(statement, query); assertThat(relation.getSize()).isEqualTo(3L); } try (Statement statement = connection.createStatement()) { String query = "SELECT * FROM PERSON WHERE name IS NULL"; Relation relation = new ResultSetRelation(statement, query); assertThat(relation.getSize()).isEqualTo(0L); } }
### Question: ResultSetInput implements RelationalInput { static RelationalInput create(ResultSet resultSet) { ResultSetIterator rows = ResultSetIterator.create(resultSet); return new ResultSetInput(rows); } @Override void close(); @Override Schema getSchema(); @Override Iterator<Row> iterator(); }### Answer: @Test public void testNumberOfRows() throws SQLException, InputCloseException { try (Statement statement = connection.createStatement()) { ResultSet resultSet = statement.executeQuery("SELECT * FROM Person"); try (RelationalInput input = ResultSetInput.create(resultSet)) { assertThat(Iterables.size(input)).isEqualTo(3); } } }
### Question: ResultSetSchemaFactory { static Schema createSchema(ResultSetMetaData metaData) throws SQLException { return new ResultSetSchemaFactory(metaData).createSchema(); } }### Answer: @Test public void test() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(2)); doReturn(String.class.getName()).when(metaData).getColumnClassName(1); doReturn(Integer.class.getName()).when(metaData).getColumnClassName(2); doReturn("a").when(metaData).getColumnName(1); doReturn("b").when(metaData).getColumnName(2); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).hasSize(2); assertThat(schema.getColumns()).contains(Column.of("a", String.class)); assertThat(schema.getColumns()).contains(Column.of("b", Integer.class)); } @Test public void testClassNotFound() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(1)); when(metaData.getColumnClassName(1)).thenReturn("foo.bar.Baz"); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).isEmpty(); } @Test public void testTableName() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(1)); when(metaData.getColumnClassName(1)).thenReturn(String.class.getName()); when(metaData.getColumnName(1)).thenReturn("a"); when(metaData.getTableName(1)).thenReturn("t"); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).hasSize(1); assertThat(schema.getColumns()).contains(Column.of("a", String.class, "t")); }
### Question: ResultTransformer { MatchingDependencyResult transform(SupportedMD supportedMD) { return with(supportedMD).toResult(); } }### Answer: @Test public void test() { ResultTransformer transformer = createConsumer(); MD md = new MDImpl(new MDSiteImpl(2).set(0, 0.8), new MDElementImpl(1, 0.7)); SupportedMD result = new SupportedMD(md, 10); MatchingDependencyResult transformed = transformer.transform(result); MatchingDependency dependency = new MatchingDependency( Collections.singletonList( new ColumnMatchWithThreshold<>(new ColumnMapping<>(AB, similarityMeasure), 0.8)), new ColumnMatchWithThreshold<>(new ColumnMapping<>(AC, similarityMeasure), 0.7) ); assertThat(transformed).isEqualTo(new MatchingDependencyResult(dependency, 10)); }
### Question: SimilaritySet { public double get(int attr) { return similaritySet[attr]; } double get(int attr); boolean isViolated(MDElement element); int size(); @Override String toString(); }### Answer: @Test public void testGet() { SimilaritySet similaritySet = new SimilaritySet(new double[]{0.2, 0.3}); assertThat(similaritySet.get(0)).isEqualTo(0.2); assertThat(similaritySet.get(1)).isEqualTo(0.3); }
### Question: SimpleColumnCombination implements Comparable<SimpleColumnCombination> { public SimpleColumnCombination combineWith(SimpleColumnCombination other, Map<SimpleColumnCombination, SimpleColumnCombination> columnCombinations) { Verify.verify(table == other.table, "only merge inside a table"); SimpleColumnCombination combinedCombination = new SimpleColumnCombination(table, columns, other.lastColumn()); if (columnCombinations != null) { SimpleColumnCombination existingCombination = columnCombinations.get(combinedCombination); if (existingCombination == null) { columnCombinations.put(combinedCombination, combinedCombination); } else { combinedCombination = existingCombination; } } return combinedCombination; } SimpleColumnCombination(int table, int[] columns); private SimpleColumnCombination(int table, int[] columns, int additionalColumn); boolean isActive(); void setActive(boolean active); long getDistinctCount(); static SimpleColumnCombination create(int table, int... columns); SimpleColumnCombination flipOff(int position); int getTable(); int getColumn(int index); int[] getColumns(); boolean startsWith(SimpleColumnCombination other); SimpleColumnCombination combineWith(SimpleColumnCombination other, Map<SimpleColumnCombination, SimpleColumnCombination> columnCombinations); int lastColumn(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(SimpleColumnCombination o); @Override String toString(); int setIndex(); void setIndex(int index); }### Answer: @Test public void testCombineWith() throws Exception { SimpleColumnCombination a = SimpleColumnCombination.create(TABLE, 2,3,6); SimpleColumnCombination b = SimpleColumnCombination.create(TABLE, 2,3,7); SimpleColumnCombination result = SimpleColumnCombination.create(TABLE, 2, 3, 6, 7); assertThat(a.combineWith(b, null), equalTo(result)); }
### Question: SimilaritySet { public boolean isViolated(MDElement element) { int attr = element.getId(); return element.getThreshold() > similaritySet[attr]; } double get(int attr); boolean isViolated(MDElement element); int size(); @Override String toString(); }### Answer: @Test public void testIsViolated() { SimilaritySet similaritySet = new SimilaritySet(new double[]{0.2, 0.3}); assertThat(similaritySet.isViolated(new MDElementImpl(0, 0.1))).isFalse(); assertThat(similaritySet.isViolated(new MDElementImpl(0, 0.2))).isFalse(); assertThat(similaritySet.isViolated(new MDElementImpl(0, 0.3))).isTrue(); }
### Question: LatticeHelper { static Lattice createLattice(LevelFunction levelFunction) { int columnPairs = levelFunction.size(); Lattice lattice = new LatticeImpl(levelFunction); MDSite lhs = new MDSiteImpl(columnPairs); for (int rhsAttr = 0; rhsAttr < columnPairs; rhsAttr++) { MD md = createMD(lhs, rhsAttr); lattice.add(md); } return lattice; } }### Answer: @Test public void testCreate() { int columnPairs = 4; Lattice lattice = LatticeHelper.createLattice(new Cardinality(columnPairs)); assertThat(lattice.getDepth()).isEqualTo(0); assertThat(lattice.getLevel(0)).hasSize(1); assertThat(lattice.containsMdOrGeneralization( new MDImpl(new MDSiteImpl(columnPairs), new MDElementImpl(0, SimilarityMeasure.MAX_SIMILARITY)))).isEqualTo(true); assertThat(lattice.containsMdOrGeneralization( new MDImpl(new MDSiteImpl(columnPairs), new MDElementImpl(1, SimilarityMeasure.MAX_SIMILARITY)))).isEqualTo(true); assertThat(lattice.containsMdOrGeneralization( new MDImpl(new MDSiteImpl(columnPairs), new MDElementImpl(2, SimilarityMeasure.MAX_SIMILARITY)))).isEqualTo(true); assertThat(lattice.containsMdOrGeneralization( new MDImpl(new MDSiteImpl(columnPairs), new MDElementImpl(3, SimilarityMeasure.MAX_SIMILARITY)))).isEqualTo(true); }
### Question: Classifier { public boolean isValidAndMinimal(double similarity) { return isValid(similarity) && isMinimal(similarity); } boolean isValidAndMinimal(double similarity); }### Answer: @Test public void testLowerBound() { Classifier classifier = new Classifier(0.0, 0.5); assertThat(classifier.isValidAndMinimal(0.6)).isTrue(); assertThat(classifier.isValidAndMinimal(0.5)).isFalse(); } @Test public void testMinThreshold() { Classifier classifier = new Classifier(0.5, 0.0); assertThat(classifier.isValidAndMinimal(0.5)).isTrue(); assertThat(classifier.isValidAndMinimal(0.4)).isFalse(); } @Test public void testMinThresholdAndLowerBound() { Classifier classifier = new Classifier(0.5, 0.5); assertThat(classifier.isValidAndMinimal(0.6)).isTrue(); assertThat(classifier.isValidAndMinimal(0.5)).isFalse(); }
### Question: FullLattice { public Optional<LatticeMD> addIfMinimalAndSupported(MD md) { MDSite lhs = md.getLhs(); if (notSupported.containsMdOrGeneralization(lhs)) { return Optional.empty(); } return lattice.addIfMinimal(md); } Optional<LatticeMD> addIfMinimalAndSupported(MD md); Collection<LatticeMD> findViolated(SimilaritySet similaritySet); int getDepth(); Collection<LatticeMD> getLevel(int level); void markNotSupported(MDSite lhs); int size(); }### Answer: @Test public void testAddNotSupported() { FullLattice fullLattice = new FullLattice(lattice, notSupported); int columnPairs = 4; MDSite lhs = new MDSiteImpl(columnPairs).set(0, 0.5); when(Boolean.valueOf(notSupported.containsMdOrGeneralization(lhs))).thenReturn(Boolean.TRUE); MD md = new MDImpl(lhs, new MDElementImpl(1, 0.7)); Optional<LatticeMD> latticeMD = fullLattice.addIfMinimalAndSupported(md); assertThat(latticeMD).isEmpty(); verify(lattice, never()).addIfMinimal(md); } @Test public void testAddSupported() { FullLattice fullLattice = new FullLattice(lattice, notSupported); int columnPairs = 4; MDSite lhs = new MDSiteImpl(columnPairs).set(0, 0.5); when(Boolean.valueOf(notSupported.containsMdOrGeneralization(lhs))).thenReturn(Boolean.FALSE); MD md = new MDImpl(lhs, new MDElementImpl(1, 0.7)); LatticeMD latticeMD = Mockito.mock(LatticeMD.class); when(lattice.addIfMinimal(md)).thenReturn(Optional.of(latticeMD)); assertThat(fullLattice.addIfMinimalAndSupported(md)).hasValue(latticeMD); verify(lattice).addIfMinimal(md); }
### Question: FullLattice { public Collection<LatticeMD> findViolated(SimilaritySet similaritySet) { return lattice.findViolated(similaritySet); } Optional<LatticeMD> addIfMinimalAndSupported(MD md); Collection<LatticeMD> findViolated(SimilaritySet similaritySet); int getDepth(); Collection<LatticeMD> getLevel(int level); void markNotSupported(MDSite lhs); int size(); }### Answer: @Test public void testFindViolated() { FullLattice fullLattice = new FullLattice(lattice, notSupported); LatticeMD latticeMD = Mockito.mock(LatticeMD.class); SimilaritySet similaritySet = Mockito.mock(SimilaritySet.class); when(lattice.findViolated(similaritySet)).thenReturn(Collections.singletonList(latticeMD)); Collection<LatticeMD> violated = fullLattice.findViolated(similaritySet); assertThat(violated).hasSize(1); assertThat(violated).contains(latticeMD); verify(lattice).findViolated(similaritySet); }
### Question: FullLattice { public int getDepth() { return lattice.getDepth(); } Optional<LatticeMD> addIfMinimalAndSupported(MD md); Collection<LatticeMD> findViolated(SimilaritySet similaritySet); int getDepth(); Collection<LatticeMD> getLevel(int level); void markNotSupported(MDSite lhs); int size(); }### Answer: @Test public void testGetDepth() { FullLattice fullLattice = new FullLattice(lattice, notSupported); when(Integer.valueOf(lattice.getDepth())).thenReturn(Integer.valueOf(2)); assertThat(fullLattice.getDepth()).isEqualTo(2); verify(lattice).getDepth(); }
### Question: FullLattice { public Collection<LatticeMD> getLevel(int level) { Collection<LatticeMD> candidates = lattice.getLevel(level); return StreamUtils.seq(candidates) .filter(this::isSupported) .toList(); } Optional<LatticeMD> addIfMinimalAndSupported(MD md); Collection<LatticeMD> findViolated(SimilaritySet similaritySet); int getDepth(); Collection<LatticeMD> getLevel(int level); void markNotSupported(MDSite lhs); int size(); }### Answer: @Test public void testGetLevel() { FullLattice fullLattice = new FullLattice(lattice, notSupported); LatticeMD latticeMD = Mockito.mock(LatticeMD.class); when(lattice.getLevel(1)).thenReturn(Collections.singletonList(latticeMD)); Collection<LatticeMD> level = fullLattice.getLevel(1); assertThat(level).hasSize(1); assertThat(level).contains(latticeMD); verify(lattice).getLevel(1); }
### Question: SimpleColumnCombination implements Comparable<SimpleColumnCombination> { public SimpleColumnCombination flipOff(int position) { int[] newColumns = new int[columns.length - 1]; System.arraycopy(columns, 0, newColumns, 0, position); System.arraycopy(columns, position + 1, newColumns, position, columns.length - position - 1); return new SimpleColumnCombination(table, newColumns); } SimpleColumnCombination(int table, int[] columns); private SimpleColumnCombination(int table, int[] columns, int additionalColumn); boolean isActive(); void setActive(boolean active); long getDistinctCount(); static SimpleColumnCombination create(int table, int... columns); SimpleColumnCombination flipOff(int position); int getTable(); int getColumn(int index); int[] getColumns(); boolean startsWith(SimpleColumnCombination other); SimpleColumnCombination combineWith(SimpleColumnCombination other, Map<SimpleColumnCombination, SimpleColumnCombination> columnCombinations); int lastColumn(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(SimpleColumnCombination o); @Override String toString(); int setIndex(); void setIndex(int index); }### Answer: @Test public void testFlipOff() throws Exception { SimpleColumnCombination a = SimpleColumnCombination.create(TABLE, 1,2,3); SimpleColumnCombination b = a.flipOff(0); SimpleColumnCombination c = a.flipOff(1); SimpleColumnCombination d = a.flipOff(2); assertThat(b, equalTo(SimpleColumnCombination.create(TABLE, 2, 3))); assertThat(c, equalTo(SimpleColumnCombination.create(TABLE, 1, 3))); assertThat(d, equalTo(SimpleColumnCombination.create(TABLE, 1, 2))); }
### Question: FullLattice { public void markNotSupported(MDSite lhs) { notSupported.addIfMinimal(lhs); } Optional<LatticeMD> addIfMinimalAndSupported(MD md); Collection<LatticeMD> findViolated(SimilaritySet similaritySet); int getDepth(); Collection<LatticeMD> getLevel(int level); void markNotSupported(MDSite lhs); int size(); }### Answer: @Test public void testMarkNotSupported() { FullLattice fullLattice = new FullLattice(lattice, notSupported); int columnPairs = 4; MDSite lhs = new MDSiteImpl(columnPairs).set(0, 0.5); fullLattice.markNotSupported(lhs); verify(notSupported).addIfMinimal(lhs); }
### Question: ThresholdLowerer { public void lowerThreshold(int rhsAttr, double threshold) { MDElement rhs = new MDElementImpl(rhsAttr, threshold); lowerThreshold(rhs); } void lowerThreshold(int rhsAttr, double threshold); void lowerThreshold(MDElement rhs, boolean minimal); }### Answer: @Test public void testMinimal() { int rhsAttr = 0; double threshold = 0.1; ThresholdLowerer task = new ThresholdLowerer(latticeMd); when(Boolean.valueOf(latticeMd.wouldBeMinimal(new MDElementImpl(rhsAttr, threshold)))).thenReturn(Boolean.TRUE); when(latticeMd.getLhs()).thenReturn(lhs); task.lowerThreshold(rhsAttr, threshold); verify(latticeMd).setRhs(rhsAttr, threshold); } @Test public void testNotMinimal() { int rhsAttr = 0; double threshold = 0.1; ThresholdLowerer task = new ThresholdLowerer(latticeMd); when(Boolean.valueOf(latticeMd.wouldBeMinimal(new MDElementImpl(rhsAttr, threshold)))).thenReturn(Boolean.FALSE); when(latticeMd.getLhs()).thenReturn(lhs); task.lowerThreshold(rhsAttr, threshold); verify(latticeMd).removeRhs(rhsAttr); verify(latticeMd, never()).setRhs(rhsAttr, threshold); } @Test public void testTrivial() { int rhsAttr = 0; double threshold = 0.1; ThresholdLowerer task = new ThresholdLowerer(latticeMd); when(Boolean.valueOf(latticeMd.wouldBeMinimal(new MDElementImpl(rhsAttr, threshold)))).thenReturn(Boolean.TRUE); when(latticeMd.getLhs()).thenReturn(lhs); when(Double.valueOf(lhs.getOrDefault(0))).thenReturn(Double.valueOf(0.1)); task.lowerThreshold(rhsAttr, threshold); verify(latticeMd).removeRhs(rhsAttr); verify(latticeMd, never()).setRhs(rhsAttr, threshold); }
### Question: SimilaritySetProcessor { @Timed Statistics process(SimilaritySet similaritySet) { return with(similaritySet).process(); } }### Answer: @SuppressWarnings("unchecked") @Test public void test() { SimilaritySetProcessor processor = createProcessor(); SimilaritySet similaritySet = Mockito.mock(SimilaritySet.class); LatticeMD latticeMD = Mockito.mock(LatticeMD.class); MDSite lhs = Mockito.mock(MDSite.class); when(latticeMD.getLhs()).thenReturn(lhs); when(lattice.findViolated(similaritySet)) .thenReturn(Collections.singletonList(latticeMD), Collections.emptyList()); int rhsAttr = 0; MDElement rhs = new MDElementImpl(rhsAttr, 0.5); when(latticeMD.getRhs()).thenReturn(Collections.singletonList(rhs)); when(Boolean.valueOf(similaritySet.isViolated(rhs))).thenReturn(Boolean.TRUE); when(Double.valueOf(similaritySet.get(rhsAttr))).thenReturn(Double.valueOf(0.4)); when(specializer.specialize(lhs, rhs, similaritySet)).thenReturn(Collections.emptyList()); when(Boolean.valueOf(latticeMD.wouldBeMinimal(new MDElementImpl(rhsAttr, 0.4)))).thenReturn(Boolean.FALSE); processor.process(similaritySet); verify(latticeMD).removeRhs(rhsAttr); verify(lattice, never()).addIfMinimalAndSupported(any()); }
### Question: Statistics { void add(Statistics statistics) { this.count += statistics.count; this.processed += statistics.processed; this.newDeduced += statistics.newDeduced; this.recommendations += statistics.recommendations; } }### Answer: @Test public void testAdd() { Statistics statistics = new Statistics(); statistics.count(); Statistics toAdd = new Statistics(); toAdd.count(); toAdd.newDeduced(); statistics.add(toAdd); assertThat(statistics.getCount()).isEqualTo(2); assertThat(statistics.getNewDeduced()).isEqualTo(1); }
### Question: Statistics { void count() { count++; } }### Answer: @Test public void testCount() { Statistics statistics = new Statistics(); assertThat(statistics.getCount()).isEqualTo(0); statistics.count(); assertThat(statistics.getCount()).isEqualTo(1); }
### Question: Statistics { void newDeduced() { newDeduced++; } }### Answer: @Test public void testNewDeduced() { Statistics statistics = new Statistics(); assertThat(statistics.getNewDeduced()).isEqualTo(0); statistics.newDeduced(); assertThat(statistics.getNewDeduced()).isEqualTo(1); }
### Question: PreprocessedColumnPairImpl implements PreprocessedColumnPair { @Timed @Override public IntCollection getAllSimilarRightRecords(int[] left, double threshold) { int leftValue = left[leftColumn]; return getAllSimilarRightRecords(leftValue, threshold); } @Timed @Override IntCollection getAllSimilarRightRecords(int[] left, double threshold); @Override IntCollection getAllSimilarRightRecords(int leftValue, double threshold); @Override double getMinSimilarity(); @Override Iterable<Double> getThresholds(ThresholdFilter thresholdFilter); @Override double getSimilarity(int leftValue, int rightValue); @Override int getRightValue(int[] right); @Override int getLeftValue(int[] left); }### Answer: @Test public void testGetAllSimilarRightRecords() { List<PreprocessedColumnPair> columnPairs = create(); PreprocessedColumnPair ab = columnPairs.get(0); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.5)).hasSize(4); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.5)).contains(Integer.valueOf(51)); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.5)).contains(Integer.valueOf(52)); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.5)).contains(Integer.valueOf(81)); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.5)).contains(Integer.valueOf(82)); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.6)).hasSize(2); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.6)).contains(Integer.valueOf(51)); assertThat(ab.getAllSimilarRightRecords(new int[]{4}, 0.6)).contains(Integer.valueOf(52)); }
### Question: PreprocessedColumnPairImpl implements PreprocessedColumnPair { @Override public double getSimilarity(int leftValue, int rightValue) { return similarityIndex.getSimilarity(leftValue, rightValue); } @Timed @Override IntCollection getAllSimilarRightRecords(int[] left, double threshold); @Override IntCollection getAllSimilarRightRecords(int leftValue, double threshold); @Override double getMinSimilarity(); @Override Iterable<Double> getThresholds(ThresholdFilter thresholdFilter); @Override double getSimilarity(int leftValue, int rightValue); @Override int getRightValue(int[] right); @Override int getLeftValue(int[] left); }### Answer: @Test public void testGetSimilarity() { List<PreprocessedColumnPair> columnPairs = create(); PreprocessedColumnPair ab = columnPairs.get(0); assertThat(ab.getSimilarity(new int[]{4}, new int[]{5, 0})).isEqualTo(0.8); assertThat(ab.getSimilarity(new int[]{4}, new int[]{8, 0})).isEqualTo(0.5); }
### Question: ValidationTask { AnalyzeTask validate() { ValidationResult results = validator.validate(lhs, rhs); return new AnalyzeTask(results, lowerer); } }### Answer: @Test public void test() { int columnPairs = 4; Collection<Rhs> rhs = Arrays .asList(Rhs.builder().rhsAttr(0).threshold(1.0).lowerBound(0.0).build(), Rhs.builder().rhsAttr(1).threshold(1.0).lowerBound(0.0).build()); MDSite lhs = new MDSiteImpl(columnPairs); RhsResult expected1 = RhsResult.builder() .rhsAttr(0) .threshold(0.5) .violations(Collections.emptyList()) .validAndMinimal(false) .build(); RhsResult expected2 = RhsResult.builder() .rhsAttr(1) .threshold(0.6) .violations(Collections.emptyList()) .validAndMinimal(true) .build(); when(validator.validate(lhs, rhs)) .thenReturn(new ValidationResult(Mockito.mock(LhsResult.class), Arrays.asList(expected1, expected2))); ValidationTask task = createTask(lhs, rhs); AnalyzeTask analyzeTask = task.validate(); ValidationResult result = analyzeTask.getResult(); assertThat(result.getRhsResults()).contains(expected1); assertThat(result.getRhsResults()).contains(expected2); }
### Question: CandidateProcessor { Statistics validateAndAnalyze(Collection<Candidate> candidates) { log.debug("Will perform {} validations", Integer.valueOf(candidates.size())); Iterable<AnalyzeTask> results = validator.validate(candidates); results.forEach(violationHandler::addViolations); return analyzer.analyze(results); } }### Answer: @Test public void test() { CandidateProcessor processor = createProcessor(); Collection<Candidate> candidates = Collections.singletonList(Mockito.mock(Candidate.class)); AnalyzeTask task = Mockito.mock(AnalyzeTask.class); Collection<AnalyzeTask> results = Collections .singletonList(task); when(task.getResult()).thenReturn(Mockito.mock(ValidationResult.class)); when(validator.validate(candidates)).thenReturn(results); when(analyzer.analyze(results)).thenReturn(Mockito.mock(Statistics.class)); processor.validateAndAnalyze(candidates); verify(validator).validate(candidates); verify(analyzer).analyze(results); }
### Question: CandidateProcessor { Collection<IntArrayPair> getRecommendations() { return violationHandler.pollViolations(); } }### Answer: @Test public void testGetRecommendations() { CandidateProcessor processor = createProcessor(); Collection<Candidate> candidates = Collections.singletonList(Mockito.mock(Candidate.class)); ValidationResult validationResult = Mockito.mock(ValidationResult.class); Collection<AnalyzeTask> results = Collections .singletonList(new AnalyzeTask(validationResult, Mockito.mock(ThresholdLowerer.class))); RhsResult rhsResult = Mockito.mock(RhsResult.class); when(validationResult.getRhsResults()).thenReturn(Collections.singletonList(rhsResult)); IntArrayPair violation = Mockito.mock(IntArrayPair.class); when(rhsResult.getViolations()).thenReturn(Collections.singletonList(violation)); when(validator.validate(candidates)).thenReturn(results); when(analyzer.analyze(results)).thenReturn(Mockito.mock(Statistics.class)); processor.validateAndAnalyze(candidates); Collection<IntArrayPair> recommendations = processor.getRecommendations(); assertThat(recommendations).hasSize(1); assertThat(recommendations).contains(violation); }
### Question: BatchValidator { Iterable<AnalyzeTask> validate(Iterable<Candidate> candidates) { return StreamUtils.stream(candidates, parallel) .map(this::createTask) .map(ValidationTask::validate) .collect(Collectors.toList()); } }### Answer: @Test public void test() { BatchValidator batchValidator = new BatchValidator(validator, parallel); Candidate candidate = Mockito.mock(Candidate.class); LatticeMD latticeMD = Mockito.mock(LatticeMD.class); MDSite lhs = Mockito.mock(MDSite.class); Collection<Rhs> rhs = Collections.emptyList(); ValidationResult validationResult = Mockito.mock(ValidationResult.class); when(candidate.getLatticeMd()).thenReturn(latticeMD); when(candidate.getRhs()).thenReturn(rhs); when(latticeMD.getLhs()).thenReturn(lhs); when(validator.validate(lhs, rhs)).thenReturn(validationResult); Iterable<AnalyzeTask> results = batchValidator .validate(Arrays.asList(candidate, candidate)); assertThat(results).hasSize(2); verify(validator, times(2)).validate(lhs, rhs); }
### Question: SupportBasedFactory implements Factory { @Override public AnalyzeStrategy create(LhsResult lhsResult) { if (isSupported(lhsResult)) { return supportedFactory.create(lhsResult); } return notSupportedFactory.create(lhsResult); } @Override AnalyzeStrategy create(LhsResult lhsResult); }### Answer: @Test public void testNotSupported() { Factory factory = createFactory(); assertThat(factory.create(new LhsResult(Mockito.mock(MDSite.class), 9))) .isInstanceOf(NotSupportedStrategy.class); } @Test public void testSupported() { Factory factory = createFactory(); assertThat(factory.create(new LhsResult(Mockito.mock(MDSite.class), 10))) .isInstanceOf(SupportedStrategy.class); }
### Question: MDSpecializer { Collection<MD> specialize(MD md) { MDSite lhs = md.getLhs(); MDElement rhs = md.getRhs(); return specializer.specialize(lhs, rhs, lhs::getOrDefault); } }### Answer: @Test public void test() { doReturn(OptionalDouble.of(0.8)).when(provider).getNext(0, 0.7); doReturn(OptionalDouble.empty()).when(provider).getNext(1, 1.0); doReturn(OptionalDouble.of(1.0)).when(provider).getNext(2, 0.0); doReturn(OptionalDouble.of(0.6)).when(provider).getNext(3, 0.0); doReturn(OptionalDouble.empty()).when(provider).getNext(4, 0.0); when(Boolean.valueOf(specializationFilter.filter(any(), any()))).thenReturn(Boolean.TRUE); int columnPairs = 5; MDSite lhs = new MDSiteImpl(columnPairs) .set(0, 0.7) .set(1, 1.0); MDElement rhs = new MDElementImpl(3, 0.8); Collection<MD> result = buildSpecializer() .specialize(new MDImpl(lhs, rhs)); assertThat(result).hasSize(3); assertThat(result).contains(new MDImpl(lhs.clone().set(0, 0.8), new MDElementImpl(3, 0.8))); assertThat(result).contains(new MDImpl(lhs.clone().set(2, 1.0), new MDElementImpl(3, 0.8))); assertThat(result).contains(new MDImpl(lhs.clone().set(3, 0.6), new MDElementImpl(3, 0.8))); }
### Question: ViolationHandler { Collection<IntArrayPair> pollViolations() { return violations.poll(); } }### Answer: @Test public void testEmpty() { ViolationHandler violationHandler = new ViolationHandler(); assertThat(violationHandler.pollViolations()).isEmpty(); }
### Question: Statistics { public void add(Statistics statistics) { this.invalid += statistics.invalid; this.notSupported += statistics.notSupported; this.newDeduced += statistics.newDeduced; this.found += statistics.found; this.validated += statistics.validated; this.groupedValidations += statistics.groupedValidations; this.rounds += statistics.rounds; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testAdd() { Statistics statistics = new Statistics(); statistics.found(); statistics.invalid(); statistics.newDeduced(); Statistics toAdd = new Statistics(); toAdd.found(); toAdd.found(); toAdd.invalid(); toAdd.validated(); toAdd.groupedValidation(); toAdd.groupedValidation(); toAdd.round(); statistics.add(toAdd); assertThat(statistics.getRounds()).isEqualTo(1); assertThat(statistics.getInvalid()).isEqualTo(2); assertThat(statistics.getNewDeduced()).isEqualTo(1); assertThat(statistics.getNotSupported()).isEqualTo(0); assertThat(statistics.getFound()).isEqualTo(3); assertThat(statistics.getValidated()).isEqualTo(1); assertThat(statistics.getGroupedValidations()).isEqualTo(2); }
### Question: Statistics { public void found() { found++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testFound() { Statistics statistics = new Statistics(); assertThat(statistics.getFound()).isEqualTo(0); statistics.found(); assertThat(statistics.getFound()).isEqualTo(1); }
### Question: Statistics { public void groupedValidation() { groupedValidations++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testGroupedValidations() { Statistics statistics = new Statistics(); assertThat(statistics.getGroupedValidations()).isEqualTo(0); statistics.groupedValidation(); assertThat(statistics.getGroupedValidations()).isEqualTo(1); }
### Question: Statistics { public void invalid() { invalid++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testInvalid() { Statistics statistics = new Statistics(); assertThat(statistics.getInvalid()).isEqualTo(0); statistics.invalid(); assertThat(statistics.getInvalid()).isEqualTo(1); }
### Question: Statistics { public void newDeduced() { newDeduced++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testNewDeduced() { Statistics statistics = new Statistics(); assertThat(statistics.getNewDeduced()).isEqualTo(0); statistics.newDeduced(); assertThat(statistics.getNewDeduced()).isEqualTo(1); }
### Question: Statistics { public void notSupported() { notSupported++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testNotSupported() { Statistics statistics = new Statistics(); assertThat(statistics.getNotSupported()).isEqualTo(0); statistics.notSupported(); assertThat(statistics.getNotSupported()).isEqualTo(1); }
### Question: Statistics { public void round() { rounds++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testRounds() { Statistics statistics = new Statistics(); assertThat(statistics.getRounds()).isEqualTo(0); statistics.round(); assertThat(statistics.getRounds()).isEqualTo(1); }
### Question: Statistics { public void validated() { validated++; } void add(Statistics statistics); void found(); void groupedValidation(); void invalid(); void newDeduced(); void notSupported(); void round(); void validated(); }### Answer: @Test public void testValidated() { Statistics statistics = new Statistics(); assertThat(statistics.getValidated()).isEqualTo(0); statistics.validated(); assertThat(statistics.getValidated()).isEqualTo(1); }
### Question: FileResultWriter implements ResultListener<T>, Closeable { @Override public void receiveResult(T result) { out.println(result); out.flush(); } FileResultWriter(File file); @Override void close(); @Override void receiveResult(T result); }### Answer: @Test public void test() throws IOException { File file = folder.newFile(); try (FileResultWriter<String> resultWriter = new FileResultWriter<>(file)) { resultWriter.receiveResult("foo"); resultWriter.receiveResult("bar"); } try (BufferedReader in = new BufferedReader(new FileReader(file))) { assertThat(in.readLine()).isEqualTo("foo"); assertThat(in.readLine()).isEqualTo("bar"); } } @Test public void testWriteNull() throws IOException { File file = folder.newFile(); try (FileResultWriter<String> resultWriter = new FileResultWriter<>(file)) { resultWriter.receiveResult(null); } try (BufferedReader in = new BufferedReader(new FileReader(file))) { assertThat(in.readLine()).isEqualTo(Objects.toString(null)); } }
### Question: MultiThresholdProvider implements ThresholdProvider { @Override public OptionalDouble getNext(int attr, double threshold) { checkElementIndex(attr, providers.length); return providers[attr].getNext(threshold); } static ThresholdProvider create(Iterable<? extends Iterable<Double>> thresholds); @Override List<DoubleSortedSet> getAll(); @Override OptionalDouble getNext(int attr, double threshold); }### Answer: @Test public void testGetNext() { List<DoubleSet> similarities = Arrays .asList(new DoubleOpenHashSet(Sets.newHashSet(Double.valueOf(0.7), Double.valueOf(0.6))), new DoubleOpenHashSet(Sets.newHashSet(Double.valueOf(0.8)))); ThresholdProvider provider = create(similarities); assertThat(provider.getNext(0, 0.5).boxed()).hasValue(Double.valueOf(0.6)); assertThat(provider.getNext(0, 0.6).boxed()).hasValue(Double.valueOf(0.7)); assertThat(provider.getNext(1, 0.8).boxed()).isEmpty(); }
### Question: SelfSchemaMapper implements SchemaMapper { @Override public Collection<ColumnPair<?>> create(Schema schema) { List<Column<?>> columns = schema.getColumns(); return columns.stream() .map(SelfSchemaMapper::toPair) .collect(Collectors.toList()); } @Override Collection<ColumnPair<?>> create(Schema schema); @Override Collection<ColumnPair<?>> create(Schema schema1, Schema schema2); }### Answer: @Test public void test() { SchemaMapper schemaMapper = new SelfSchemaMapper(); List<Column<?>> columns = Arrays.asList(A, B, C); Schema schema = Schema.of(columns); when(relation.getSchema()).thenReturn(schema); Collection<ColumnPair<?>> mapping = schemaMapper.create(relation); assertThat(mapping).hasSize(3); assertThat(mapping).contains(new ColumnPair<>(A, A)); assertThat(mapping).contains(new ColumnPair<>(B, B)); assertThat(mapping).contains(new ColumnPair<>(C, C)); }
### Question: FixedSchemaMapper implements SchemaMapper { @Override public Collection<ColumnPair<?>> create(Schema schema1, Schema schema2) { List<Column<?>> columns = schema1.getColumns(); return columns.stream() .flatMap(this::getMatching) .collect(Collectors.toList()); } @Override Collection<ColumnPair<?>> create(Schema schema1, Schema schema2); }### Answer: @Test public void test() { Multimap<Column<?>, Column<?>> map = ImmutableMultimap.<Column<?>, Column<?>>builder() .put(A, B) .put(A, C) .put(B, A) .build(); SchemaMapper schemaMapper = new FixedSchemaMapper(map); List<Column<?>> columns = Arrays.asList(A, B, C); Schema schema = Schema.of(columns); when(relation.getSchema()).thenReturn(schema); Collection<ColumnPair<?>> mapping = schemaMapper.create(relation); assertThat(mapping).hasSize(3); assertThat(mapping).contains(new ColumnPair<>(A, B)); assertThat(mapping).contains(new ColumnPair<>(A, C)); assertThat(mapping).contains(new ColumnPair<>(B, A)); }
### Question: TypeSchemaMapper implements SchemaMapper { private static Collection<ColumnPair<?>> create(Iterable<Column<?>> columns1, Iterable<Column<?>> columns2) { return StreamUtils.seq(columns1).crossJoin(columns2) .map(t -> t.map(SchemaMapperHelper::toPair)) .flatMap(Optionals::stream) .collect(Collectors.toList()); } @Override Collection<ColumnPair<?>> create(Schema schema); @Override Collection<ColumnPair<?>> create(Schema schema1, Schema schema2); }### Answer: @Test public void testSingleRelation() { SchemaMapper schemaMapper = new TypeSchemaMapper(); List<Column<?>> columns = Arrays.asList(A, B, C); Schema schema = Schema.of(columns); when(relation.getSchema()).thenReturn(schema); Collection<ColumnPair<?>> mapping = schemaMapper.create(relation); assertThat(mapping).hasSize(4); assertThat(mapping).contains(new ColumnPair<>(A, A)); assertThat(mapping).contains(new ColumnPair<>(B, B)); Assert.assertThat(mapping, either(hasItem(new ColumnPair<>(A, B))).or(hasItem(new ColumnPair<>(B, A)))); assertThat(mapping).contains(new ColumnPair<>(C, C)); } @Test public void testTwoRelations() { SchemaMapper schemaMapper = new TypeSchemaMapper(); List<Column<?>> columns = Arrays.asList(A, B, C); Schema schema = Schema.of(columns); when(relation.getSchema()).thenReturn(schema); Collection<ColumnPair<?>> mapping = schemaMapper.create(relation, relation); assertThat(mapping).hasSize(5); assertThat(mapping).contains(new ColumnPair<>(A, A)); assertThat(mapping).contains(new ColumnPair<>(B, B)); assertThat(mapping).contains(new ColumnPair<>(A, B)); assertThat(mapping).contains(new ColumnPair<>(B, A)); assertThat(mapping).contains(new ColumnPair<>(C, C)); }
### Question: JCommanderRunner { public void run(String... args) { boolean success = parse(args); if (!success || needsHelp()) { printUsage(); return; } app.run(); } static JCommanderRunnerBuilder create(Application app); void run(String... args); }### Answer: @Test public void testRunWithHelp() { TestApplication app = new TestApplication(); JCommanderRunner runner = createRunner(app); runner.run("--help"); assertThat(app.ran).isFalse(); } @Test public void testRunWithRequired() { TestApplication app = new TestApplication(); JCommanderRunner runner = createRunner(app); runner.run("-r"); assertThat(app.ran).isTrue(); } @Test public void testRunWithoutRequired() { TestApplication app = new TestApplication(); JCommanderRunner runner = createRunner(app); runner.run(); assertThat(app.ran).isFalse(); }
### Question: FDTree extends FDTreeElement { public void addFunctionalDependency(BitSet lhs, int a) { FDTreeElement fdTreeEl; FDTreeElement currentNode = this; currentNode.addRhsAttribute(a); for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { if (currentNode.children[i - 1] == null) { fdTreeEl = new FDTreeElement(maxAttributeNumber); currentNode.children[i - 1] = fdTreeEl; } currentNode = currentNode.getChild(i - 1); currentNode.addRhsAttribute(a); } currentNode.markAsLastVertex(a - 1); } FDTree(int maxAttributeNumber); void addMostGeneralDependencies(); void addFunctionalDependency(BitSet lhs, int a); boolean isEmpty(); void filterSpecializations(); void filterGeneralizations(); void printDependencies(); }### Answer: @Test public void testContainsSpezialization() { FDTree fdtree = new FDTree(5); BitSet lhs = new BitSet(); lhs.set(1); lhs.set(3); lhs.set(5); fdtree.addFunctionalDependency(lhs, 4); lhs.clear(1); lhs.set(2); fdtree.addFunctionalDependency(lhs, 4); lhs.clear(3); boolean result = fdtree.containsSpecialization(lhs, 4, 0); assertTrue(result); }
### Question: Fun implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> configurationSpecifications = new ArrayList<>(); configurationSpecifications.add(new ConfigurationRequirementRelationalInput(INPUT_FILE_TAG)); return configurationSpecifications; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { assertThat(algorithm.getConfigurationRequirements(), hasItem(isA(ConfigurationRequirementRelationalInput.class))); }
### Question: Fun implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values) { if (identifier.equals(INPUT_FILE_TAG)) { this.inputGenerator = values[0]; } } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetConfigurationValueStringRelationalInputGenerator() { RelationalInputGenerator expectedInputGenerator = mock(RelationalInputGenerator.class); algorithm.setRelationalInputConfigurationValue(Fun.INPUT_FILE_TAG, expectedInputGenerator); assertSame(expectedInputGenerator, algorithm.inputGenerator); }
### Question: Fun implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void execute() throws InputGenerationException, InputIterationException, CouldNotReceiveResultException, AlgorithmConfigurationException, ColumnNameMismatchException { RelationalInput input = inputGenerator.generateNewCopy(); PLIBuilder pliBuilder = new PLIBuilder(input); List<PositionListIndex> pliList = pliBuilder.getPLIList(); this.fun = new FunAlgorithm(input.relationName(), input.columnNames(), this.resultReceiver); this.fun.run(pliList); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() throws InputGenerationException, InputIterationException, CouldNotReceiveResultException, AlgorithmConfigurationException, ColumnNameMismatchException { AlgorithmTestFixture fixture = new AlgorithmTestFixture(); algorithm.setRelationalInputConfigurationValue(Fun.INPUT_FILE_TAG, fixture.getInputGenerator()); algorithm.setResultReceiver(fixture.getFunctionalDependencyResultReceiver()); algorithm.execute(); fixture.verifyFunctionalDependencyResultReceiver(); }
### Question: Fun implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver) { this.resultReceiver = resultReceiver; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetResultReceiverFunctionalDependencyResultReceiver() { FunctionalDependencyResultReceiver expectedResultReceiver = mock(FunctionalDependencyResultReceiver.class); algorithm.setResultReceiver(expectedResultReceiver); assertSame(expectedResultReceiver, algorithm.resultReceiver); }
### Question: MvDDetector extends MvDDetectorAlgorithm implements MultivaluedDependencyAlgorithm, // Defines the type of the algorithm, i.e., the result type, for instance, FunctionalDependencyAlgorithm or InclusionDependencyAlgorithm; implementing multiple types is possible RelationalInputParameterAlgorithm, // Defines the input type of the algorithm; relational input is any relational input from files or databases; more specific input specifications are possible BooleanParameterAlgorithm, IntegerParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.algorithmConfig = this.algorithmConfig; super.execute(); } @Override String getAuthors(); @Override String getDescription(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setIntegerConfigurationValue(String identifier, Integer... values); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void setResultReceiver(MultivaluedDependencyResultReceiver resultReceiver); @Override void execute(); }### Answer: @Test public void testExecute() { }
### Question: ResultTree { public boolean insert(Result result) { ResultTree parent = getInsertPosition(result); if (parent != null) { parent.getChildren().add(new ResultTree(result)); return true; } return false; } ResultTree(Result root); Result getNode(); void setNode(Result node); List<ResultTree> getChildren(); void setChildren(List<ResultTree> children); boolean insert(Result result); ResultTree getInsertPosition(Result result); boolean contains(BitSet lhs, int rhs); List<Result> getLeaves(); }### Answer: @Test public void testInsertNotPossibleForDifferentRhs() { Result node = mockResult(mockFD(new int[]{0, 4, 7, 9}, 3)); Result child = mockResult(mockFD(new int[]{4, 7, 9}, 3)); Result offendingResult = mockResult(mockFD(new int[] {4, 7}, 1)); ResultTree tree = new ResultTree(node); tree.insert(child); boolean inserted = tree.insert(offendingResult); Assert.assertFalse(inserted); } @Test public void testInsertNotPossibleForNonDescendants() { Result node = mockResult(mockFD(new int[]{0, 4, 7, 9}, 3)); Result child = mockResult(mockFD(new int[]{4, 7, 9}, 3)); Result offendingResult = mockResult(mockFD(new int[] {5, 7}, 3)); ResultTree tree = new ResultTree(node); tree.insert(child); boolean inserted = tree.insert(offendingResult); Assert.assertFalse(inserted); }
### Question: ResultLattice { public boolean insert(Result node) { if (valid(node)) { int l = node.getEmbeddedFD().lhs.cardinality(); if (! layers.containsKey(l)) { layers.put(l, new LinkedList<Result>()); } if (!layers.get(l).contains(node)) { layers.get(l).add(node); } return true; } return false; } ResultLattice(int rhs); ResultLattice(Result root); boolean insert(Result node); List<Result> getLayer(int i); int size(); boolean contains(BitSet lhs, int rhs); boolean contains(Result node); List<Result> getParents(Result child); List<Result> getChildren(Result node); List<Result> getLeaves(); }### Answer: @Test public void testInsertNotPossibleForDifferentRhs() { Result node = mockResult(mockFD(new int[]{0, 4, 7, 9}, 3)); Result child = mockResult(mockFD(new int[]{4, 7, 9}, 3)); Result offendingResult = mockResult(mockFD(new int[] {4, 7}, 1)); ResultLattice lattice = new ResultLattice(node); lattice.insert(child); boolean inserted = lattice.insert(offendingResult); Assert.assertFalse(inserted); }
### Question: LhsUtils { public static List<BitSet> generateLhsSubsets(BitSet lhs) { List<BitSet> results = new LinkedList<>(); for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { BitSet subset = (BitSet) lhs.clone(); subset.flip(i); if (subset.cardinality() > 0) { results.add(subset); } } return results; } static void addSubsetsTo(FDTreeElement.InternalFunctionalDependency fd, Collection<FDTreeElement.InternalFunctionalDependency> collection); static List<BitSet> generateLhsSubsets(BitSet lhs); static List<BitSet> generateLhsSupersets(BitSet lhs, int numAttributes); }### Answer: @Test public void testGenerateLhsSubsetsDoesNotReturnAnythingIfThereAreNoSubsets() { List<BitSet> results = LhsUtils.generateLhsSubsets(new BitSet(64)); Assert.assertEquals(0, results.size()); } @Test public void testGenerateLhsSubsetsDoesGenerateSetsWithOneLessAttribute() { BitSet parent = generateLhs(64, new int[] {1, 2, 3}); List<BitSet> results = LhsUtils.generateLhsSubsets(parent); Assert.assertEquals(3, results.size()); Assert.assertTrue(results.contains(generateLhs(64, new int[] {1, 2}))); Assert.assertTrue(results.contains(generateLhs(64, new int[] {2, 3}))); Assert.assertTrue(results.contains(generateLhs(64, new int[] {1, 3}))); }
### Question: DVSuperLogLog extends DVSuperLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVSuperLogLog.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVSuperLogLog.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVSuperLogLog extends DVSuperLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: DVHyperLogLog extends DVHyperLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVHyperLogLog.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVHyperLogLog.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVHyperLogLog extends DVHyperLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: PruningGraph { public boolean find(ColumnCombinationBitset columnCombination) { return findRecursively(columnCombination, new ColumnCombinationBitset(), 1); } PruningGraph(int numberOfColumns, int overflowTreshold, boolean positiveFeature); void add(ColumnCombinationBitset columnCombination); boolean find(ColumnCombinationBitset columnCombination); }### Answer: @Test public void testFind() { PruningGraph graph = fixture.getGraphWith1Element(); assertFalse(graph.find(fixture.columnCombinationAC)); assertTrue(graph.find(fixture.columnCombinationABC)); } @Test public void testFindWithOverflow() { PruningGraph graph = fixture.getGraphWith2ElementAndOverflow(); assertFalse(graph.find(fixture.columnCombinationAC)); assertTrue(graph.find(fixture.columnCombinationABC)); } @Test public void testFindWithOverflowNonUnique() { PruningGraph graph = fixture.getGraphWith2ElementAndOverflowNonUnique(); assertFalse(graph.find(fixture.columnCombinationAC)); assertTrue(graph.find(fixture.columnCombinationB)); assertTrue(graph.find(fixture.columnCombinationBC)); }
### Question: Ducc implements UniqueColumnCombinationsAlgorithm, RelationalInputParameterAlgorithm, BooleanParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> spec = new ArrayList<>(); ConfigurationRequirementRelationalInput input = new ConfigurationRequirementRelationalInput(INPUT_HANDLE); spec.add(input); ConfigurationRequirementBoolean nullEqualsNull = new ConfigurationRequirementBoolean(NULL_EQUALS_NULL); Boolean[] defaultNullEqualsNull = new Boolean[1]; defaultNullEqualsNull[0] = true; nullEqualsNull.setDefaultValues(defaultNullEqualsNull); nullEqualsNull.setRequired(true); spec.add(nullEqualsNull); return spec; } Ducc(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(UniqueColumnCombinationResultReceiver receiver); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { ConfigurationRequirementRelationalInput expectedSpecification1 = new ConfigurationRequirementRelationalInput(Ducc.INPUT_HANDLE); ConfigurationRequirementBoolean expectedSpecification2 = new ConfigurationRequirementBoolean(Ducc.NULL_EQUALS_NULL); List<ConfigurationRequirement<?>> spec = ducc.getConfigurationRequirements(); assertEquals(2, spec.size()); assertEquals(expectedSpecification1.getIdentifier(), spec.get(0).getIdentifier()); assertEquals(expectedSpecification2.getIdentifier(), spec.get(1).getIdentifier()); }
### Question: Ducc implements UniqueColumnCombinationsAlgorithm, RelationalInputParameterAlgorithm, BooleanParameterAlgorithm { @Override public void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values) throws AlgorithmConfigurationException { if (identifier.equals(INPUT_HANDLE)) { inputGenerator = values[0]; } else { throw new AlgorithmConfigurationException("Operation should not be called"); } } Ducc(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(UniqueColumnCombinationResultReceiver receiver); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetConfigurationValueStringSimpleRelationalInputGenerator() throws AlgorithmConfigurationException { RelationalInputGenerator expectedInputGenerator = mock(RelationalInputGenerator.class); ducc.setRelationalInputConfigurationValue(Ducc.INPUT_HANDLE, expectedInputGenerator); assertEquals(expectedInputGenerator, ducc.inputGenerator); } @Test public void testSetConfigurationValueStringSimpleRelationalInputGeneratorFail() throws AlgorithmConfigurationException { RelationalInputGenerator expectedInputGenerator = mock(RelationalInputGenerator.class); try { ducc.setRelationalInputConfigurationValue("wrong identifier", expectedInputGenerator); fail("UnsupportedOperationException was expected but was not thrown"); } catch (AlgorithmConfigurationException e) { } assertEquals(null, ducc.inputGenerator); }
### Question: Ducc implements UniqueColumnCombinationsAlgorithm, RelationalInputParameterAlgorithm, BooleanParameterAlgorithm { @Override public void setBooleanConfigurationValue(String identifier, Boolean... values) throws AlgorithmConfigurationException { if (identifier.equals(NULL_EQUALS_NULL)) { this.nullEqualsNull = values[0]; } else { throw new AlgorithmConfigurationException("Operation should not be called"); } } Ducc(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(UniqueColumnCombinationResultReceiver receiver); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetConfigurationValueNullEqualsNull() throws AlgorithmConfigurationException { boolean nullEqualsNull = false; ducc.setBooleanConfigurationValue(Ducc.NULL_EQUALS_NULL, nullEqualsNull); assertEquals(nullEqualsNull, ducc.nullEqualsNull); }
### Question: Ducc implements UniqueColumnCombinationsAlgorithm, RelationalInputParameterAlgorithm, BooleanParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { RelationalInput input; input = inputGenerator.generateNewCopy(); PLIBuilder pliBuilder = new PLIBuilder(input, this.nullEqualsNull); List<PositionListIndex> plis = pliBuilder.getPLIList(); DuccAlgorithm duccAlgorithm = new DuccAlgorithm(input.relationName(), input.columnNames(), this.resultReceiver); duccAlgorithm.run(plis); } Ducc(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(UniqueColumnCombinationResultReceiver receiver); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() throws AlgorithmExecutionException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { AlgorithmTestFixture fixture = new AlgorithmTestFixture(); ducc.setRelationalInputConfigurationValue(Ducc.INPUT_HANDLE, fixture.getInputGenerator()); ducc.setResultReceiver(fixture.getUniqueColumnCombinationResultReceiver()); Random random = mock(Random.class); when(random.nextDouble()).thenReturn(1d); ducc.random = random; ducc.execute(); fixture.verifyUniqueColumnCombinationResultReceiver(); }
### Question: Ducc implements UniqueColumnCombinationsAlgorithm, RelationalInputParameterAlgorithm, BooleanParameterAlgorithm { @Override public void setResultReceiver(UniqueColumnCombinationResultReceiver receiver) { this.resultReceiver = receiver; } Ducc(); @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setResultReceiver(UniqueColumnCombinationResultReceiver receiver); @Override void setBooleanConfigurationValue(String identifier, Boolean... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetResultReceiverUniqueColumnCombinationResultReceiver() { UniqueColumnCombinationResultReceiver expectedResultReceiver = mock(UniqueColumnCombinationResultReceiver.class); ducc.setResultReceiver(expectedResultReceiver); assertSame(expectedResultReceiver, ducc.resultReceiver); }
### Question: DVPCSA extends DVPCSAAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVPCSA.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVPCSA.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVPCSA extends DVPCSAAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: FdMine implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> configurationSpecifications = new ArrayList<>(); configurationSpecifications.add(new ConfigurationRequirementRelationalInput(INPUT_FILE_TAG)); return configurationSpecifications; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { assertThat(algorithm.getConfigurationRequirements(), hasItem(isA(ConfigurationRequirementRelationalInput.class))); }
### Question: FdMine implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values) { if (identifier.equals(INPUT_FILE_TAG)) { this.inputGenerator = values[0]; } } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetConfigurationValueStringRelationalInputGenerator() { RelationalInputGenerator expectedInputGenerator = mock(RelationalInputGenerator.class); algorithm.setRelationalInputConfigurationValue(FdMine.INPUT_FILE_TAG, expectedInputGenerator); assertSame(expectedInputGenerator, algorithm.inputGenerator); }
### Question: FdMine implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void execute() throws InputGenerationException, InputIterationException, CouldNotReceiveResultException, AlgorithmConfigurationException, ColumnNameMismatchException { RelationalInput input = inputGenerator.generateNewCopy(); relationName = input.relationName(); columnNames = input.columnNames(); PLIBuilder pliBuilder = new PLIBuilder(input); int columnIndex = 0; for (PositionListIndex pli : pliBuilder.getPLIList()) { plis.put(new ColumnCombinationBitset(columnIndex), pli); columnIndex++; } r = new ColumnCombinationBitset(); Set<ColumnCombinationBitset> candidateSet = new HashSet<>(); for (columnIndex = 0; columnIndex < input.numberOfColumns(); columnIndex++) { r.addColumn(columnIndex); candidateSet.add(new ColumnCombinationBitset(columnIndex)); } for (ColumnCombinationBitset xi : candidateSet) { closure.put(xi, new ColumnCombinationBitset()); } while (!candidateSet.isEmpty()) { for (ColumnCombinationBitset xi : candidateSet) { computeNonTrivialClosure(xi); obtainFdAndKey(xi); } obtainEqSet(candidateSet); pruneCandidates(candidateSet); generateCandidates(candidateSet); } displayFD(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() throws AlgorithmExecutionException { AlgorithmTestFixture fixture = new AlgorithmTestFixture(); algorithm.setRelationalInputConfigurationValue(FdMine.INPUT_FILE_TAG, fixture.getInputGenerator()); algorithm.setResultReceiver(fixture.getFunctionalDependencyResultReceiver()); algorithm.execute(); fixture.verifyFunctionalDependencyResultReceiverForFDMine(); }
### Question: FdMine implements FunctionalDependencyAlgorithm, RelationalInputParameterAlgorithm { @Override public void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver) { this.resultReceiver = resultReceiver; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void execute(); @Override void setResultReceiver(FunctionalDependencyResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testSetResultReceiver() { FunctionalDependencyResultReceiver expectedResultReceiver = mock(FunctionalDependencyResultReceiver.class); algorithm.setResultReceiver(expectedResultReceiver); assertSame(expectedResultReceiver, algorithm.resultReceiver); }
### Question: DVLogLog extends DVLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVLogLog.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVLogLog.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVLogLog extends DVLogLogAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: ParserHelper { public static boolean isDouble(String s) { return s != null && doublePattern.test(s); } static boolean isDouble(String s); static boolean isInteger(String s); static boolean isInteger(String s, int radix); }### Answer: @Test public void testIsDouble() { assertTrue(ParserHelper.isDouble("1.0")); assertFalse(ParserHelper.isDouble("Z2")); }
### Question: Column { @Override public String toString() { return tableName + "." + name; } Column(String tableName, String name); Type getType(); String getName(); @Override String toString(); void addLine(String string); Comparable<?> getValue(int line); Long getLong(int line); Double getDouble(int line); String getString(int line); }### Answer: @Test public void testToString() { Column c = new Column("relation", "test"); Assert.assertEquals("relation.test", c.toString()); }
### Question: DVAKMV extends DVAKMVAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVAKMV.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVAKMV.Identifier.RELATIVE_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVAKMV extends DVAKMVAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: DVMinCount extends DVMinCountAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVMinCount.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVMinCount.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVMinCount extends DVMinCountAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: DVFM extends DVFMAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements() { ArrayList<ConfigurationRequirement<?>> conf = new ArrayList<>(); conf.add(new ConfigurationRequirementRelationalInput(DVFM.Identifier.INPUT_GENERATOR.name())); ConfigurationRequirementString inputstandard_error=new ConfigurationRequirementString(DVFM.Identifier.STANDARD_ERROR.name()); inputstandard_error.setRequired(false); String[] Defaults={"0.01"}; inputstandard_error.setDefaultValues(Defaults); conf.add(inputstandard_error); return conf; } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testGetConfigurationRequirements() { }
### Question: DVFM extends DVFMAlgorithm implements BasicStatisticsAlgorithm, RelationalInputParameterAlgorithm, StringParameterAlgorithm { @Override public void execute() throws AlgorithmExecutionException { super.execute(); } @Override ArrayList<ConfigurationRequirement<?>> getConfigurationRequirements(); @Override void setResultReceiver(BasicStatisticsResultReceiver resultReceiver); @Override void setRelationalInputConfigurationValue(String identifier, RelationalInputGenerator... values); @Override void execute(); @Override void setStringConfigurationValue(String identifier, String... values); @Override String getAuthors(); @Override String getDescription(); }### Answer: @Test public void testExecute() { }
### Question: DefaultSimilarityClassifier implements SimilarityClassifier<T> { @Override public boolean areSimilar(T obj1, T obj2) { return calculateSimilarity(obj1, obj2) >= threshold; } @Override boolean areSimilar(T obj1, T obj2); @Override SimilarityClassifier<T> asClassifier(double newThreshold); @Override String toString(); }### Answer: @Test public void test() { assertThat(getClassifier(0.6).areSimilar("foo", "bar")).isFalse(); assertThat(getClassifier(0.5).areSimilar("foo", "bar")).isTrue(); assertThat(getClassifier(0.4).areSimilar("foo", "bar")).isTrue(); }
### Question: StringUtils { public static String toLowerCase(String s) { return Optional.ofNullable(s) .map(String::toLowerCase) .orElse(null); } static String toLowerCase(String s); static String join(CharSequence delimiter, Iterable<?> elements); }### Answer: @Test public void testToLowerCase() { assertThat(StringUtils.toLowerCase("foO")).isEqualTo("foo"); assertThat(StringUtils.toLowerCase(null)).isNull(); }
### Question: OptionalDouble { public Optional<Double> boxed() { return map(d -> Double.valueOf(d)); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testBoxed() { assertThat(OptionalDouble.empty().boxed()).isEmpty(); assertThat(OptionalDouble.of(1.0).boxed()).hasValue(1.0); }
### Question: OptionalDouble { public static OptionalDouble empty() { return EMPTY; } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testEmpty() { assertThat(OptionalDouble.empty().boxed()).isEmpty(); }
### Question: OptionalDouble { public OptionalDouble filter(@NonNull DoublePredicate predicate) { if (!optional.isPresent()) { return this; } return predicate.test(optional.getAsDouble()) ? this : empty(); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testFilter() { assertThat(OptionalDouble.empty().filter(d -> d > 2.0).isPresent()).isFalse(); assertThat(OptionalDouble.of(2.0).filter(d -> d > 2.0).isPresent()).isFalse(); assertThat(OptionalDouble.of(3.0).filter(d -> d > 2.0).isPresent()).isTrue(); }
### Question: OptionalDouble { public void ifPresent(DoubleConsumer consumer) { optional.ifPresent(consumer); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testIfPresent() { DoubleCollection collection = new DoubleArrayList(); OptionalDouble.of(2.0).ifPresent(collection::add); assertThat(collection).hasSize(1); assertThat(collection).contains(2.0); }
### Question: OptionalDouble { public boolean isPresent() { return optional.isPresent(); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testIsPresent() { assertThat(OptionalDouble.empty().isPresent()).isFalse(); assertThat(OptionalDouble.of(1.0).isPresent()).isTrue(); }
### Question: OptionalDouble { public <T> Optional<T> map(@NonNull DoubleFunction<T> mapper) { return optional.isPresent() ? Optional.ofNullable(mapper.apply(optional.getAsDouble())) : Optional.empty(); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testMap() { assertThat(OptionalDouble.empty().map(d -> 1)).isEmpty(); assertThat(OptionalDouble.of(2.0).map(d -> 1)).hasValue(1); }
### Question: OptionalDouble { public static OptionalDouble of(double value) { return new OptionalDouble(value); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testOf() { assertThat(OptionalDouble.of(2.0).boxed()).hasValue(2.0); }
### Question: OptionalDouble { public static OptionalDouble ofNullable(Double value) { return value == null ? empty() : of(value.doubleValue()); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testOfNullable() { assertThat(OptionalDouble.ofNullable(null).boxed()).isEmpty(); assertThat(OptionalDouble.ofNullable(1.0).boxed()).hasValue(1.0); }
### Question: OptionalDouble { public double orElse(double other) { return optional.orElse(other); } private OptionalDouble(); private OptionalDouble(double value); static OptionalDouble empty(); static OptionalDouble of(double value); static OptionalDouble ofNullable(Double value); Optional<Double> boxed(); OptionalDouble filter(@NonNull DoublePredicate predicate); double getAsDouble(); void ifPresent(DoubleConsumer consumer); boolean isPresent(); Optional<T> map(@NonNull DoubleFunction<T> mapper); double orElse(double other); }### Answer: @Test public void testOrElse() { assertThat(OptionalDouble.empty().orElse(2.0)).isEqualTo(2.0); assertThat(OptionalDouble.of(1.0).orElse(2.0)).isEqualTo(1.0); }
### Question: ReflectionUtils { @SuppressWarnings("unchecked") public static <T> Optional<T> get(Field field, Object obj) { try { T value = (T) field.get(obj); return Optional.ofNullable(value); } catch (Exception e) { return Optional.empty(); } } static MakeAccessible<A> accessible(A accessibleObject); @SuppressWarnings("unchecked") static Optional<T> get(Field field, Object obj); static Optional<T> getAnnotationIfPresent( AnnotatedElement annotatedElement, Class<T> annotationClass); static Optional<T> getDefaultValue(Class<? extends Annotation> annotation, String property); static boolean isBooleanField(Field field); }### Answer: @Test public void testGet() throws NoSuchFieldException { HelperClass obj = new HelperClass(); Field field = HelperClass.class.getDeclaredField(ACCESSIBLE); boolean accessible = true; obj.setAccessible(accessible); assertThat(obj.getAccessible()).isEqualTo(accessible); assertThat(ReflectionUtils.get(field, obj)).hasValue(accessible); } @Test public void testGetInaccessible() throws NoSuchFieldException { HelperClass obj = new HelperClass(); Field field = HelperClass.class.getDeclaredField(INACCESSIBLE); boolean inaccessible = true; obj.setInaccessible(inaccessible); assertThat(obj.getInaccessible()).isEqualTo(inaccessible); assertThat(ReflectionUtils.get(field, obj)).isEmpty(); }