This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch check_cpp_files
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
The following commit(s) were added to refs/heads/check_cpp_files by this push:
new b6760147 deserialize from C++ tests
b6760147 is described below
commit b67601472b8f17b309269d11e5e4c15e631b3ede
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Fri Aug 25 17:10:00 2023 -0700
deserialize from C++ tests
---
...DeTest.java => ReqSketchCrossLanguageTest.java} | 37 ++++-
.../sampling/VarOptCrossLanguageTest.java | 166 +++++++++++++++++++++
.../sampling/VarOptSketchSerDeTest.java | 70 ---------
.../sampling/VarOptUnionSerDeTest.java | 61 --------
...Test.java => ThetaSketchCrossLanguageTest.java} | 32 +++-
...DeTest.java => AodSketchCrossLanguageTest.java} | 52 ++++++-
6 files changed, 283 insertions(+), 135 deletions(-)
diff --git a/src/test/java/org/apache/datasketches/req/ReqSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
similarity index 50%
rename from src/test/java/org/apache/datasketches/req/ReqSketchSerDeTest.java
rename to
src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
index 1a1977b2..4d925270 100644
--- a/src/test/java/org/apache/datasketches/req/ReqSketchSerDeTest.java
+++ b/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
@@ -19,15 +19,26 @@
package org.apache.datasketches.req;
+import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
+import java.util.Comparator;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator;
import org.testng.annotations.Test;
-public class ReqSketchSerDeTest {
+/**
+ * Serialize binary sketches to be tested by C++ code.
+ * Test deserialization of binary sketches serialized by C++ code.
+ */
+public class ReqSketchCrossLanguageTest {
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
@@ -39,4 +50,28 @@ public class ReqSketchSerDeTest {
}
}
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCpp() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+ for (int n: nArr) {
+ final byte[] bytes = Files.readAllBytes(cppPath.resolve("req_float_n" +
n + "_cpp.sk"));
+ final ReqSketch sk = ReqSketch.heapify(Memory.wrap(bytes));
+ assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
+ assertTrue(n > 10 ? sk.isEstimationMode() : !sk.isEstimationMode());
+ assertEquals(sk.getN(), n);
+ if (n > 0) {
+ assertEquals(sk.getMinItem(), 1);
+ assertEquals(sk.getMaxItem(), n);
+ QuantilesFloatsSketchIterator it = sk.iterator();
+ long weight = 0;
+ while(it.next()) {
+ assertTrue(it.getQuantile() >= sk.getMinItem());
+ assertTrue(it.getQuantile() <= sk.getMaxItem());
+ weight += it.getWeight();
+ }
+ assertEquals(weight, n);
+ }
+ }
+ }
+
}
diff --git
a/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
new file mode 100644
index 00000000..0826e1da
--- /dev/null
+++
b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.sampling;
+
+import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
+import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.cppPath;
+import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+
+import org.apache.datasketches.common.ArrayOfDoublesSerDe;
+import org.apache.datasketches.common.ArrayOfLongsSerDe;
+import org.apache.datasketches.common.ArrayOfStringsSerDe;
+import org.apache.datasketches.memory.Memory;
+import org.testng.annotations.Test;
+
+/**
+ * Serialize binary sketches to be tested by C++ code.
+ * Test deserialization of binary sketches serialized by C++ code.
+ */
+public class VarOptCrossLanguageTest {
+ static final double EPS = 1e-13;
+
+ @Test(groups = {GENERATE_JAVA_FILES})
+ public void generateSketchesLong() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
+ for (int n: nArr) {
+ final VarOptItemsSketch<Long> sk = VarOptItemsSketch.newInstance(32);
+ for (int i = 1; i <= n; i++) sk.update(Long.valueOf(i), 1.0);
+ Files.newOutputStream(javaPath.resolve("varopt_sketch_long_n" + n +
"_java.sk"))
+ .write(sk.toByteArray(new ArrayOfLongsSerDe()));
+ }
+ }
+
+ @Test(groups = {GENERATE_JAVA_FILES})
+ public void generateSketchStringExact() throws IOException {
+ final VarOptItemsSketch<String> sketch =
VarOptItemsSketch.newInstance(1024);
+ for (int i = 1; i <= 200; ++i) {
+ sketch.update(Integer.toString(i), 1000.0 / i);
+ }
+
Files.newOutputStream(javaPath.resolve("varopt_sketch_string_exact_java.sk"))
+ .write(sketch.toByteArray(new ArrayOfStringsSerDe()));
+ }
+
+ @Test(groups = {GENERATE_JAVA_FILES})
+ public void generateSketchLongSampling() throws IOException {
+ final VarOptItemsSketch<Long> sketch = VarOptItemsSketch.newInstance(1024);
+ for (long i = 0; i < 2000; ++i) {
+ sketch.update(i, 1.0);
+ }
+ // heavy items have negative weights to allow a simple predicate to filter
+ sketch.update(-1L, 100000.0);
+ sketch.update(-2L, 110000.0);
+ sketch.update(-3L, 120000.0);
+
Files.newOutputStream(javaPath.resolve("varopt_sketch_long_sampling_java.sk"))
+ .write(sketch.toByteArray(new ArrayOfLongsSerDe()));
+ }
+
+ @Test(groups = {GENERATE_JAVA_FILES})
+ public void generateUnionDoubleSampling() throws IOException {
+ final int kSmall = 16;
+ final int n1 = 32;
+ final int n2 = 64;
+ final int kMax = 128;
+
+ // small k sketch, but sampling
+ VarOptItemsSketch<Double> sketch = VarOptItemsSketch.newInstance(kSmall);
+ for (int i = 0; i < n1; ++i) {
+ sketch.update(1.0 * i, 1.0);
+ }
+ sketch.update(-1.0, n1 * n1); // heavy items have negative weights to
allow a simple predicate to filter
+
+
+ final VarOptItemsUnion<Double> union = VarOptItemsUnion.newInstance(kMax);
+ union.update(sketch);
+
+ // another one, but different n to get a different per-item weight
+ sketch = VarOptItemsSketch.newInstance(kSmall);
+ for (int i = 0; i < n2; ++i) {
+ sketch.update(1.0 * i, 1.0);
+ }
+ union.update(sketch);
+
Files.newOutputStream(javaPath.resolve("varopt_union_double_sampling_java.sk"))
+ .write(union.toByteArray(new ArrayOfDoublesSerDe()));
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppSketchLongs() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+ for (int n: nArr) {
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("varopt_sketch_long_n" + n + "_cpp.sk"));
+ final VarOptItemsSketch<Long> sk =
VarOptItemsSketch.heapify(Memory.wrap(bytes), new ArrayOfLongsSerDe());
+ assertEquals(sk.getK(), 32);
+ assertEquals(sk.getN(), n);
+ assertEquals(sk.getNumSamples(), n > 10 ? 32 : n);
+ }
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppSketchStringsExact() throws IOException {
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("varopt_sketch_string_exact_cpp.sk"));
+ final VarOptItemsSketch<String> sk =
VarOptItemsSketch.heapify(Memory.wrap(bytes), new ArrayOfStringsSerDe());
+ assertEquals(sk.getK(), 1024);
+ assertEquals(sk.getN(), 200);
+ assertEquals(sk.getNumSamples(), 200);
+ final SampleSubsetSummary ss = sk.estimateSubsetSum(item -> true);
+ double weight = 0;
+ for (int i = 1; i <= 200; ++i) weight += 1000.0 / i;
+ assertEquals(ss.getTotalSketchWeight(), weight, EPS);
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppSketchLongsSampling() throws IOException {
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("varopt_sketch_long_sampling_cpp.sk"));
+ final VarOptItemsSketch<Long> sk =
VarOptItemsSketch.heapify(Memory.wrap(bytes), new ArrayOfLongsSerDe());
+ assertEquals(sk.getK(), 1024);
+ assertEquals(sk.getN(), 2003);
+ assertEquals(sk.getNumSamples(), 1024);
+ SampleSubsetSummary ss = sk.estimateSubsetSum(item -> true);
+ assertEquals(ss.getTotalSketchWeight(), 332000.0, EPS);
+
+ ss = sk.estimateSubsetSum(item -> item < 0);
+ assertEquals(ss.getEstimate(), 330000.0); // heavy item, weight is exact
+
+ ss = sk.estimateSubsetSum(item -> item >= 0);
+ assertEquals(ss.getEstimate(), 2000.0, EPS);
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppUnionDoubleSampling() throws IOException {
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("varopt_union_double_sampling_cpp.sk"));
+ final VarOptItemsUnion<Double> u =
VarOptItemsUnion.heapify(Memory.wrap(bytes), new ArrayOfDoublesSerDe());
+
+ // must reduce k in the process
+ final VarOptItemsSketch<Double> sk = u.getResult();
+ assertTrue(sk.getK() < 128);
+ assertEquals(sk.getN(), 97);
+
+ // light items, ignoring the heavy one
+ SampleSubsetSummary ss = sk.estimateSubsetSum(item -> item >= 0);
+ assertEquals(ss.getEstimate(), 96.0, EPS);
+ assertEquals(ss.getTotalSketchWeight(), 96.0 + 1024.0, EPS);
+ }
+
+}
diff --git
a/src/test/java/org/apache/datasketches/sampling/VarOptSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/sampling/VarOptSketchSerDeTest.java
deleted file mode 100644
index efb19e8c..00000000
--- a/src/test/java/org/apache/datasketches/sampling/VarOptSketchSerDeTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.datasketches.sampling;
-
-import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
-import static org.apache.datasketches.common.TestUtil.javaPath;
-
-import java.io.IOException;
-import java.nio.file.Files;
-
-import org.apache.datasketches.common.ArrayOfLongsSerDe;
-import org.apache.datasketches.common.ArrayOfStringsSerDe;
-import org.testng.annotations.Test;
-
-public class VarOptSketchSerDeTest {
-
-
- @Test(groups = {GENERATE_JAVA_FILES})
- public void generateBinariesForCompatibilityTesting() throws IOException {
- final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
- for (int n: nArr) {
- final VarOptItemsSketch<Long> sk = VarOptItemsSketch.newInstance(32);
- for (int i = 1; i <= n; i++) sk.update(Long.valueOf(i), 1.0);
- Files.newOutputStream(javaPath.resolve("varopt_sketch_long_n" + n +
"_java.sk"))
- .write(sk.toByteArray(new ArrayOfLongsSerDe()));
- }
- }
-
- @Test(groups = {GENERATE_JAVA_FILES})
- public void generateBinariesForCompatibilityTestingStringExact() throws
IOException {
- final VarOptItemsSketch<String> sketch =
VarOptItemsSketch.newInstance(1024);
- for (int i = 1; i <= 200; ++i) {
- sketch.update(Integer.toString(i), 1000.0 / i);
- }
-
Files.newOutputStream(javaPath.resolve("varopt_sketch_string_exact_java.sk"))
- .write(sketch.toByteArray(new ArrayOfStringsSerDe()));
- }
-
- @Test(groups = {GENERATE_JAVA_FILES})
- public void generateBinariesForCompatibilityTestingLongSampling() throws
IOException {
- final VarOptItemsSketch<Long> sketch = VarOptItemsSketch.newInstance(1024);
- for (long i = 0; i < 2000; ++i) {
- sketch.update(i, 1.0);
- }
- // heavy items have negative weights to allow a simple predicate to filter
- sketch.update(-1L, 100000.0);
- sketch.update(-2L, 110000.0);
- sketch.update(-3L, 120000.0);
-
Files.newOutputStream(javaPath.resolve("varopt_sketch_long_sampling_java.sk"))
- .write(sketch.toByteArray(new ArrayOfLongsSerDe()));
- }
-
-}
diff --git
a/src/test/java/org/apache/datasketches/sampling/VarOptUnionSerDeTest.java
b/src/test/java/org/apache/datasketches/sampling/VarOptUnionSerDeTest.java
deleted file mode 100644
index d88871f0..00000000
--- a/src/test/java/org/apache/datasketches/sampling/VarOptUnionSerDeTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.datasketches.sampling;
-
-import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
-import static org.apache.datasketches.common.TestUtil.javaPath;
-
-import java.io.IOException;
-import java.nio.file.Files;
-
-import org.apache.datasketches.common.ArrayOfDoublesSerDe;
-import org.testng.annotations.Test;
-
-public class VarOptUnionSerDeTest {
-
- @Test(groups = {GENERATE_JAVA_FILES})
- public void generateBinariesForCompatibilityTesting() throws IOException {
- final int kSmall = 16;
- final int n1 = 32;
- final int n2 = 64;
- final int kMax = 128;
-
- // small k sketch, but sampling
- VarOptItemsSketch<Double> sketch = VarOptItemsSketch.newInstance(kSmall);
- for (int i = 0; i < n1; ++i) {
- sketch.update(1.0 * i, 1.0);
- }
- sketch.update(-1.0, n1 * n1); // heavy items have negative weights to
allow a simple predicate to filter
-
-
- final VarOptItemsUnion<Double> union = VarOptItemsUnion.newInstance(kMax);
- union.update(sketch);
-
- // another one, but different n to get a different per-item weight
- sketch = VarOptItemsSketch.newInstance(kSmall);
- for (int i = 0; i < n2; ++i) {
- sketch.update(1.0 * i, 1.0);
- }
- union.update(sketch);
-
Files.newOutputStream(javaPath.resolve("varopt_union_double_sampling_java.sk"))
- .write(union.toByteArray(new ArrayOfDoublesSerDe()));
- }
-
-}
diff --git
a/src/test/java/org/apache/datasketches/theta/ThetaSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
similarity index 57%
rename from
src/test/java/org/apache/datasketches/theta/ThetaSketchSerDeTest.java
rename to
src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
index 419167c9..7bc49d9d 100644
--- a/src/test/java/org/apache/datasketches/theta/ThetaSketchSerDeTest.java
+++
b/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
@@ -19,16 +19,25 @@
package org.apache.datasketches.theta;
-import static org.apache.datasketches.common.TestUtil.*;
+import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
+import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.cppPath;
+import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
+import org.apache.datasketches.memory.Memory;
import org.testng.annotations.Test;
-public class ThetaSketchSerDeTest {
+/**
+ * Serialize binary sketches to be tested by C++ code.
+ * Test deserialization of binary sketches serialized by C++ code.
+ */
+public class ThetaSketchCrossLanguageTest {
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
@@ -49,4 +58,23 @@ public class ThetaSketchSerDeTest {
Files.newOutputStream(javaPath.resolve("theta_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
}
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCpp() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+ for (int n: nArr) {
+ final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_n" + n +
"_cpp.sk"));
+ final CompactSketch sketch = CompactSketch.wrap(Memory.wrap(bytes));
+ assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
+ assertEquals(sketch.getEstimate(), n, n * 0.03);
+ }
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppNonEmptyNoEntries() throws IOException {
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("theta_non_empty_no_entries_cpp.sk"));
+ final CompactSketch sketch = CompactSketch.wrap(Memory.wrap(bytes));
+ assertFalse(sketch.isEmpty());
+ assertEquals(sketch.getRetainedEntries(), 0);
+ }
+
}
diff --git
a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/ArrayOfDoublesSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
similarity index 54%
rename from
src/test/java/org/apache/datasketches/tuple/arrayofdoubles/ArrayOfDoublesSketchSerDeTest.java
rename to
src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
index 9a083b7d..e3b0db81 100644
---
a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/ArrayOfDoublesSketchSerDeTest.java
+++
b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
@@ -19,17 +19,25 @@
package org.apache.datasketches.tuple.arrayofdoubles;
+import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
+import org.apache.datasketches.memory.Memory;
import org.testng.annotations.Test;
-public class ArrayOfDoublesSketchSerDeTest {
+/**
+ * Serialize binary sketches to be tested by C++ code.
+ * Test deserialization of binary sketches serialized by C++ code.
+ */
+public class AodSketchCrossLanguageTest {
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTestingOneValue() throws
IOException {
@@ -61,4 +69,46 @@ public class ArrayOfDoublesSketchSerDeTest {
Files.newOutputStream(javaPath.resolve("aod_1_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
}
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppOneValue() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+ for (int n: nArr) {
+ final byte[] bytes = Files.readAllBytes(cppPath.resolve("aod_1_n" + n +
"_cpp.sk"));
+ final ArrayOfDoublesSketch sketch =
ArrayOfDoublesSketch.wrap(Memory.wrap(bytes));
+ assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
+ assertEquals(sketch.getEstimate(), n, n * 0.03);
+ assertEquals(sketch.getNumValues(), 1);
+ final ArrayOfDoublesSketchIterator it = sketch.iterator();
+ while (it.next()) {
+ assertTrue(it.getKey() < sketch.getThetaLong());
+ }
+ }
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppThreeValues() throws IOException {
+ final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+ for (int n: nArr) {
+ final byte[] bytes = Files.readAllBytes(cppPath.resolve("aod_3_n" + n +
"_cpp.sk"));
+ final ArrayOfDoublesSketch sketch =
ArrayOfDoublesSketch.wrap(Memory.wrap(bytes));
+ assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
+ assertEquals(sketch.getEstimate(), n, n * 0.03);
+ assertEquals(sketch.getNumValues(), 3);
+ final ArrayOfDoublesSketchIterator it = sketch.iterator();
+ while (it.next()) {
+ assertTrue(it.getKey() < sketch.getThetaLong());
+ assertEquals(it.getValues()[0], it.getValues()[1]);
+ assertEquals(it.getValues()[0], it.getValues()[2]);
+ }
+ }
+ }
+
+ @Test(groups = {CHECK_CPP_FILES})
+ public void deserializeFromCppOneValueNonEmptyNoEntries() throws IOException
{
+ final byte[] bytes =
Files.readAllBytes(cppPath.resolve("aod_1_non_empty_no_entries_cpp.sk"));
+ final ArrayOfDoublesSketch sketch =
ArrayOfDoublesSketch.wrap(Memory.wrap(bytes));
+ assertFalse(sketch.isEmpty());
+ assertEquals(sketch.getRetainedEntries(), 0);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]