use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllSketchAggregatorTest method testAggregate.
@Test
public void testAggregate() {
final HllSketchAggregator sketchAggregator = new HllSketchAggregator();
HllSketch currentSketch = new HllSketch(10);
currentSketch.update("A");
currentSketch.update("B");
assertEquals(2.0D, currentSketch.getEstimate(), DELTA);
HllSketch newSketch = new HllSketch(10);
newSketch.update("C");
newSketch.update("D");
currentSketch = sketchAggregator.apply(currentSketch, newSketch);
assertEquals(4.0D, currentSketch.getEstimate(), DELTA);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class IterableToHllSketchTest method shouldCreateEmptyWhenNull.
@Test
public void shouldCreateEmptyWhenNull() {
// Given
IterableToHllSketch iterableToHllSketch = new IterableToHllSketch();
// When
HllSketch result = iterableToHllSketch.apply(null);
// Then
assertThat(result.getEstimate()).isEqualTo(0);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllpSketchJsonSerialisationTest method shouldDeserialiseNewHllpWithValues.
@Test
public void shouldDeserialiseNewHllpWithValues() throws IOException {
// Given
final String sketchAsString = "{\"logK\": 20, \"values\": [\"value1\", \"value2\", \"value2\", \"value2\", \"value3\"]}";
// When
HllSketch hllp = JSONSerialiser.deserialise(sketchAsString, HllSketch.class);
// Then
HllSketch expected = new HllSketch(20);
expected.update("value1");
expected.update("value2");
expected.update("value2");
expected.update("value2");
expected.update("value3");
assertArrayEquals(expected.toCompactByteArray(), hllp.toCompactByteArray());
}
Aggregations