Skip to content

Add Go cross-serde tests for CPC sketch #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/apache/datasketches/cpc/CpcSketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public String toString(final boolean detail) {
final double errConst = mergeFlag ? log(2) : sqrt(log(2) / 2.0);
final double rse = errConst / Math.sqrt(1 << lgK);
final StringBuilder sb = new StringBuilder();
sb.append("### CPD SKETCH - PREAMBLE:").append(LS);
sb.append("### CPC SKETCH - PREAMBLE:").append(LS);
sb.append(" Flavor : ").append(getFlavor()).append(LS);
sb.append(" LgK : ").append(lgK).append(LS);
sb.append(" Merge Flag : ").append(mergeFlag).append(LS);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/apache/datasketches/common/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class TestUtil {
*/
public static final String GENERATE_JAVA_FILES = "generate_java_files";
public static final String CHECK_CPP_FILES = "check_cpp_files";
public static final String CHECK_GO_FILES = "check_go_files";
public static final String CHECK_CPP_HISTORICAL_FILES = "check_cpp_historical_files";

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

/**
* The full target Path for Go serialized sketches to be tested by Java.
*/
public static final Path goPath = createPath("serialization_test_data/go_generated_files");

private static Path createPath(final String projectLocalDir) {
try {
return Files.createDirectories(Paths.get(userDir, projectLocalDir));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package org.apache.datasketches.cpc;

import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_GO_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.goPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;

Expand Down Expand Up @@ -78,4 +80,17 @@ public void allFlavors() throws IOException {
}
}

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

}
Loading