leerho commented on code in PR #535: URL: https://github.com/apache/datasketches-java/pull/535#discussion_r1542059194
########## src/test/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnovTest.java: ########## @@ -0,0 +1,357 @@ +/* + * 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.quantilescommon; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.Random; + +import org.apache.datasketches.kll.KllDoublesSketch; +import org.apache.datasketches.kll.KllFloatsSketch; +import org.apache.datasketches.kll.KllSketch; +import org.apache.datasketches.quantiles.DoublesSketch; +import org.apache.datasketches.quantiles.UpdateDoublesSketch; +import org.testng.annotations.Test; + +public class KolmogorovSmirnovTest { + + @Test + public void checkDisjointDistributionClassicDoubles() { + final int k = 256; + final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); + final UpdateDoublesSketch s2 = DoublesSketch.builder().setK(k).build(); + + final Random rand = new Random(1); + + final int n = (3 * k) - 1; + for (int i = 0; i < n; ++i) { + final double x = rand.nextGaussian(); + s1.update(x + 500); + s2.update(x); + } + final double delta = DoublesSketch.getNormalizedRankError(k, false); + println("D = " + KolmogorovSmirnov.computeKSDelta(s1, s2)); + assertEquals(KolmogorovSmirnov.computeKSDelta(s1, s2), 1.0, delta); + } + + @Test + public void checkDisjointDistributionKllDoubles() { + final int k = 256; + final KllDoublesSketch s1 = KllDoublesSketch.newHeapInstance(k); + final KllDoublesSketch s2 = KllDoublesSketch.newHeapInstance(k); + + final Random rand = new Random(1); + + final int n = (3 * k) - 1; + for (int i = 0; i < n; ++i) { + final double x = rand.nextGaussian(); + s1.update(x + 500); + s2.update(x); + } + final double delta = KllSketch.getNormalizedRankError(k, false); + println("D = " + KolmogorovSmirnov.computeKSDelta(s1, s2)); + assertEquals(KolmogorovSmirnov.computeKSDelta(s1, s2), 1.0, delta); Review Comment: After a long side conversation, resolved to change name delta -> eps and the tolerance to 2 * eps. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
