|
21 | 21 | import org.elasticsearch.xpack.esql.core.type.DataType; |
22 | 22 | import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase; |
23 | 23 | import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; |
| 24 | +import org.hamcrest.Matcher; |
24 | 25 | import org.junit.BeforeClass; |
25 | 26 |
|
| 27 | +import java.math.BigDecimal; |
| 28 | +import java.math.RoundingMode; |
26 | 29 | import java.time.Duration; |
27 | 30 | import java.time.Instant; |
28 | 31 | import java.time.LocalDateTime; |
@@ -666,7 +669,7 @@ private static List<TestCaseSupplier> intRandomTestCases() { |
666 | 669 | ), |
667 | 670 | startsWith("DecayIntEvaluator["), |
668 | 671 | DataType.DOUBLE, |
669 | | - closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult)) |
| 672 | + decayValueMatcher(scoreScriptNumericResult) |
670 | 673 | ); |
671 | 674 | })); |
672 | 675 | } |
@@ -740,7 +743,7 @@ private static List<TestCaseSupplier> longRandomTestCases() { |
740 | 743 | ), |
741 | 744 | startsWith("DecayLongEvaluator["), |
742 | 745 | DataType.DOUBLE, |
743 | | - equalTo(scoreScriptNumericResult) |
| 746 | + decayValueMatcher(scoreScriptNumericResult) |
744 | 747 | ); |
745 | 748 | })); |
746 | 749 | } |
@@ -810,7 +813,7 @@ private static List<TestCaseSupplier> doubleRandomTestCases() { |
810 | 813 | ), |
811 | 814 | startsWith("DecayDoubleEvaluator["), |
812 | 815 | DataType.DOUBLE, |
813 | | - closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult)) |
| 816 | + decayValueMatcher(scoreScriptNumericResult) |
814 | 817 | ); |
815 | 818 | })); |
816 | 819 | } |
@@ -908,7 +911,7 @@ private static List<TestCaseSupplier> geoPointRandomTestCases() { |
908 | 911 | ), |
909 | 912 | startsWith("DecayGeoPointEvaluator["), |
910 | 913 | DataType.DOUBLE, |
911 | | - closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult)) |
| 914 | + decayValueMatcher(scoreScriptNumericResult) |
912 | 915 | ); |
913 | 916 | })); |
914 | 917 | } |
@@ -1087,7 +1090,7 @@ private static List<TestCaseSupplier> datetimeRandomTestCases() { |
1087 | 1090 | ), |
1088 | 1091 | startsWith("DecayDatetimeEvaluator["), |
1089 | 1092 | DataType.DOUBLE, |
1090 | | - closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult)) |
| 1093 | + decayValueMatcher(scoreScriptNumericResult) |
1091 | 1094 | ); |
1092 | 1095 | })); |
1093 | 1096 | } |
@@ -1174,7 +1177,7 @@ private static List<TestCaseSupplier> dateNanosRandomTestCases() { |
1174 | 1177 | ), |
1175 | 1178 | startsWith("DecayDateNanosEvaluator["), |
1176 | 1179 | DataType.DOUBLE, |
1177 | | - closeTo(scoreScriptNumericResult, 1e-10) |
| 1180 | + decayValueMatcher(scoreScriptNumericResult) |
1178 | 1181 | ); |
1179 | 1182 | }) |
1180 | 1183 | ); |
@@ -1229,4 +1232,12 @@ private static MapExpression createOptionsMap(Object offset, Double decay, Strin |
1229 | 1232 |
|
1230 | 1233 | return new MapExpression(Source.EMPTY, keyValuePairs); |
1231 | 1234 | } |
| 1235 | + |
| 1236 | + private static Matcher<Double> decayValueMatcher(Double value) { |
| 1237 | + if (value == Double.POSITIVE_INFINITY || value == Double.NEGATIVE_INFINITY) { |
| 1238 | + return equalTo(value); |
| 1239 | + } |
| 1240 | + |
| 1241 | + return closeTo(BigDecimal.valueOf(value).setScale(4, RoundingMode.CEILING).doubleValue(), 0.001); |
| 1242 | + } |
1232 | 1243 | } |
0 commit comments