Search in sources :

Example 56 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusJsonSerialisationTest method shouldDeserialiseNewHllpWithOffers.

@Test
public void shouldDeserialiseNewHllpWithOffers() throws IOException {
    // Given
    final String sketchAsString = "{\"p\": 5, \"sp\": 5, \"offers\": [\"value1\", \"value2\", \"value2\", \"value2\", \"value3\"]}";
    // When
    HyperLogLogPlus hllp = JSONSerialiser.deserialise(sketchAsString, HyperLogLogPlus.class);
    // Then
    HyperLogLogPlus expected = new HyperLogLogPlus(5, 5);
    expected.offer("value1");
    expected.offer("value2");
    expected.offer("value2");
    expected.offer("value2");
    expected.offer("value3");
    assertArrayEquals(expected.getBytes(), hllp.getBytes());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 57 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusJsonSerialisationTest method shouldDeserialiseNewNestedHllpWithSAndSpValues.

@Test
public void shouldDeserialiseNewNestedHllpWithSAndSpValues() throws IOException {
    // Given
    final String sketchAsString = "{\"hyperLogLogPlus\": {\"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)

Example 58 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class IterableToHyperLogLogPlusTest method shouldCreateHllSketchCardinality.

@Test
public void shouldCreateHllSketchCardinality() {
    // Given
    IterableToHyperLogLogPlus iterableToHyperLogLogPlus = new IterableToHyperLogLogPlus();
    List<Object> input = Arrays.asList("one", "one", "two", "two", "three");
    // When
    HyperLogLogPlus result = iterableToHyperLogLogPlus.apply(input);
    // Then
    assertThat(result.cardinality()).isEqualTo(3);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Example 59 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusConverterTest method testConverter.

@Test
public void testConverter() throws ConversionException {
    final HyperLogLogPlus hyperLogLogPlus = new HyperLogLogPlus(5, 5);
    hyperLogLogPlus.offer("A");
    hyperLogLogPlus.offer("B");
    assertEquals(hyperLogLogPlus.cardinality(), (long) HYPER_LOG_LOG_PLUS_CONVERTER.convert(hyperLogLogPlus));
    final HyperLogLogPlus emptyHyperLogLogPlus = new HyperLogLogPlus(5, 5);
    assertEquals(emptyHyperLogLogPlus.cardinality(), (long) HYPER_LOG_LOG_PLUS_CONVERTER.convert(emptyHyperLogLogPlus));
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test)

Example 60 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusKryoSerializerTest method getTestObject.

@Override
protected HyperLogLogPlus getTestObject() {
    final HyperLogLogPlus hyperLogLogPlus = new HyperLogLogPlus(5, 5);
    IntStream.range(0, 1000).forEach(i -> hyperLogLogPlus.offer("" + i));
    return hyperLogLogPlus;
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)

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