aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchUtils.java
blob: 9bec86c928b6bbde739957584cb08aa8576ed2bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.aggregation.hll;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;

/**
 * Utility class for creating sketches and comparing their content.
 *
 * @author bjorncs
 */
public class SketchUtils {

    private SketchUtils() {}

    public static SparseSketch createSparseSketch(Integer... values) {
        SparseSketch sketch = new SparseSketch();
        sketch.aggregate(Arrays.asList(values));
        return sketch;
    }

    public static NormalSketch createNormalSketch(Integer... values) {
        NormalSketch sketch = new NormalSketch();
        sketch.aggregate(Arrays.asList(values));
        return sketch;
    }

    public static void assertSketchContains(Sketch<?> sketch, Integer... values) {
        if (sketch instanceof SparseSketch) {
            assertSparseSketchContains((SparseSketch) sketch, values);
        } else {
            assertNormalSketchContains((NormalSketch) sketch, values);
        }
    }

    public static void assertNormalSketchContains(NormalSketch sketch, Integer... values) {
        NormalSketch expectedSketch = createNormalSketch(values);
        assertEquals(expectedSketch, sketch);
    }

    public static void assertSparseSketchContains(SparseSketch sketch, Integer... values) {
        SparseSketch expectedSketch = createSparseSketch(values);
        assertEquals(expectedSketch, sketch);
    }
}