|
44 | 44 | import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; |
45 | 45 | import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator; |
46 | 46 | import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; |
| 47 | +import org.apache.datasketches.quantilescommon.QuantilesLongsSketchIterator; |
47 | 48 | import org.testng.annotations.Test; |
48 | 49 |
|
49 | 50 | /** |
@@ -209,4 +210,28 @@ public int compare(final String s1, final String s2) { |
209 | 210 | } |
210 | 211 | } |
211 | 212 |
|
| 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 | + } |
212 | 237 | } |
0 commit comments