leerho commented on a change in pull request #324: URL: https://github.com/apache/incubator-datasketches-java/pull/324#discussion_r452904819
########## File path: src/test/java/org/apache/datasketches/theta/SetOpsCornerCasesTest.java ########## @@ -0,0 +1,495 @@ +/* + * 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.theta; + +import static org.apache.datasketches.theta.SetOpsCornerCasesTest.State.EMPTY; +import static org.apache.datasketches.theta.SetOpsCornerCasesTest.State.EST_HEAP; +import static org.apache.datasketches.theta.SetOpsCornerCasesTest.State.EST_MEMORY_UNORDERED; +import static org.apache.datasketches.theta.SetOpsCornerCasesTest.State.EXACT; +import static org.apache.datasketches.theta.SetOpsCornerCasesTest.State.NULL; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.util.Random; + +import org.apache.datasketches.memory.WritableMemory; +import org.testng.Assert; +import org.testng.annotations.Test; + +@SuppressWarnings({"javadoc","deprecation"}) +public class SetOpsCornerCasesTest { + + /*******************************************/ + Random rand = new Random(9001); //deterministic + + @Test + public void checkSetOpsRandom() { + int hiA = 0, loB = 0, hiB = 0; + for (int i = 0; i < 1000; i++) { + hiA = rand.nextInt(128); //skA fed values between 0 and 127 + loB = rand.nextInt(64); + hiB = loB + rand.nextInt(64); //skB fed up to 63 values starting at loB + compareSetOpsRandom(64, 0, hiA, loB, hiB); + } + } + + private static void compareSetOpsRandom(int k, int loA, int hiA, int loB, int hiB) { + UpdateSketch tskA = Sketches.updateSketchBuilder().setNominalEntries(k).build(); + UpdateSketch tskB = Sketches.updateSketchBuilder().setNominalEntries(k).build(); + + for (int i = loA; i < hiA; i++) { tskA.update(i); } + for (int i = loB; i < hiB; i++) { tskB.update(i); } + + CompactSketch rcskStdU = doStdUnion(tskA, tskB, k, null); + CompactSketch rcskPwU = doPwUnion(tskA, tskB, k); + checkCornerCase(rcskPwU, rcskStdU); + + CompactSketch rcskStdPairU = doStdPairUnion(tskA, tskB, k, null); + checkCornerCase(rcskStdPairU, rcskStdU); + + CompactSketch rcskStdI = doStdIntersection(tskA, tskB, null); + CompactSketch rcskPwI = doPwIntersection(tskA, tskB); + checkCornerCase(rcskPwI, rcskStdI); + + CompactSketch rcskStdPairI = doStdPairIntersection(tskA, tskB, null); + checkCornerCase(rcskStdPairI, rcskStdI); + + CompactSketch rcskStdAnotB = doStdAnotB(tskA, tskB, null); + CompactSketch rcskPwAnotB = doPwAnotB(tskA, tskB); + checkCornerCase(rcskPwAnotB, rcskStdAnotB); + + CompactSketch rcskStdStatefulAnotB = doStdStatefulAnotB(tskA, tskB, null); + checkCornerCase(rcskStdStatefulAnotB, rcskStdAnotB); + } + + /*******************************************/ + + @Test + //Check all corner cases against standard Union, Intersection, and AnotB. + //The unordered case is not tested + public void compareCornerCases() { + int k = 64; + for (State stateA : State.values()) { + for (State stateB : State.values()) { + if ((stateA == EST_MEMORY_UNORDERED) || (stateB == EST_MEMORY_UNORDERED)) { continue; } + cornerCaseChecks(stateA, stateB, k); + //cornerCaseChecksMemory(stateA, stateB, k); Review comment: No I did not. Thanks! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
