use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusAggregatorTest method shouldBeEqualWhenBothAggregatorsHaveSameSketches.
@Test
public void shouldBeEqualWhenBothAggregatorsHaveSameSketches() throws IOException {
// Given
final HyperLogLogPlusAggregator aggregator1 = new HyperLogLogPlusAggregator();
final HyperLogLogPlusAggregator aggregator2 = new HyperLogLogPlusAggregator();
final HyperLogLogPlus hllp1 = new HyperLogLogPlus(5, 5);
hllp1.offer("A");
hllp1.offer("B");
final HyperLogLogPlus hllp2 = new HyperLogLogPlus(5, 5);
hllp2.offer("A");
hllp2.offer("B");
aggregator1._aggregate(hllp1);
aggregator2._aggregate(hllp2);
// Then
assertEquals(aggregator1, aggregator2);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusIsLessThanTest method setup.
@Before
public void setup() {
hyperLogLogPlusWithCardinality5 = new HyperLogLogPlus(5, 5);
for (int i = 1; i <= 5; i++) {
hyperLogLogPlusWithCardinality5.offer(i);
}
assertEquals(5l, hyperLogLogPlusWithCardinality5.cardinality());
hyperLogLogPlusWithCardinality15 = new HyperLogLogPlus(5, 5);
for (int i = 1; i <= 18; i++) {
hyperLogLogPlusWithCardinality15.offer(i);
}
assertEquals(15l, hyperLogLogPlusWithCardinality15.cardinality());
hyperLogLogPlusWithCardinality31 = new HyperLogLogPlus(5, 5);
for (int i = 1; i <= 32; i++) {
hyperLogLogPlusWithCardinality31.offer(i);
}
assertEquals(31l, hyperLogLogPlusWithCardinality31.cardinality());
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusSerialiserTest method testDeserialiseEmptyBytesReturnsNull.
@Test
public void testDeserialiseEmptyBytesReturnsNull() throws SerialisationException {
// Given
final HyperLogLogPlus hllp = HYPER_LOG_LOG_PLUS_SERIALISER.deserialiseEmptyBytes();
// Then
assertNull(hllp);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusSerialiserTest method testSerialiseAndDeserialiseWhenEmpty.
@Test
public void testSerialiseAndDeserialiseWhenEmpty() {
HyperLogLogPlus hyperLogLogPlus = new HyperLogLogPlus(5, 5);
long preSerialisationCardinality = hyperLogLogPlus.cardinality();
byte[] hyperLogLogPlusSerialised;
try {
hyperLogLogPlusSerialised = HYPER_LOG_LOG_PLUS_SERIALISER.serialise(hyperLogLogPlus);
} catch (SerialisationException exception) {
fail("A Serialisation Exception Occurred");
return;
}
HyperLogLogPlus hyperLogLogPlusDeserialised;
try {
hyperLogLogPlusDeserialised = HYPER_LOG_LOG_PLUS_SERIALISER.deserialise(hyperLogLogPlusSerialised);
} catch (SerialisationException exception) {
fail("A Serialisation Exception Occurred");
return;
}
assertEquals(preSerialisationCardinality, hyperLogLogPlusDeserialised.cardinality());
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method runTestWithSketch.
private void runTestWithSketch(final HyperLogLogPlus sketch) throws IOException {
// When - serialise
final String json = mapper.writeValueAsString(sketch);
// Then - serialise
final String[] parts = json.split("[:,]");
final String[] expectedParts = { "{\"hyperLogLogPlus\"", "{\"hyperLogLogPlusSketchBytes\"", "BYTES", "\"cardinality\"", sketch.cardinality() + "}}" };
for (int i = 0; i < parts.length; i++) {
if (2 != i) {
// skip checking the bytes
assertEquals(expectedParts[i], parts[i]);
}
}
// When - deserialise
final HyperLogLogPlus deserialisedSketch = mapper.readValue(IOUtils.toInputStream(json), HyperLogLogPlus.class);
// Then - deserialise
assertNotNull(deserialisedSketch);
assertEquals(sketch.cardinality(), deserialisedSketch.cardinality());
}
Aggregations