Search in sources :

Example 16 with HyperLogLogPlus

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());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)

Example 17 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 18 with HyperLogLogPlus

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());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 19 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 20 with HyperLogLogPlus

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());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Aggregations

HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)58 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)6 User (uk.gov.gchq.gaffer.user.User)6 Edge (uk.gov.gchq.gaffer.data.element.Edge)5 Element (uk.gov.gchq.gaffer.data.element.Element)5 Graph (uk.gov.gchq.gaffer.graph.Graph)5 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)5 ArrayList (java.util.ArrayList)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 HashSet (java.util.HashSet)3 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)3 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)3 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)3 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)3 CardinalityMergeException (com.clearspring.analytics.stream.cardinality.CardinalityMergeException)2 TreeNode (com.fasterxml.jackson.core.TreeNode)2