|
30 | 30 | import java.util.Arrays;
|
31 | 31 | import java.util.Comparator;
|
32 | 32 |
|
| 33 | +import org.apache.datasketches.common.ArrayOfBooleansSerDe; |
33 | 34 | import org.apache.datasketches.common.ArrayOfDoublesSerDe;
|
34 | 35 | import org.apache.datasketches.common.ArrayOfItemsSerDe;
|
35 | 36 | import org.apache.datasketches.common.ArrayOfLongsSerDe;
|
@@ -647,16 +648,53 @@ public void getQuantiles() {
|
647 | 648 | assertEquals(quantiles1, quantiles2);
|
648 | 649 | }
|
649 | 650 |
|
| 651 | + @Test |
| 652 | + public void checkIssue484() { |
| 653 | + Boolean[] items = { true,false,true,false,true,false,true,false,true,false }; |
| 654 | + ItemsSketch<Boolean> sketch = ItemsSketch.getInstance(Boolean.class, Boolean::compareTo); |
| 655 | + for (int i = 0; i < items.length; i++) { sketch.update(items[i]); } |
| 656 | + byte[] serialized = sketch.toByteArray(new ArrayOfBooleansSerDe()); |
| 657 | + ItemsSketch<Boolean> deserialized = |
| 658 | + ItemsSketch.getInstance(Boolean.class, Memory.wrap(serialized), Boolean::compareTo, new ArrayOfBooleansSerDe()); |
| 659 | + checkSketchesEqual(sketch, deserialized); |
| 660 | + } |
| 661 | + |
| 662 | + private static <T> void checkSketchesEqual(ItemsSketch<T> expected, ItemsSketch<T> actual) { |
| 663 | + ItemsSketchSortedView<T> expSV = expected.getSortedView(); |
| 664 | + ItemsSketchSortedView<T> actSV = actual.getSortedView(); |
| 665 | + int N = (int)actSV.getN(); |
| 666 | + long[] expCumWts = expSV.getCumulativeWeights(); |
| 667 | + Boolean[] expItemsArr = (Boolean[])expSV.getQuantiles(); |
| 668 | + long[] actCumWts = actSV.getCumulativeWeights(); |
| 669 | + Boolean[] actItemsArr = (Boolean[])actSV.getQuantiles(); |
| 670 | + printf("%3s %8s %8s\n", "i","Actual", "Expected"); |
| 671 | + for (int i = 0; i < N; i++) { |
| 672 | + printf("%3d %8s %8s\n", i, actItemsArr[i].toString(), expItemsArr[i].toString()); |
| 673 | + } |
| 674 | + assertEquals(actCumWts, expCumWts); |
| 675 | + assertEquals(actItemsArr, expItemsArr); |
| 676 | + } |
| 677 | + |
650 | 678 | @Test
|
651 | 679 | public void printlnTest() {
|
652 | 680 | println("PRINTING: "+this.getClass().getName());
|
653 | 681 | }
|
654 | 682 |
|
| 683 | + private final static boolean enablePrinting = false; |
| 684 | + |
| 685 | + /** |
| 686 | + * @param format the format |
| 687 | + * @param args the args |
| 688 | + */ |
| 689 | + private static final void printf(final String format, final Object ...args) { |
| 690 | + if (enablePrinting) { System.out.printf(format, args); } |
| 691 | + } |
| 692 | + |
655 | 693 | /**
|
656 |
| - * @param s value to print |
| 694 | + * @param o the Object to println |
657 | 695 | */
|
658 |
| - static void println(final String s) { |
659 |
| - //System.out.println(s); //disable here |
| 696 | + private static final void println(final Object o) { |
| 697 | + if (enablePrinting) { System.out.println(o.toString()); } |
660 | 698 | }
|
661 | 699 |
|
662 | 700 | }
|
0 commit comments