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 = new String(JSONSerialiser.serialise(sketch));
// Then - serialise
JsonAssert.assertEquals("" + "{\"hyperLogLogPlus\":" + "{\"hyperLogLogPlusSketchBytes\":" + new String(JSONSerialiser.serialise(sketch.getBytes())) + "," + "\"cardinality\":" + sketch.cardinality() + "}}", json);
// When - deserialise
final HyperLogLogPlus deserialisedSketch = JSONSerialiser.deserialise(json, HyperLogLogPlus.class);
// Then - deserialise
assertNotNull(deserialisedSketch);
assertEquals(sketch.cardinality(), deserialisedSketch.cardinality());
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testValidHyperLogLogPlusSketchSerialisedCorrectly.
@Test
public void testValidHyperLogLogPlusSketchSerialisedCorrectly() throws IOException {
// Given
final String testString = "TestString";
final HyperLogLogPlus sketch = new HyperLogLogPlus(5, 5);
sketch.offer(testString);
// When / Then
runTestWithSketch(sketch);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testNullHyperLogLogSketchDeserialisedAsEmptySketch.
@Test
public void testNullHyperLogLogSketchDeserialisedAsEmptySketch() throws IOException {
// Given
final String sketchAsString = "{}";
// When
HyperLogLogPlus hllp = JSONSerialiser.deserialise(sketchAsString, HyperLogLogPlus.class);
// Then
assertEquals(0, hllp.cardinality());
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testEmptyHyperLogLogPlusSketchIsSerialised.
@Test
public void testEmptyHyperLogLogPlusSketchIsSerialised() throws IOException {
// Given
final HyperLogLogPlus sketch = new HyperLogLogPlus(5, 5);
// When / Then
runTestWithSketch(sketch);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method shouldDeserialiseNewHllpWithSAndSpValues.
@Test
public void shouldDeserialiseNewHllpWithSAndSpValues() throws IOException {
// Given
final String sketchAsString = "{\"p\": 5, \"sp\": 10}";
// When
HyperLogLogPlus hllp = JSONSerialiser.deserialise(sketchAsString, HyperLogLogPlus.class);
// Then
assertArrayEquals(new HyperLogLogPlus(5, 10).getBytes(), hllp.getBytes());
}
Aggregations