use of org.apache.datasketches.tuple.adouble.DoubleSummaryFactory in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method serializeDeserializeSmallExact.
@Test
public void serializeDeserializeSmallExact() {
UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
us.update("a", 1.0);
us.update("b", 1.0);
us.update("c", 1.0);
CompactSketch<DoubleSummary> sketch1 = us.compact();
Sketch<DoubleSummary> sketch2 = Sketches.heapifySketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer());
Assert.assertFalse(sketch2.isEmpty());
Assert.assertFalse(sketch2.isEstimationMode());
Assert.assertEquals(sketch2.getEstimate(), 3.0);
Assert.assertEquals(sketch2.getLowerBound(1), 3.0);
Assert.assertEquals(sketch2.getUpperBound(1), 3.0);
Assert.assertEquals(sketch2.getRetainedEntries(), 3);
Assert.assertEquals(sketch2.getThetaLong(), Long.MAX_VALUE);
Assert.assertEquals(sketch2.getTheta(), 1.0);
SketchIterator<DoubleSummary> it = sketch2.iterator();
int count = 0;
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 1.0);
count++;
}
Assert.assertEquals(count, 3);
}
use of org.apache.datasketches.tuple.adouble.DoubleSummaryFactory in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method deserializeWrongType.
@SuppressWarnings("deprecation")
@Test(expectedExceptions = SketchesArgumentException.class)
public void deserializeWrongType() {
UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
for (int i = 0; i < 8192; i++) {
us.update(i, 1.0);
}
CompactSketch<DoubleSummary> sketch1 = us.compact();
Sketches.heapifyUpdatableSketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer(), new DoubleSummaryFactory(mode));
}
use of org.apache.datasketches.tuple.adouble.DoubleSummaryFactory in project sketches-core by DataSketches.
the class MiscTest method checkUpdatableSketchBuilderReset.
@Test
public void checkUpdatableSketchBuilderReset() {
final DoubleSummary.Mode mode = Mode.Sum;
final UpdatableSketchBuilder<Double, DoubleSummary> bldr = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode));
bldr.reset();
final UpdatableSketch<Double, DoubleSummary> sk = bldr.build();
assertTrue(sk.isEmpty());
}
use of org.apache.datasketches.tuple.adouble.DoubleSummaryFactory in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method serializeDeserializeEstimation.
@Test
public void serializeDeserializeEstimation() throws Exception {
UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
for (int i = 0; i < 8192; i++) {
us.update(i, 1.0);
}
us.trim();
CompactSketch<DoubleSummary> sketch1 = us.compact();
byte[] bytes = sketch1.toByteArray();
// for binary testing
// TestUtil.writeBytesToFile(bytes, "CompactSketchWithDoubleSummary4K.sk");
Sketch<DoubleSummary> sketch2 = Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
Assert.assertFalse(sketch2.isEmpty());
Assert.assertTrue(sketch2.isEstimationMode());
Assert.assertEquals(sketch2.getEstimate(), sketch1.getEstimate());
Assert.assertEquals(sketch2.getThetaLong(), sketch1.getThetaLong());
SketchIterator<DoubleSummary> it = sketch2.iterator();
int count = 0;
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 1.0);
count++;
}
Assert.assertEquals(count, 4096);
}
use of org.apache.datasketches.tuple.adouble.DoubleSummaryFactory in project sketches-core by DataSketches.
the class MiscTest method checkCopyCtor.
@Test
public void checkCopyCtor() {
final DoubleSummary.Mode mode = Mode.Sum;
final UpdatableSketchBuilder<Double, DoubleSummary> bldr = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode));
bldr.reset();
final UpdatableSketch<Double, DoubleSummary> sk = bldr.build();
sk.update(1.0, 1.0);
assertEquals(sk.getRetainedEntries(), 1);
final UpdatableSketch<Double, DoubleSummary> sk2 = sk.copy();
assertEquals(sk2.getRetainedEntries(), 1);
}
Aggregations