use of org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer 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.DoubleSummaryDeserializer 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.DoubleSummaryDeserializer in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method serialVersion1Compatibility.
@Test
public void serialVersion1Compatibility() throws Exception {
byte[] bytes = getResourceBytes("CompactSketchWithDoubleSummary4K_serialVersion1.sk");
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
Assert.assertTrue(sketch.isEstimationMode());
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.99);
Assert.assertEquals(sketch.getRetainedEntries(), 4096);
int count = 0;
SketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 1.0);
count++;
}
Assert.assertEquals(count, 4096);
}
use of org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer 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);
}
Aggregations