|
@@ -37,45 +37,35 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
|
|
|
@ParametersFactory
|
|
|
public static Iterable<Object[]> parameters() {
|
|
|
- return parameterSuppliersFromTypedData(List.of(new TestCaseSupplier("Int - Int", () -> {
|
|
|
- // Ensure we don't have an overflow
|
|
|
- int rhs = randomIntBetween((Integer.MIN_VALUE >> 1) - 1, (Integer.MAX_VALUE >> 1) - 1);
|
|
|
- int lhs = randomIntBetween((Integer.MIN_VALUE >> 1) - 1, (Integer.MAX_VALUE >> 1) - 1);
|
|
|
- return new TestCaseSupplier.TestCase(
|
|
|
- List.of(
|
|
|
- new TestCaseSupplier.TypedData(lhs, DataTypes.INTEGER, "lhs"),
|
|
|
- new TestCaseSupplier.TypedData(rhs, DataTypes.INTEGER, "rhs")
|
|
|
+
|
|
|
+ List<TestCaseSupplier> suppliers = TestCaseSupplier.forBinaryWithWidening(
|
|
|
+ new TestCaseSupplier.NumericTypeTestConfigs<Number>(
|
|
|
+ new TestCaseSupplier.NumericTypeTestConfig<>(
|
|
|
+ (Integer.MIN_VALUE >> 1) - 1,
|
|
|
+ (Integer.MAX_VALUE >> 1) - 1,
|
|
|
+ (l, r) -> l.intValue() - r.intValue(),
|
|
|
+ "SubIntsEvaluator"
|
|
|
),
|
|
|
- "SubIntsEvaluator[lhs=Attribute[channel=0], rhs=Attribute[channel=1]]",
|
|
|
- DataTypes.INTEGER,
|
|
|
- equalTo(lhs - rhs)
|
|
|
- );
|
|
|
- }), new TestCaseSupplier("Long - Long", () -> {
|
|
|
- // Ensure we don't have an overflow
|
|
|
- long rhs = randomLongBetween((Long.MIN_VALUE >> 1) - 1, (Long.MAX_VALUE >> 1) - 1);
|
|
|
- long lhs = randomLongBetween((Long.MIN_VALUE >> 1) - 1, (Long.MAX_VALUE >> 1) - 1);
|
|
|
- return new TestCaseSupplier.TestCase(
|
|
|
- List.of(
|
|
|
- new TestCaseSupplier.TypedData(lhs, DataTypes.LONG, "lhs"),
|
|
|
- new TestCaseSupplier.TypedData(rhs, DataTypes.LONG, "rhs")
|
|
|
+ new TestCaseSupplier.NumericTypeTestConfig<>(
|
|
|
+ (Long.MIN_VALUE >> 1) - 1,
|
|
|
+ (Long.MAX_VALUE >> 1) - 1,
|
|
|
+ (l, r) -> l.longValue() - r.longValue(),
|
|
|
+ "SubLongsEvaluator"
|
|
|
),
|
|
|
- "SubLongsEvaluator[lhs=Attribute[channel=0], rhs=Attribute[channel=1]]",
|
|
|
- DataTypes.LONG,
|
|
|
- equalTo(lhs - rhs)
|
|
|
- );
|
|
|
- }), new TestCaseSupplier("Double - Double", () -> {
|
|
|
- double rhs = randomDouble();
|
|
|
- double lhs = randomDouble();
|
|
|
- return new TestCaseSupplier.TestCase(
|
|
|
- List.of(
|
|
|
- new TestCaseSupplier.TypedData(lhs, DataTypes.DOUBLE, "lhs"),
|
|
|
- new TestCaseSupplier.TypedData(rhs, DataTypes.DOUBLE, "rhs")
|
|
|
- ),
|
|
|
- "SubDoublesEvaluator[lhs=Attribute[channel=0], rhs=Attribute[channel=1]]",
|
|
|
- DataTypes.DOUBLE,
|
|
|
- equalTo(lhs - rhs)
|
|
|
- );
|
|
|
- })/*, new TestCaseSupplier("ULong - ULong", () -> {
|
|
|
+ new TestCaseSupplier.NumericTypeTestConfig<>(
|
|
|
+ Double.NEGATIVE_INFINITY,
|
|
|
+ Double.POSITIVE_INFINITY,
|
|
|
+ (l, r) -> l.doubleValue() - r.doubleValue(),
|
|
|
+ "SubDoublesEvaluator"
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ "lhs",
|
|
|
+ "rhs",
|
|
|
+ (lhs, rhs) -> List.of(),
|
|
|
+ true
|
|
|
+ );
|
|
|
+
|
|
|
+ /* new TestCaseSupplier("ULong - ULong", () -> {
|
|
|
// Ensure we don't have an overflow
|
|
|
// TODO: we should be able to test values over Long.MAX_VALUE too...
|
|
|
long rhs = randomLongBetween(0, (Long.MAX_VALUE >> 1) - 1);
|
|
@@ -88,7 +78,9 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
"SubUnsignedLongsEvaluator[lhs=Attribute[channel=0], rhs=Attribute[channel=1]]",
|
|
|
equalTo(asLongUnsigned(lhsBI.subtract(rhsBI).longValue()))
|
|
|
);
|
|
|
- }) */, new TestCaseSupplier("Datetime - Period", () -> {
|
|
|
+ }) */
|
|
|
+
|
|
|
+ suppliers.add(new TestCaseSupplier("Datetime - Period", () -> {
|
|
|
long lhs = (Long) randomLiteral(DataTypes.DATETIME).value();
|
|
|
Period rhs = (Period) randomLiteral(EsqlDataTypes.DATE_PERIOD).value();
|
|
|
return new TestCaseSupplier.TestCase(
|
|
@@ -100,7 +92,8 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
DataTypes.DATETIME,
|
|
|
equalTo(asMillis(asDateTime(lhs).minus(rhs)))
|
|
|
);
|
|
|
- }), new TestCaseSupplier("Period - Period", () -> {
|
|
|
+ }));
|
|
|
+ suppliers.add(new TestCaseSupplier("Period - Period", () -> {
|
|
|
Period lhs = (Period) randomLiteral(EsqlDataTypes.DATE_PERIOD).value();
|
|
|
Period rhs = (Period) randomLiteral(EsqlDataTypes.DATE_PERIOD).value();
|
|
|
return new TestCaseSupplier.TestCase(
|
|
@@ -112,7 +105,8 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
EsqlDataTypes.DATE_PERIOD,
|
|
|
equalTo(lhs.minus(rhs))
|
|
|
);
|
|
|
- }), new TestCaseSupplier("Datetime - Duration", () -> {
|
|
|
+ }));
|
|
|
+ suppliers.add(new TestCaseSupplier("Datetime - Duration", () -> {
|
|
|
long lhs = (Long) randomLiteral(DataTypes.DATETIME).value();
|
|
|
Duration rhs = (Duration) randomLiteral(EsqlDataTypes.TIME_DURATION).value();
|
|
|
TestCaseSupplier.TestCase testCase = new TestCaseSupplier.TestCase(
|
|
@@ -125,7 +119,8 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
equalTo(asMillis(asDateTime(lhs).minus(rhs)))
|
|
|
);
|
|
|
return testCase;
|
|
|
- }), new TestCaseSupplier("Duration - Duration", () -> {
|
|
|
+ }));
|
|
|
+ suppliers.add(new TestCaseSupplier("Duration - Duration", () -> {
|
|
|
Duration lhs = (Duration) randomLiteral(EsqlDataTypes.TIME_DURATION).value();
|
|
|
Duration rhs = (Duration) randomLiteral(EsqlDataTypes.TIME_DURATION).value();
|
|
|
return new TestCaseSupplier.TestCase(
|
|
@@ -137,7 +132,8 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
EsqlDataTypes.TIME_DURATION,
|
|
|
equalTo(lhs.minus(rhs))
|
|
|
);
|
|
|
- }), new TestCaseSupplier("MV", () -> {
|
|
|
+ }));
|
|
|
+ suppliers.add(new TestCaseSupplier("MV", () -> {
|
|
|
// Ensure we don't have an overflow
|
|
|
int rhs = randomIntBetween((Integer.MIN_VALUE >> 1) - 1, (Integer.MAX_VALUE >> 1) - 1);
|
|
|
int lhs = randomIntBetween((Integer.MIN_VALUE >> 1) - 1, (Integer.MAX_VALUE >> 1) - 1);
|
|
@@ -152,39 +148,50 @@ public class SubTests extends AbstractFunctionTestCase {
|
|
|
is(nullValue())
|
|
|
).withWarning("Line -1:-1: evaluation of [] failed, treating result as null. Only first 20 failures recorded.")
|
|
|
.withWarning("Line -1:-1: java.lang.IllegalArgumentException: single-value function encountered multi-value");
|
|
|
- }),
|
|
|
- // exact math arithmetic exceptions
|
|
|
+ }));
|
|
|
+ // exact math arithmetic exceptions
|
|
|
+ suppliers.add(
|
|
|
arithmeticExceptionOverflowCase(
|
|
|
DataTypes.INTEGER,
|
|
|
() -> Integer.MIN_VALUE,
|
|
|
() -> randomIntBetween(1, Integer.MAX_VALUE),
|
|
|
"SubIntsEvaluator"
|
|
|
- ),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ suppliers.add(
|
|
|
arithmeticExceptionOverflowCase(
|
|
|
DataTypes.INTEGER,
|
|
|
() -> randomIntBetween(Integer.MIN_VALUE, -2),
|
|
|
() -> Integer.MAX_VALUE,
|
|
|
"SubIntsEvaluator"
|
|
|
- ),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ suppliers.add(
|
|
|
arithmeticExceptionOverflowCase(
|
|
|
DataTypes.LONG,
|
|
|
() -> Long.MIN_VALUE,
|
|
|
() -> randomLongBetween(1L, Long.MAX_VALUE),
|
|
|
"SubLongsEvaluator"
|
|
|
- ),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ suppliers.add(
|
|
|
arithmeticExceptionOverflowCase(
|
|
|
DataTypes.LONG,
|
|
|
() -> randomLongBetween(Long.MIN_VALUE, -2L),
|
|
|
() -> Long.MAX_VALUE,
|
|
|
"SubLongsEvaluator"
|
|
|
- ),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ suppliers.add(
|
|
|
arithmeticExceptionOverflowCase(
|
|
|
DataTypes.UNSIGNED_LONG,
|
|
|
() -> ZERO_AS_UNSIGNED_LONG,
|
|
|
() -> randomLongBetween(-Long.MAX_VALUE, Long.MAX_VALUE),
|
|
|
"SubUnsignedLongsEvaluator"
|
|
|
)
|
|
|
- ));
|
|
|
+ );
|
|
|
+
|
|
|
+ return parameterSuppliersFromTypedData(suppliers);
|
|
|
}
|
|
|
|
|
|
@Override
|