Skip to content
Merged
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
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ tests:
- class: org.elasticsearch.packaging.test.WindowsServiceTests
method: test80JavaOptsInEnvVar
issue: https://github.com/elastic/elasticsearch/issues/113219
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.AvgTests
method: "testFold {TestCase=<double> #2}"
issue: https://github.com/elastic/elasticsearch/issues/113225
- class: org.elasticsearch.packaging.test.WindowsServiceTests
method: test81JavaOptsInJvmOptions
issue: https://github.com/elastic/elasticsearch/issues/113313
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,7 @@ private void aggregateSingleMode(Expression expression) {
result = extractResultFromAggregator(aggregator, PlannerUtils.toElementType(testCase.expectedType()));
}

assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void aggregateGroupingSingleMode(Expression expression) {
Expand Down Expand Up @@ -263,15 +255,7 @@ private void aggregateWithIntermediates(Expression expression) {
result = extractResultFromAggregator(aggregator, PlannerUtils.toElementType(testCase.expectedType()));
}

assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void evaluate(Expression evaluableExpression) {
Expand All @@ -288,15 +272,7 @@ private void evaluate(Expression evaluableExpression) {
if (testCase.expectedType() == DataType.UNSIGNED_LONG && result != null) {
result = NumericUtils.unsignedLongAsBigInteger((Long) result);
}
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void resolveExpression(Expression expression, Consumer<Expression> onAggregator, Consumer<Expression> onEvaluableExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

/**
Expand Down Expand Up @@ -750,6 +752,34 @@ public static void testFunctionInfo() {
assertEquals(returnFromSignature, returnTypes);
}

/**
* Asserts the result of a test case matches the expected result and warnings.
* <p>
* The {@code result} parameter should be an object as returned by {@link #toJavaObjectUnsignedLongAware}.
* </p>
*/
@SuppressWarnings("unchecked")
protected final void assertTestCaseResultAndWarnings(Object result) {
if (result instanceof Iterable<?>) {
var collectionResult = (Iterable<Object>) result;
assertThat(collectionResult, not(hasItem(Double.NaN)));
assertThat(collectionResult, not(hasItem(Double.POSITIVE_INFINITY)));
assertThat(collectionResult, not(hasItem(Double.NEGATIVE_INFINITY)));
}

assert testCase.getMatcher().matches(Double.NaN) == false;
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());

if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
}

protected final void assertTypeResolutionFailure(Expression expression) {
assertTrue("expected unresolved", expression.typeResolved().unresolved());
assertThat(expression.typeResolved().message(), equalTo(testCase.getExpectedTypeError()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;

Expand Down Expand Up @@ -127,15 +126,7 @@ public final void testEvaluate() {
result = toJavaObjectUnsignedLongAware(block, 0);
}
}
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

/**
Expand Down
Loading