Search in sources :

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

Example 52 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 = serialiser.deserialiseEmpty();
    // Then
    assertNull(hllp);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 53 with HyperLogLogPlus

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 54 with HyperLogLogPlus

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

Example 55 with HyperLogLogPlus

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

Aggregations

HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)63 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 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 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)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 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 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)2