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());
}
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());
}
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);
}
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));
}
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;
}
Aggregations