Skip to content

Commit

Permalink
Added the same test to classic, just to make sure the bug didn't appear
Browse files Browse the repository at this point in the history
there.
  • Loading branch information
leerho committed Dec 21, 2023
1 parent 29a655d commit 62721f7
Showing 1 changed file with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.Comparator;

import org.apache.datasketches.common.ArrayOfBooleansSerDe;
import org.apache.datasketches.common.ArrayOfDoublesSerDe;
import org.apache.datasketches.common.ArrayOfItemsSerDe;
import org.apache.datasketches.common.ArrayOfLongsSerDe;
Expand Down Expand Up @@ -647,16 +648,53 @@ public void getQuantiles() {
assertEquals(quantiles1, quantiles2);
}

@Test
public void checkIssue484() {
Boolean[] items = { true,false,true,false,true,false,true,false,true,false };
ItemsSketch<Boolean> sketch = ItemsSketch.getInstance(Boolean.class, Boolean::compareTo);
for (int i = 0; i < items.length; i++) { sketch.update(items[i]); }
byte[] serialized = sketch.toByteArray(new ArrayOfBooleansSerDe());
ItemsSketch<Boolean> deserialized =
ItemsSketch.getInstance(Boolean.class, Memory.wrap(serialized), Boolean::compareTo, new ArrayOfBooleansSerDe());
checkSketchesEqual(sketch, deserialized);
}

private static <T> void checkSketchesEqual(ItemsSketch<T> expected, ItemsSketch<T> actual) {
ItemsSketchSortedView<T> expSV = expected.getSortedView();
ItemsSketchSortedView<T> actSV = actual.getSortedView();
int N = (int)actSV.getN();
long[] expCumWts = expSV.getCumulativeWeights();
Boolean[] expItemsArr = (Boolean[])expSV.getQuantiles();
long[] actCumWts = actSV.getCumulativeWeights();
Boolean[] actItemsArr = (Boolean[])actSV.getQuantiles();
printf("%3s %8s %8s\n", "i","Actual", "Expected");
for (int i = 0; i < N; i++) {
printf("%3d %8s %8s\n", i, actItemsArr[i].toString(), expItemsArr[i].toString());
}
assertEquals(actCumWts, expCumWts);
assertEquals(actItemsArr, expItemsArr);
}

@Test
public void printlnTest() {
println("PRINTING: "+this.getClass().getName());
}

private final static boolean enablePrinting = false;

/**
* @param format the format
* @param args the args
*/
private static final void printf(final String format, final Object ...args) {
if (enablePrinting) { System.out.printf(format, args); }
}

/**
* @param s value to print
* @param o the Object to println
*/
static void println(final String s) {
//System.out.println(s); //disable here
private static final void println(final Object o) {
if (enablePrinting) { System.out.println(o.toString()); }
}

}

0 comments on commit 62721f7

Please sign in to comment.