Skip to content

Commit 6a514db

Browse files
committed
test: add cases from C++ deserialize
1 parent e532b7f commit 6a514db

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,47 @@ public void deserializeFromCpp() throws IOException {
9999
}
100100
}
101101

102+
@Test(groups = {CHECK_CPP_FILES})
103+
public void deserializeNegativeFromCpp() throws IOException {
104+
final int[] nArr = {1, 10};
105+
for (final int n: nArr) {
106+
final byte[] bytes = getFileBytes(cppPath, "req_float_negative_n" + n + "_cpp.sk");
107+
final ReqSketch sk = ReqSketch.heapify(MemorySegment.ofArray(bytes));
108+
assertTrue(!sk.isEmpty());
109+
assertEquals(sk.getN(), n);
110+
assertEquals(sk.getMinItem(), -n);
111+
assertEquals(sk.getMaxItem(), -1);
112+
final QuantilesFloatsSketchIterator it = sk.iterator();
113+
long weight = 0;
114+
while(it.next()) {
115+
assertTrue(it.getQuantile() >= sk.getMinItem());
116+
assertTrue(it.getQuantile() <= sk.getMaxItem());
117+
weight += it.getWeight();
118+
}
119+
assertEquals(weight, n);
120+
}
121+
}
122+
123+
@Test(groups = {CHECK_CPP_FILES})
124+
public void deserializeMixedFromCpp() throws IOException {
125+
final int[] nArr = {1, 10};
126+
for (final int n: nArr) {
127+
final byte[] bytes = getFileBytes(cppPath, "req_float_mixed_n" + n + "_cpp.sk");
128+
final ReqSketch sk = ReqSketch.heapify(MemorySegment.ofArray(bytes));
129+
assertTrue(!sk.isEmpty());
130+
final int expectedN = 2 * n + 1; // range -n to n inclusive
131+
assertEquals(sk.getN(), expectedN);
132+
assertEquals(sk.getMinItem(), -n);
133+
assertEquals(sk.getMaxItem(), (float) n);
134+
final QuantilesFloatsSketchIterator it = sk.iterator();
135+
long weight = 0;
136+
while(it.next()) {
137+
assertTrue(it.getQuantile() >= sk.getMinItem());
138+
assertTrue(it.getQuantile() <= sk.getMaxItem());
139+
weight += it.getWeight();
140+
}
141+
assertEquals(weight, expectedN);
142+
}
143+
}
144+
102145
}

0 commit comments

Comments
 (0)