Skip to content

Commit 62721f7

Browse files
committed
Added the same test to classic, just to make sure the bug didn't appear
there.
1 parent 29a655d commit 62721f7

1 file changed

Lines changed: 41 additions & 3 deletions

File tree

src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Arrays;
3131
import java.util.Comparator;
3232

33+
import org.apache.datasketches.common.ArrayOfBooleansSerDe;
3334
import org.apache.datasketches.common.ArrayOfDoublesSerDe;
3435
import org.apache.datasketches.common.ArrayOfItemsSerDe;
3536
import org.apache.datasketches.common.ArrayOfLongsSerDe;
@@ -647,16 +648,53 @@ public void getQuantiles() {
647648
assertEquals(quantiles1, quantiles2);
648649
}
649650

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+
650678
@Test
651679
public void printlnTest() {
652680
println("PRINTING: "+this.getClass().getName());
653681
}
654682

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+
655693
/**
656-
* @param s value to print
694+
* @param o the Object to println
657695
*/
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()); }
660698
}
661699

662700
}

0 commit comments

Comments
 (0)