Search in sources :

Example 31 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 32 with HyperLogLogPlus

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

Example 33 with HyperLogLogPlus

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

Example 34 with HyperLogLogPlus

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());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Test(org.junit.Test)

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

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