Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Aug 2, 2024
1 parent 02c4949 commit 048932f
Showing 1 changed file with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.Supplier;

import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.is;

public class MvPSeriesWeightedSumTests extends AbstractScalarFunctionTestCase {
public MvPSeriesWeightedSumTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
Expand Down Expand Up @@ -59,10 +60,77 @@ private static void doubles(List<TestCaseSupplier> cases) {
match(expectedResult)
);
}));

cases.add(new TestCaseSupplier("values between 0 and 1", List.of(DataType.DOUBLE, DataType.DOUBLE), () -> {
List<Double> field = randomList(1, 10, () -> randomDoubleBetween(0, 1, true));
double p = randomDoubleBetween(-10, 10, true);
double expectedResult = calcPSeriesWeightedSum(field, p);

return new TestCaseSupplier.TestCase(
List.of(
new TestCaseSupplier.TypedData(field, DataType.DOUBLE, "field"),
new TestCaseSupplier.TypedData(p, DataType.DOUBLE, "p").forceLiteral()
),
"MvPSeriesWeightedSumDoubleEvaluator[block=Attribute[channel=0], p=" + p + "]",
DataType.DOUBLE,
match(expectedResult)
);
}));

cases.add(new TestCaseSupplier("values between -1 and 0", List.of(DataType.DOUBLE, DataType.DOUBLE), () -> {
List<Double> field = randomList(1, 10, () -> randomDoubleBetween(-1, 0, true));
double p = randomDoubleBetween(-10, 10, true);
double expectedResult = calcPSeriesWeightedSum(field, p);

return new TestCaseSupplier.TestCase(
List.of(
new TestCaseSupplier.TypedData(field, DataType.DOUBLE, "field"),
new TestCaseSupplier.TypedData(p, DataType.DOUBLE, "p").forceLiteral()
),
"MvPSeriesWeightedSumDoubleEvaluator[block=Attribute[channel=0], p=" + p + "]",
DataType.DOUBLE,
match(expectedResult)
);
}));

cases.add(new TestCaseSupplier("values between 1 and Double.MAX_VALUE", List.of(DataType.DOUBLE, DataType.DOUBLE), () -> {
List<Double> field = randomList(1, 10, () -> randomDoubleBetween(1, Double.MAX_VALUE, true));
double p = randomDoubleBetween(-10, 10, true);
double expectedResult = calcPSeriesWeightedSum(field, p);

return new TestCaseSupplier.TestCase(
List.of(
new TestCaseSupplier.TypedData(field, DataType.DOUBLE, "field"),
new TestCaseSupplier.TypedData(p, DataType.DOUBLE, "p").forceLiteral()
),
"MvPSeriesWeightedSumDoubleEvaluator[block=Attribute[channel=0], p=" + p + "]",
DataType.DOUBLE,
match(expectedResult)
);
}));

cases.add(new TestCaseSupplier("values between -Double.MAX_VALUE and 1", List.of(DataType.DOUBLE, DataType.DOUBLE), () -> {
List<Double> field = randomList(1, 10, () -> randomDoubleBetween(-Double.MAX_VALUE, 1, true));
double p = randomDoubleBetween(-10, 10, true);
double expectedResult = calcPSeriesWeightedSum(field, p);

return new TestCaseSupplier.TestCase(
List.of(
new TestCaseSupplier.TypedData(field, DataType.DOUBLE, "field"),
new TestCaseSupplier.TypedData(p, DataType.DOUBLE, "p").forceLiteral()
),
"MvPSeriesWeightedSumDoubleEvaluator[block=Attribute[channel=0], p=" + p + "]",
DataType.DOUBLE,
match(expectedResult)
);
}));
}

private static Matcher<Double> match(Double value) {
return closeTo(value, Math.abs(value * .00000001));
if (Double.isFinite(value)) {
return closeTo(value, Math.abs(value * .00000001));
}
return is(value);
}

private static double calcPSeriesWeightedSum(List<Double> field, double p) {
Expand Down

0 comments on commit 048932f

Please sign in to comment.