fixed bug in junit which was exposed due to new caching feature of the formula evaluator
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@693179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e18c4ad16
commit
d84d5e0b58
@ -26,79 +26,77 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class TestXSSFFormulaEvaluation extends TestCase {
|
public class TestXSSFFormulaEvaluation extends TestCase {
|
||||||
public TestXSSFFormulaEvaluation(String name) {
|
public TestXSSFFormulaEvaluation(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
// Use system out logger
|
// Use system out logger
|
||||||
System.setProperty(
|
System.setProperty(
|
||||||
"org.apache.poi.util.POILogger",
|
"org.apache.poi.util.POILogger",
|
||||||
"org.apache.poi.util.SystemOutLogger"
|
"org.apache.poi.util.SystemOutLogger"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleArithmatic() throws Exception {
|
public void testSimpleArithmatic() {
|
||||||
Workbook wb = new XSSFWorkbook();
|
Workbook wb = new XSSFWorkbook();
|
||||||
Sheet s = wb.createSheet();
|
Sheet s = wb.createSheet();
|
||||||
Row r = s.createRow(0);
|
Row r = s.createRow(0);
|
||||||
|
|
||||||
Cell c1 = r.createCell(0);
|
Cell c1 = r.createCell(0);
|
||||||
c1.setCellFormula("1+5");
|
c1.setCellFormula("1+5");
|
||||||
assertTrue( Double.isNaN(c1.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c1.getNumericCellValue()) );
|
||||||
|
|
||||||
Cell c2 = r.createCell(1);
|
Cell c2 = r.createCell(1);
|
||||||
c2.setCellFormula("10/2");
|
c2.setCellFormula("10/2");
|
||||||
assertTrue( Double.isNaN(c2.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c2.getNumericCellValue()) );
|
||||||
|
|
||||||
FormulaEvaluator fe = new FormulaEvaluator(s, wb);
|
FormulaEvaluator fe = new FormulaEvaluator(s, wb);
|
||||||
fe.setCurrentRow(r);
|
|
||||||
|
|
||||||
fe.evaluateFormulaCell(c1);
|
fe.evaluateFormulaCell(c1);
|
||||||
fe.evaluateFormulaCell(c2);
|
fe.evaluateFormulaCell(c2);
|
||||||
|
|
||||||
assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
|
assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
|
assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSumCount() throws Exception {
|
public void testSumCount() {
|
||||||
Workbook wb = new XSSFWorkbook();
|
Workbook wb = new XSSFWorkbook();
|
||||||
Sheet s = wb.createSheet();
|
Sheet s = wb.createSheet();
|
||||||
Row r = s.createRow(0);
|
Row r = s.createRow(0);
|
||||||
r.createCell(0).setCellValue(2.5);
|
r.createCell(0).setCellValue(2.5);
|
||||||
r.createCell(1).setCellValue(1.1);
|
r.createCell(1).setCellValue(1.1);
|
||||||
r.createCell(2).setCellValue(3.2);
|
r.createCell(2).setCellValue(3.2);
|
||||||
r.createCell(4).setCellValue(10.7);
|
r.createCell(4).setCellValue(10.7);
|
||||||
|
|
||||||
r = s.createRow(1);
|
r = s.createRow(1);
|
||||||
|
|
||||||
Cell c1 = r.createCell(0);
|
Cell c1 = r.createCell(0);
|
||||||
c1.setCellFormula("SUM(A1:B1)");
|
c1.setCellFormula("SUM(A1:B1)");
|
||||||
assertTrue( Double.isNaN(c1.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c1.getNumericCellValue()) );
|
||||||
|
|
||||||
Cell c2 = r.createCell(1);
|
Cell c2 = r.createCell(1);
|
||||||
c2.setCellFormula("SUM(A1:E1)");
|
c2.setCellFormula("SUM(A1:E1)");
|
||||||
assertTrue( Double.isNaN(c2.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c2.getNumericCellValue()) );
|
||||||
|
|
||||||
Cell c3 = r.createCell(2);
|
Cell c3 = r.createCell(2);
|
||||||
c3.setCellFormula("COUNT(A1:A1)");
|
c3.setCellFormula("COUNT(A1:A1)");
|
||||||
assertTrue( Double.isNaN(c3.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c3.getNumericCellValue()) );
|
||||||
|
|
||||||
Cell c4 = r.createCell(2);
|
Cell c4 = r.createCell(3);
|
||||||
c4.setCellFormula("COUNTA(A1:E1)");
|
c4.setCellFormula("COUNTA(A1:E1)");
|
||||||
assertTrue( Double.isNaN(c4.getNumericCellValue()) );
|
assertTrue( Double.isNaN(c4.getNumericCellValue()) );
|
||||||
|
|
||||||
|
|
||||||
// Evaluate and test
|
// Evaluate and test
|
||||||
FormulaEvaluator fe = new FormulaEvaluator(s, wb);
|
FormulaEvaluator fe = new FormulaEvaluator(s, wb);
|
||||||
fe.setCurrentRow(r);
|
|
||||||
|
|
||||||
fe.evaluateFormulaCell(c1);
|
fe.evaluateFormulaCell(c1);
|
||||||
fe.evaluateFormulaCell(c2);
|
fe.evaluateFormulaCell(c2);
|
||||||
fe.evaluateFormulaCell(c3);
|
fe.evaluateFormulaCell(c3);
|
||||||
fe.evaluateFormulaCell(c4);
|
fe.evaluateFormulaCell(c4);
|
||||||
|
|
||||||
assertEquals(3.6, c1.getNumericCellValue(), 0.0001);
|
assertEquals(3.6, c1.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
|
assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(1, c3.getNumericCellValue(), 0.0001);
|
assertEquals(1, c3.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(4, c4.getNumericCellValue(), 0.0001);
|
assertEquals(4, c4.getNumericCellValue(), 0.0001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user