use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestMid method testExtremes.
/**
* Extreme values for startPos and numChars
*/
public void testExtremes() {
confirmMid(new StringEval("galactic"), new NumberEval(4), new NumberEval(400), "actic");
confirmMid(new StringEval("galactic"), new NumberEval(30), new NumberEval(4), "");
confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(0), "");
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestMatch method testSimpleNumber.
public void testSimpleNumber() {
ValueEval[] values = { new NumberEval(4), new NumberEval(5), new NumberEval(10), new NumberEval(10), new NumberEval(25) };
AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
confirmInt(2, invokeMatch(new NumberEval(5), ae));
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new NumberEval(10), ae, MATCH_LARGEST_LTE));
confirmInt(3, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new NumberEval(20), ae, MATCH_LARGEST_LTE));
assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestEDate method testEDateDecrease.
@Test
public void testEDateDecrease() {
EDate eDate = new EDate();
Date startDate = new Date();
int offset = -2;
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[] { new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset) }, null);
Date resultDate = DateUtil.getJavaDate(result.getNumberValue());
Calendar instance = LocaleUtil.getLocaleCalendar();
instance.setTime(startDate);
instance.add(Calendar.MONTH, offset);
assertEquals(resultDate, instance.getTime());
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class CalculateMortgage method evaluate.
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
// verify that we have enough data
if (args.length != 3) {
return ErrorEval.VALUE_INVALID;
}
// declare doubles for values
double principal, rate, years, result;
try {
// extract values as ValueEval
ValueEval v1 = OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex());
ValueEval v2 = OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex());
ValueEval v3 = OperandResolver.getSingleValue(args[2], ec.getRowIndex(), ec.getColumnIndex());
// get data as doubles
principal = OperandResolver.coerceValueToDouble(v1);
rate = OperandResolver.coerceValueToDouble(v2);
years = OperandResolver.coerceValueToDouble(v3);
result = calculateMortgagePayment(principal, rate, years);
System.out.println("Result = " + result);
checkValue(result);
} catch (EvaluationException e) {
return e.getErrorEval();
}
return new NumberEval(result);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestFixed method testOptionalParams.
@Test
public void testOptionalParams() {
Fixed fixed = new Fixed();
ValueEval evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789));
assertTrue(evaluate instanceof StringEval);
assertEquals("1,234.57", ((StringEval) evaluate).getStringValue());
evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1));
assertTrue(evaluate instanceof StringEval);
assertEquals("1,234.6", ((StringEval) evaluate).getStringValue());
evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1), BoolEval.TRUE);
assertTrue(evaluate instanceof StringEval);
assertEquals("1234.6", ((StringEval) evaluate).getStringValue());
evaluate = fixed.evaluate(new ValueEval[] {}, 1, 1);
assertTrue(evaluate instanceof ErrorEval);
evaluate = fixed.evaluate(new ValueEval[] { new NumberEval(1), new NumberEval(1), new NumberEval(1), new NumberEval(1) }, 1, 1);
assertTrue(evaluate instanceof ErrorEval);
}
Aggregations