use of com.yahoo.sketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class VarOptItemsUnionTest method unionEmptySketch.
@Test
public void unionEmptySketch() {
final int k = 2048;
final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
// we'll union from Memory for good measure
final byte[] sketchBytes = VarOptItemsSketch.<String>newInstance(k).toByteArray(serDe);
final Memory mem = Memory.wrap(sketchBytes);
final VarOptItemsUnion<String> union = VarOptItemsUnion.newInstance(k);
union.update(mem, serDe);
final VarOptItemsSketch<String> result = union.getResult();
assertEquals(result.getN(), 0);
assertEquals(result.getHRegionCount(), 0);
assertEquals(result.getRRegionCount(), 0);
assertTrue(Double.isNaN(result.getTau()));
}
use of com.yahoo.sketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class VarOptItemsSketchTest method checkEmptySketch.
@Test
public void checkEmptySketch() {
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(5);
assertEquals(vis.getN(), 0);
assertEquals(vis.getNumSamples(), 0);
assertNull(vis.getSamplesAsArrays());
assertNull(vis.getSamplesAsArrays(Long.class));
final byte[] sketchBytes = vis.toByteArray(new ArrayOfStringsSerDe());
final Memory mem = Memory.wrap(sketchBytes);
// only minPreLongs bytes and should deserialize to empty
assert sketchBytes != null;
assertEquals(sketchBytes.length, Family.VAROPT.getMinPreLongs() << 3);
final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
final VarOptItemsSketch<String> loadedVis = VarOptItemsSketch.heapify(mem, serDe);
assertEquals(loadedVis.getNumSamples(), 0);
println("Empty sketch:");
println(" Preamble:");
println(PreambleUtil.preambleToString(mem));
println(" Sketch:");
println(vis.toString());
}
use of com.yahoo.sketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class VarOptItemsSketchTest method checkNonEmptyDegenerateSketch.
@Test
public void checkNonEmptyDegenerateSketch() {
// make an empty serialized sketch, then copy the items into a
// PreambleUtil.VO_WARMUP_PRELONGS-sized byte array
// so there'll be no items, then clear the empty flag so it will try to load
// the rest.
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(12, ResizeFactor.X2);
final byte[] sketchBytes = vis.toByteArray(new ArrayOfStringsSerDe());
final byte[] dstByteArr = new byte[PreambleUtil.VO_WARMUP_PRELONGS << 3];
final WritableMemory mem = WritableMemory.wrap(dstByteArr);
mem.putByteArray(0, sketchBytes, 0, sketchBytes.length);
// ensure non-empty but with H and R region sizes set to 0
// may be null
final Object memObj = mem.getArray();
final long memAddr = mem.getCumulativeOffset(0L);
// set not-empty
PreambleUtil.insertFlags(memObj, memAddr, 0);
PreambleUtil.insertHRegionItemCount(memObj, memAddr, 0);
PreambleUtil.insertRRegionItemCount(memObj, memAddr, 0);
final VarOptItemsSketch<String> rebuilt = VarOptItemsSketch.heapify(mem, new ArrayOfStringsSerDe());
assertNotNull(rebuilt);
assertEquals(rebuilt.getNumSamples(), 0);
}
use of com.yahoo.sketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method checkGetInstanceExcep1.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkGetInstanceExcep1() {
Memory mem = Memory.wrap(new byte[4]);
ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
use of com.yahoo.sketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method checkGetInstanceExcep2.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkGetInstanceExcep2() {
Memory mem = Memory.wrap(new byte[8]);
ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
Aggregations