Skip to content

Commit e4f7a5b

Browse files
authored
Merge pull request #723 from proost/test-kll-long-sketch-compatibility
test: KLL Long sketch compatibility with C++
2 parents cf427ae + 5d215c7 commit e4f7a5b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI;
4545
import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator;
4646
import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI;
47+
import org.apache.datasketches.quantilescommon.QuantilesLongsSketchIterator;
4748
import org.testng.annotations.Test;
4849

4950
/**
@@ -209,4 +210,28 @@ public int compare(final String s1, final String s2) {
209210
}
210211
}
211212

213+
@Test(groups = {CHECK_CPP_FILES})
214+
public void kllLong() throws IOException {
215+
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
216+
for (final int n: nArr) {
217+
final byte[] bytes = Files.readAllBytes(cppPath.resolve("kll_long_n" + n + "_cpp.sk"));
218+
final KllLongsSketch sketch = KllLongsSketch.heapify(MemorySegment.ofArray(bytes));
219+
assertEquals(sketch.getK(), 200);
220+
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
221+
assertTrue(n > 100 ? sketch.isEstimationMode() : !sketch.isEstimationMode());
222+
assertEquals(sketch.getN(), n);
223+
if (n > 0) {
224+
assertEquals(sketch.getMinItem(), 1);
225+
assertEquals(sketch.getMaxItem(), n);
226+
long weight = 0;
227+
final QuantilesLongsSketchIterator it = sketch.iterator();
228+
while (it.next()) {
229+
assertTrue(it.getQuantile() >= sketch.getMinItem());
230+
assertTrue(it.getQuantile() <= sketch.getMaxItem());
231+
weight += it.getWeight();
232+
}
233+
assertEquals(weight, n);
234+
}
235+
}
236+
}
212237
}

0 commit comments

Comments
 (0)