Skip to content

Commit f5689af

Browse files
authored
Fixing doctests result matchers (#135979)
* Fixing doctests result matchers * fxup * fixup * fixup
1 parent c9dc3e8 commit f5689af

File tree

3 files changed

+22
-55
lines changed

3 files changed

+22
-55
lines changed

muted-tests.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -558,36 +558,12 @@ tests:
558558
- class: org.elasticsearch.indices.recovery.IndexRecoveryIT
559559
method: testUsesFileBasedRecoveryIfOperationsBasedRecoveryWouldBeUnreasonable
560560
issue: https://github.com/elastic/elasticsearch/issues/135737
561-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IncreaseTests
562-
method: testGroupingAggregate {TestCase=<small positive doubles>}
563-
issue: https://github.com/elastic/elasticsearch/issues/135752
564-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IncreaseTests
565-
method: testGroupingAggregate {TestCase=<positive ints>}
566-
issue: https://github.com/elastic/elasticsearch/issues/135753
567-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IncreaseTests
568-
method: testGroupingAggregate {TestCase=<positive longs>}
569-
issue: https://github.com/elastic/elasticsearch/issues/135754
570-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IncreaseTests
571-
method: testGroupingAggregate {TestCase=<big positive doubles>}
572-
issue: https://github.com/elastic/elasticsearch/issues/135755
573561
- class: org.elasticsearch.xpack.esql.ccq.AllSupportedFieldsIT
574562
method: testFetchDenseVector {pref=null mode=time_series}
575563
issue: https://github.com/elastic/elasticsearch/issues/135762
576-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IrateTests
577-
method: testGroupingAggregate {TestCase=<positive longs>}
578-
issue: https://github.com/elastic/elasticsearch/issues/135775
579564
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
580565
method: test
581566
issue: https://github.com/elastic/elasticsearch/issues/135787
582-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IrateTests
583-
method: testGroupingAggregate {TestCase=<positive ints>}
584-
issue: https://github.com/elastic/elasticsearch/issues/135814
585-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IrateTests
586-
method: testGroupingAggregate {TestCase=<small positive doubles>}
587-
issue: https://github.com/elastic/elasticsearch/issues/135757
588-
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IrateTests
589-
method: testGroupingAggregate {TestCase=<big positive doubles>}
590-
issue: https://github.com/elastic/elasticsearch/issues/135756
591567
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
592568
method: test
593569
issue: https://github.com/elastic/elasticsearch/issues/135787

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/IncreaseTests.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Objects;
2626
import java.util.function.Supplier;
2727

28-
import static org.hamcrest.Matchers.closeTo;
2928
import static org.hamcrest.Matchers.equalTo;
3029
import static org.hamcrest.Matchers.hasSize;
3130

@@ -126,18 +125,18 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier
126125
if (nonNullDataRows.size() < 2) {
127126
matcher = Matchers.nullValue();
128127
} else {
129-
double increase = 0.0;
128+
double resets = 0.0;
129+
double last = ((Number) nonNullDataRows.get(0)).doubleValue();
130+
double current = last;
130131
for (int i = 1; i < nonNullDataRows.size(); i++) {
131-
double previous = ((Number) nonNullDataRows.get(i - 1)).doubleValue();
132-
double current = ((Number) nonNullDataRows.get(i)).doubleValue();
133-
if (current >= previous) {
134-
increase += current - previous;
135-
} else {
136-
// Counter reset
137-
increase += current;
132+
double prev = ((Number) nonNullDataRows.get(i)).doubleValue();
133+
if (prev > current) {
134+
resets += prev;
138135
}
136+
current = prev;
139137
}
140-
matcher = closeTo(increase, 0.1 * increase);
138+
double increase = resets + (last - current);
139+
matcher = Matchers.allOf(Matchers.greaterThanOrEqualTo(increase * 0.9), Matchers.lessThanOrEqualTo(increase * 1.01));
141140
}
142141

143142
return new TestCaseSupplier.TestCase(

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/IrateTests.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,22 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier
122122
);
123123

124124
List<Object> nonNullDataRows = dataRows.stream().filter(Objects::nonNull).toList();
125-
Object maxValue = null;
126-
Object minValue = null;
127-
128-
for (int i = dataRows.size() - 1; i >= 0; i--) {
129-
if (dataRows.get(i) != null) {
130-
if (maxValue == null) {
131-
maxValue = dataRows.get(i);
132-
} else if (((Comparable) dataRows.get(i)).compareTo(maxValue) > 0) {
133-
maxValue = dataRows.get(i);
134-
}
135-
if (minValue == null) {
136-
minValue = dataRows.get(i);
137-
} else if (((Comparable) dataRows.get(i)).compareTo(minValue) < 0) {
138-
minValue = dataRows.get(i);
139-
}
140-
}
141-
}
142-
143-
final Matcher<?> matcher;
125+
Matcher<?> matcher;
144126
if (nonNullDataRows.size() < 2) {
145127
matcher = Matchers.nullValue();
146128
} else {
147-
var maxDiff = ((Number) maxValue).doubleValue() - ((Number) minValue).doubleValue();
148-
matcher = Matchers.allOf(Matchers.greaterThanOrEqualTo(-maxDiff), Matchers.lessThanOrEqualTo(maxDiff));
129+
var lastValue = ((Number) nonNullDataRows.getFirst()).doubleValue();
130+
var secondLastValue = ((Number) nonNullDataRows.get(1)).doubleValue();
131+
var increase = lastValue >= secondLastValue ? lastValue - secondLastValue : lastValue;
132+
var largestTimestamp = timestamps.get(0);
133+
var secondLargestTimestamp = timestamps.get(1);
134+
var smallestTimestamp = timestamps.getLast();
135+
matcher = Matchers.allOf(
136+
Matchers.greaterThanOrEqualTo(increase / (largestTimestamp - smallestTimestamp) * 1000 * 0.9),
137+
Matchers.lessThanOrEqualTo(
138+
increase / (largestTimestamp - secondLargestTimestamp) * (largestTimestamp - smallestTimestamp) * 1000
139+
)
140+
);
149141
}
150142

151143
return new TestCaseSupplier.TestCase(

0 commit comments

Comments
 (0)