Skip to content

Commit b2cbb47

Browse files
committed
add cpc-go cross-serde
1 parent f6bdeb0 commit b2cbb47

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/test/java/org/apache/datasketches/common/TestUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public final class TestUtil {
4747
*/
4848
public static final String GENERATE_JAVA_FILES = "generate_java_files";
4949
public static final String CHECK_CPP_FILES = "check_cpp_files";
50+
public static final String CHECK_GO_FILES = "check_go_files";
5051
public static final String CHECK_CPP_HISTORICAL_FILES = "check_cpp_historical_files";
5152

5253
/**
@@ -59,6 +60,11 @@ public final class TestUtil {
5960
*/
6061
public static final Path cppPath = createPath("serialization_test_data/cpp_generated_files");
6162

63+
/**
64+
* The full target Path for Go serialized sketches to be tested by Java.
65+
*/
66+
public static final Path goPath = createPath("serialization_test_data/go_generated_files");
67+
6268
private static Path createPath(final String projectLocalDir) {
6369
try {
6470
return Files.createDirectories(Paths.get(userDir, projectLocalDir));

src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
package org.apache.datasketches.cpc;
2121

2222
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
23+
import static org.apache.datasketches.common.TestUtil.CHECK_GO_FILES;
2324
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
2425
import static org.apache.datasketches.common.TestUtil.cppPath;
26+
import static org.apache.datasketches.common.TestUtil.goPath;
2527
import static org.apache.datasketches.common.TestUtil.javaPath;
2628
import static org.testng.Assert.assertEquals;
2729

@@ -78,4 +80,17 @@ public void allFlavors() throws IOException {
7880
}
7981
}
8082

83+
@Test(groups = {CHECK_GO_FILES})
84+
public void checkAllFlavorsGo() throws IOException {
85+
final int[] nArr = {0, 100, 200, 2000, 20000};
86+
final Flavor[] flavorArr = {Flavor.EMPTY, Flavor.SPARSE, Flavor.HYBRID, Flavor.PINNED, Flavor.SLIDING};
87+
int flavorIdx = 0;
88+
for (int n: nArr) {
89+
final byte[] bytes = Files.readAllBytes(goPath.resolve("cpc_n" + n + "_go.sk"));
90+
final CpcSketch sketch = CpcSketch.heapify(Memory.wrap(bytes));
91+
assertEquals(sketch.getFlavor(), flavorArr[flavorIdx++]);
92+
assertEquals(sketch.getEstimate(), n, n * 0.02);
93+
}
94+
}
95+
8196
}

0 commit comments

Comments
 (0)