Remove copy-pasted code (#29409)
* Remove copy-pasted code We had two instances of copy-pasted code with a bad license from another website. The code was doing something rather simple, and that functionality already exists within junit. This PR simply leverages the junit functionality.
This commit is contained in:
parent
28e9ef3c83
commit
ec65710926
|
@ -1292,8 +1292,8 @@ public class MovAvgIT extends ESIntegTestCase {
|
|||
assertThat("[_count] movavg should be NaN, but is ["+countMovAvg.value()+"] instead", countMovAvg.value(), equalTo(Double.NaN));
|
||||
} else {
|
||||
assertThat("[_count] movavg is null", countMovAvg, notNullValue());
|
||||
assertTrue("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]",
|
||||
nearlyEqual(countMovAvg.value(), expectedCount, 0.1));
|
||||
assertEquals("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]",
|
||||
countMovAvg.value(), expectedCount, 0.1);
|
||||
}
|
||||
|
||||
// This is a gap bucket
|
||||
|
@ -1304,29 +1304,8 @@ public class MovAvgIT extends ESIntegTestCase {
|
|||
assertThat("[value] movavg should be NaN, but is ["+valuesMovAvg.value()+"] instead", valuesMovAvg.value(), equalTo(Double.NaN));
|
||||
} else {
|
||||
assertThat("[value] movavg is null", valuesMovAvg, notNullValue());
|
||||
assertTrue("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]",
|
||||
nearlyEqual(valuesMovAvg.value(), expectedValue, 0.1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Better floating point comparisons courtesy of https://github.com/brazzy/floating-point-gui.de
|
||||
*
|
||||
* Snippet adapted to use doubles instead of floats
|
||||
*/
|
||||
private static boolean nearlyEqual(double a, double b, double epsilon) {
|
||||
final double absA = Math.abs(a);
|
||||
final double absB = Math.abs(b);
|
||||
final double diff = Math.abs(a - b);
|
||||
|
||||
if (a == b) { // shortcut, handles infinities
|
||||
return true;
|
||||
} else if (a == 0 || b == 0 || diff < Double.MIN_NORMAL) {
|
||||
// a or b is zero or both are extremely close to it
|
||||
// relative error is less meaningful here
|
||||
return diff < (epsilon * Double.MIN_NORMAL);
|
||||
} else { // use relative error
|
||||
return diff / Math.min((absA + absB), Double.MAX_VALUE) < epsilon;
|
||||
assertEquals("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]",
|
||||
valuesMovAvg.value(), expectedValue, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.DoubleMatcher.nearlyEqual;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
|
@ -156,8 +155,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
|
|||
assertTrue("Vanilla maxScore is NaN but Profile is not [" + profileMaxScore + "]",
|
||||
Float.isNaN(profileMaxScore));
|
||||
} else {
|
||||
assertTrue("Profile maxScore of [" + profileMaxScore + "] is not close to Vanilla maxScore [" + vanillaMaxScore + "]",
|
||||
nearlyEqual(vanillaMaxScore, profileMaxScore, 0.001));
|
||||
assertEquals("Profile maxScore of [" + profileMaxScore + "] is not close to Vanilla maxScore [" + vanillaMaxScore + "]",
|
||||
vanillaMaxScore, profileMaxScore, 0.001);
|
||||
}
|
||||
|
||||
assertThat(
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch 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.elasticsearch.test.hamcrest;
|
||||
|
||||
|
||||
public class DoubleMatcher {
|
||||
|
||||
/**
|
||||
* Better floating point comparisons courtesy of https://github.com/brazzy/floating-point-gui.de
|
||||
*
|
||||
* Snippet adapted to use doubles instead of floats
|
||||
*/
|
||||
public static boolean nearlyEqual(double a, double b, double epsilon) {
|
||||
final double absA = Math.abs(a);
|
||||
final double absB = Math.abs(b);
|
||||
final double diff = Math.abs(a - b);
|
||||
|
||||
if (a == b) { // shortcut, handles infinities
|
||||
return true;
|
||||
} else if (a == 0 || b == 0 || diff < Double.MIN_NORMAL) {
|
||||
// a or b is zero or both are extremely close to it
|
||||
// relative error is less meaningful here
|
||||
return diff < (epsilon * Double.MIN_NORMAL);
|
||||
} else { // use relative error
|
||||
return diff / Math.min((absA + absB), Double.MAX_VALUE) < epsilon;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue