|
27 | 27 |
|
28 | 28 | import java.util.Comparator; |
29 | 29 |
|
| 30 | +import org.apache.datasketches.common.ArrayOfBooleansSerDe; |
30 | 31 | import org.apache.datasketches.common.ArrayOfStringsSerDe; |
31 | 32 | import org.apache.datasketches.common.SketchesArgumentException; |
32 | 33 | import org.apache.datasketches.common.Util; |
@@ -437,6 +438,33 @@ public void checkGetSingleItem() { |
437 | 438 | assertEquals(skCompact.getSingleItem(), "1"); |
438 | 439 | } |
439 | 440 |
|
| 441 | + @Test |
| 442 | + public void checkIssue484() { |
| 443 | + Boolean[] items = { true,false,true,false,true,false,true,false,true,false }; |
| 444 | + KllItemsSketch<Boolean> sketch = KllItemsSketch.newHeapInstance(Boolean::compareTo, new ArrayOfBooleansSerDe()); |
| 445 | + for (int i = 0; i < items.length; i++) { sketch.update(items[i]); } |
| 446 | + byte[] serialized = sketch.toByteArray(); |
| 447 | + KllItemsSketch<Boolean> deserialized = |
| 448 | + KllItemsSketch.wrap(Memory.wrap(serialized), Boolean::compareTo, new ArrayOfBooleansSerDe()); |
| 449 | + checkSketchesEqual(items, sketch, deserialized); |
| 450 | + } |
| 451 | + |
| 452 | + private static <T> void checkSketchesEqual(T[] items, KllItemsSketch<T> expected, KllItemsSketch<T> actual) { |
| 453 | + KllItemsSketchSortedView<T> expSV = expected.getSortedView(); |
| 454 | + KllItemsSketchSortedView<T> actSV = actual.getSortedView(); |
| 455 | + long N = actSV.getN(); |
| 456 | + long[] expCumWts = expSV.getCumulativeWeights(); |
| 457 | + Boolean[] expItemsArr = (Boolean[])expSV.getQuantiles(); |
| 458 | + long[] actCumWts = actSV.getCumulativeWeights(); |
| 459 | + Boolean[] actItemsArr = (Boolean[])actSV.getQuantiles(); |
| 460 | + printf("%3s %8s %8s\n", "i","Actual", "Expected"); |
| 461 | + for (int i = 0; i < N; i++) { |
| 462 | + printf("%3d %8s %8s\n", i, actItemsArr[i].toString(), expItemsArr[i].toString()); |
| 463 | + } |
| 464 | + assertEquals(actCumWts, expCumWts); |
| 465 | + assertEquals(actItemsArr, expItemsArr); |
| 466 | + } |
| 467 | + |
440 | 468 | private final static boolean enablePrinting = false; |
441 | 469 |
|
442 | 470 | /** |
|
0 commit comments