use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class RealValuedFunction method unaryFunctionCall.
private FieldValue unaryFunctionCall(FieldValue argument) {
Quantity q = Casting.toQuantity(argument);
if (Double.isNaN(q.getValue())) {
return new Quantity(Double.NaN);
}
double d = toDouble(q);
double value = apply(d);
if (Double.isNaN(value)) {
return new Quantity(Double.NaN);
} else {
return new Quantity(value);
}
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class StatFunction method apply.
@Override
public final FieldValue apply(List<FieldValue> arguments) {
double[] argumentValues = new double[arguments.size()];
for (int i = 0; i < arguments.size(); i++) {
FieldValue argument = arguments.get(i);
if (argument instanceof Quantity) {
Quantity quantity = (Quantity) argument;
argumentValues[i] = quantity.getValue();
} else {
argumentValues[i] = Double.NaN;
}
}
double result = compute(argumentValues, 0, argumentValues.length);
return new Quantity(result);
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class CeilingFunctionTest method test.
@Test
public void test() {
assertThat(CeilingFunction.INSTANCE.apply(1.6), Matchers.equalTo(2.0));
assertThat(CeilingFunction.INSTANCE.apply(1.5), Matchers.equalTo(2.0));
assertThat(CeilingFunction.INSTANCE.apply(1.4), Matchers.equalTo(2.0));
assertThat(CeilingFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-1.0));
assertThat(CeilingFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-1.0));
assertThat(CeilingFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-1.0));
assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(2.0)));
assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-1.0)));
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class FloorFunctionTest method test.
@Test
public void test() {
assertThat(FloorFunction.INSTANCE.apply(1.6), Matchers.equalTo(1.0));
assertThat(FloorFunction.INSTANCE.apply(1.5), Matchers.equalTo(1.0));
assertThat(FloorFunction.INSTANCE.apply(1.4), Matchers.equalTo(1.0));
assertThat(FloorFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-2.0));
assertThat(FloorFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-2.0));
assertThat(FloorFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-2.0));
assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(1.0)));
assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-2.0)));
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class YearFracFunctionTest method evaluation.
@Test
public void evaluation() {
LocalDate x = new LocalDate(2016, 1, 1);
LocalDate y = new LocalDate(2017, 1, 1);
Quantity z = (Quantity) YearFracFunction.INSTANCE.apply(Arrays.<FieldValue>asList(x, y));
assertThat(z, equalTo(new Quantity(1.0)));
}
Aggregations