use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllSketchEntityGeneratorTest method shouldCreateSimpleEntitiesWithProperties.
@Test
public void shouldCreateSimpleEntitiesWithProperties() {
// Given
HllSketchEntityGenerator hllSketchEntityGenerator = new HllSketchEntityGenerator();
hllSketchEntityGenerator.propertyToCopy(PROP1);
Edge edge = new Edge.Builder().group(TestGroups.ENTITY).source(A).dest(B).property(PROP1, VALUE1).build();
List<? extends Element> edges = Arrays.asList(edge);
// When
Iterable<? extends Element> elements = hllSketchEntityGenerator.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);
HllSketch entityCardinalityA = (HllSketch) entityResultA.getProperty(DEFAULT_PROPERTY_NAME);
assertThat(entityCardinalityA.getEstimate()).isEqualTo(1);
assertThat(entityResultA.getProperty(PROP1)).isEqualTo(VALUE1);
assertThat(entityResultB.getGroup()).isEqualTo(DEFAULT_ENTITY_GROUP);
assertThat(entityResultB.getVertex()).isEqualTo(B);
HllSketch entityCardinalityB = (HllSketch) entityResultB.getProperty(DEFAULT_PROPERTY_NAME);
assertThat(entityCardinalityB.getEstimate()).isEqualTo(1);
assertThat(entityResultB.getProperty(PROP1)).isEqualTo(VALUE1);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class ToHllSketchTest method shouldCreateEmptyWhenNull.
@Test
public void shouldCreateEmptyWhenNull() {
// Given
ToHllSketch toHllSketch = new ToHllSketch();
// When
HllSketch result = toHllSketch.apply(null);
// Then
assertThat(result.getEstimate()).isEqualTo(0);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllSketchSerialiserTest method testSerialiser.
private void testSerialiser(final HllSketch sketch) {
final double cardinality = sketch.getEstimate();
final byte[] sketchSerialised;
try {
sketchSerialised = SERIALISER.serialise(sketch);
} catch (final SerialisationException exception) {
fail("A SerialisationException occurred");
return;
}
final HllSketch sketchDeserialised;
try {
sketchDeserialised = SERIALISER.deserialise(sketchSerialised);
} catch (final SerialisationException exception) {
fail("A SerialisationException occurred");
return;
}
assertEquals(cardinality, sketchDeserialised.getEstimate(), DELTA);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllpSketchJsonSerialisationTest method testNullHyperLogLogPlusSketchIsSerialisedAsNullString.
@Test
public void testNullHyperLogLogPlusSketchIsSerialisedAsNullString() throws SerialisationException {
// Given
final HllSketch sketch = null;
// When
final String sketchAsString = new String(JSONSerialiser.serialise(sketch));
// Then - Serialisation framework will serialise nulls as 'null' string.
assertEquals("null", sketchAsString);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllpSketchJsonSerialisationTest method shouldDeserialiseNewHllpWithSAndSpValues.
@Test
public void shouldDeserialiseNewHllpWithSAndSpValues() throws IOException {
// Given
final String sketchAsString = "{\"logK\": 20}";
// When
HllSketch hllp = JSONSerialiser.deserialise(sketchAsString, HllSketch.class);
// Then
assertArrayEquals(new HllSketch(20).toCompactByteArray(), hllp.toCompactByteArray());
}
Aggregations