[TEST] test against scaled value instead of fixed epsilon in MovAvgIT

When comparing doubles, fixed epsilons can fail because the absolute
difference in values may be quite large, even though the relative
difference is tiny (e.g. with two very large numbers).

Instead, we can scale epsilon by the absolute value of the expected
value.  This means we are looking for a diff that is epsilon-percent
away from the value, rather than just epsilon.

This is basically checking the relative error using junit's assertEqual.

Closes #29456, unmutes the test
This commit is contained in:
Zachary Tong 2018-04-17 17:33:18 +00:00
parent 9c8ebb608f
commit cfc9d12acc
1 changed files with 2 additions and 3 deletions

View File

@ -68,7 +68,6 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/29456")
@ESIntegTestCase.SuiteScopeTestCase
public class MovAvgIT extends ESIntegTestCase {
private static final String INTERVAL_FIELD = "l_value";
@ -1296,7 +1295,7 @@ public class MovAvgIT extends ESIntegTestCase {
} else {
assertThat("[_count] movavg is null", countMovAvg, notNullValue());
assertEquals("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]",
countMovAvg.value(), expectedCount, 0.1);
countMovAvg.value(), expectedCount, 0.1 * Math.abs(countMovAvg.value()));
}
// This is a gap bucket
@ -1308,7 +1307,7 @@ public class MovAvgIT extends ESIntegTestCase {
} else {
assertThat("[value] movavg is null", valuesMovAvg, notNullValue());
assertEquals("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]",
valuesMovAvg.value(), expectedValue, 0.1);
valuesMovAvg.value(), expectedValue, 0.1 * Math.abs(countMovAvg.value()));
}
}