</p>
</section>
+ <section><title>Testing Framework</title>
+ <p>Automated testing of the implemented Function is easy.
+ The source code for this is in the file: o.a.p.h.record.formula.GenericFormulaTestCase.java
+ This class has a reference to the test xls file (not /a/ test xls, /the/ test xls :)
+ which may need to be changed for your environment. Once you do that, in the test xls,
+ locate the entry for the function that you have implemented and enter different tests
+ in a cell in the FORMULA row. Then copy the "value of" the formula that you entered in the
+ cell just below it (this is easily done in excel as:
+ [copy the formula cell] > [go to cell below] > Edit > Paste Special > Values > "ok").
+ You can enter multiple such formulas and paste their values in the cell below and the
+ test framework will automatically test if the formula evaluation matches the expected
+ value (Again, hard to put in words, so if you will, please take time to quickly look
+ at the code and the currently entered tests in the patch attachment "FormulaEvalTestData.xls"
+ file).
+ </p>
+ </section>
+
<anchor id="appendixA"/>
<section>
<title>Appendix A</title>
</source>
</section>
</body>
-</document>
\ No newline at end of file
+</document>
<changes>
<release version="3.8-beta6" date="2012-??-??">
+ <action dev="poi-developers" type="add">52057 - updated formula test framework to be aware of recently added Functions </action>
<action dev="poi-developers" type="add">52574 - support setting header / footer page margins in HSSF </action>
<action dev="poi-developers" type="add">52583 - fixed WorkbookUtil#createSafeSheetName to escape colon </action>
<action dev="poi-developers" type="add">51710 - fixed reading shared formulas in XSSF </action>
double d0 = singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
double d1 = singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
double multi = Math.pow(10d,d1);
- result = Math.floor(d0 * multi) / multi;
+ if(d0 < 0) result = -Math.floor(-d0 * multi) / multi;
+ else result = Math.floor(d0 * multi) / multi;
checkValue(result);
}catch (EvaluationException e) {
return e.getErrorEval();
package org.apache.poi.ss.formula.eval;
import java.io.PrintStream;
+import java.util.Collection;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
/**
* Tests formulas and operators as loaded from a test data spreadsheet.<p/>
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*/
public final class TestFormulasFromSpreadsheet extends TestCase {
+ private static final POILogger logger = POILogFactory.getLogger(TestFormulasFromSpreadsheet.class);
private static final class Result {
public static final int SOME_EVALUATIONS_FAILED = -1;
+ _evaluationFailureCount + " evaluation(s). " + successMsg;
throw new AssertionFailedError(msg);
}
- if(false) { // normally no output for successful tests
- System.out.println(getClass().getName() + ": " + successMsg);
- }
+ logger.log(POILogger.INFO, getClass().getName() + ": " + successMsg);
}
/**
*/
private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);
+ Collection<String> funcs = FunctionEval.getSupportedFunctionNames();
int rowIndex = startRowIndex;
while (true) {
default:
throw new RuntimeException("unexpected result");
case Result.NO_EVALUATIONS_FOUND: // do nothing
+ String uname = targetFunctionName.toUpperCase();
+ if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
+ funcs.contains(uname)) {
+ logger.log(POILogger.WARN, uname + ": function is supported but missing test data");
+ }
+ break;
}
}
rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION;
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
+
+ public void testNegative() {
+ ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) };
+ @SuppressWarnings("static-access")
+ ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
+ assertEquals("TRUNC", (new NumberEval(-8)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ }
}