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 = serialiser.serialise(hyperLogLogPlus);
} catch (final SerialisationException exception) {
fail("A Serialisation Exception Occurred");
return;
}
HyperLogLogPlus hyperLogLogPlusDeserialised;
try {
hyperLogLogPlusDeserialised = serialiser.deserialise(hyperLogLogPlusSerialised);
} catch (final 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 HyperLogLogPlusSerialiserTest method testDeserialiseEmptyBytesReturnsNull.
@Test
public void testDeserialiseEmptyBytesReturnsNull() throws SerialisationException {
// Given
final HyperLogLogPlus hllp = serialiser.deserialiseEmpty();
// Then
assertNull(hllp);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusEntityGeneratorTest method shouldCreateSimpleEntities.
@Test
public void shouldCreateSimpleEntities() {
// Given
HyperLogLogPlusEntityGenerator hyperLogLogPlusEntityGenerator = new HyperLogLogPlusEntityGenerator();
Edge edge = new Edge.Builder().group(TestGroups.ENTITY).source(A).dest(B).build();
List<? extends Element> edges = Arrays.asList(edge);
// When
Iterable<? extends Element> elements = hyperLogLogPlusEntityGenerator.apply(edges);
// Then
Iterator<? extends Element> elementIterator = elements.iterator();
Edge edgeResult = (Edge) elementIterator.next();
Entity entityResultA = (Entity) elementIterator.next();
Entity entityResultB = (Entity) elementIterator.next();
assertThat(elementIterator.hasNext()).isFalse();
assertThat(edgeResult).isEqualTo(edge);
assertThat(entityResultA.getGroup()).isEqualTo(DEFAULT_ENTITY_GROUP);
assertThat(entityResultA.getVertex()).isEqualTo(A);
HyperLogLogPlus entityCardinalityA = (HyperLogLogPlus) entityResultA.getProperty(DEFAULT_PROPERTY_NAME);
assertThat(entityCardinalityA.cardinality()).isEqualTo(1);
assertThat(entityResultB.getGroup()).isEqualTo(DEFAULT_ENTITY_GROUP);
assertThat(entityResultB.getVertex()).isEqualTo(B);
HyperLogLogPlus entityCardinalityB = (HyperLogLogPlus) entityResultB.getProperty(DEFAULT_PROPERTY_NAME);
assertThat(entityCardinalityB.cardinality()).isEqualTo(1);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class ToHyperLogLogPlusTest method shouldCreateHyperLogLogPlus.
@Test
public void shouldCreateHyperLogLogPlus() {
// Given
ToHyperLogLogPlus toHyperLogLogPlus = new ToHyperLogLogPlus();
// When
HyperLogLogPlus result = toHyperLogLogPlus.apply("input");
// Then
assertThat(result.cardinality()).isEqualTo(1);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testNullHyperLogLogPlusSketchIsSerialisedAsNullString.
@Test
public void testNullHyperLogLogPlusSketchIsSerialisedAsNullString() throws SerialisationException {
// Given
final HyperLogLogPlus sketch = null;
// When
final String sketchAsString = new String(JSONSerialiser.serialise(sketch));
// Then - Serialisation framework will serialise nulls as 'null' string.
assertEquals("null", sketchAsString);
}
Aggregations