use of org.apache.datasketches.tuple.Union in project sketches-core by DataSketches.
the class AdoubleUnionTest method checkUnionUpdateWithTheta.
@Test
public void checkUnionUpdateWithTheta() {
final Union<DoubleSummary> union = new Union<>(new DoubleSummarySetOperations(mode, mode));
UpdateSketch usk = null;
DoubleSummary dsum = null;
try {
union.union(usk, dsum);
fail();
} catch (final SketchesArgumentException e) {
}
usk = new UpdateSketchBuilder().build();
try {
union.union(usk, dsum);
fail();
} catch (final SketchesArgumentException e) {
}
dsum = new DoubleSummaryFactory(mode).newSummary();
for (int i = 0; i < 10; i++) {
usk.update(i);
}
union.union(usk, dsum);
Assert.assertEquals(union.getResult().getEstimate(), 10.0);
}
use of org.apache.datasketches.tuple.Union in project sketches-core by DataSketches.
the class ArrayOfStringsSketchTest method checkSketch.
@SuppressWarnings("deprecation")
@Test
public void checkSketch() {
ArrayOfStringsSketch sketch1 = new ArrayOfStringsSketch();
String[][] strArrArr = { { "a", "b" }, { "c", "d" }, { "e", "f" } };
int len = strArrArr.length;
for (int i = 0; i < len; i++) {
sketch1.update(strArrArr[i], strArrArr[i]);
}
// insert duplicate
sketch1.update(strArrArr[0], strArrArr[0]);
// printSummaries(sketch1.iterator());
byte[] array = sketch1.toByteArray();
WritableMemory wmem = WritableMemory.writableWrap(array);
ArrayOfStringsSketch sketch2 = new ArrayOfStringsSketch(wmem);
// printSummaries(sketch2.iterator());
checkSummaries(sketch2, sketch2);
String[] strArr3 = { "g", "h" };
sketch2.update(strArr3, strArr3);
Union<ArrayOfStringsSummary> union = new Union<>(new ArrayOfStringsSummarySetOperations());
union.union(sketch1);
union.union(sketch2);
CompactSketch<ArrayOfStringsSummary> csk = union.getResult();
// printSummaries(csk.iterator());
assertEquals(csk.getRetainedEntries(), 4);
Intersection<ArrayOfStringsSummary> inter = new Intersection<>(new ArrayOfStringsSummarySetOperations());
inter.intersect(sketch1);
inter.intersect(sketch2);
csk = inter.getResult();
assertEquals(csk.getRetainedEntries(), 3);
AnotB<ArrayOfStringsSummary> aNotB = new AnotB<>();
aNotB.setA(sketch2);
aNotB.notB(sketch1);
csk = aNotB.getResult(true);
assertEquals(csk.getRetainedEntries(), 1);
}
Aggregations