aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorAmol S. Deshmukh <amol@apache.org>2006-08-09 20:03:36 +0000
committerAmol S. Deshmukh <amol@apache.org>2006-08-09 20:03:36 +0000
commit0be9c45f8fc2bea064e049b85592c25e141a10df (patch)
treec3375c75134a2ddbf44f5c19a87e5fb74ca42a2b /src/testcases
parentcf07eb769a984bc73ea875923d9261c984b232cf (diff)
downloadpoi-0be9c45f8fc2bea064e049b85592c25e141a10df.tar.gz
poi-0be9c45f8fc2bea064e049b85592c25e141a10df.zip
bugfix 38396: Exponential numbers are now handled by the formula parser
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@430132 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
index 812a42d71c..b77353f8b2 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
@@ -404,6 +404,104 @@ public class TestFormulaParser extends TestCase {
}
+ // bug 38396 : Formula with exponential numbers not parsed correctly.
+ public void testExponentialParsing() {
+ FormulaParser fp = new FormulaParser("1.3E21/2", null);
+ fp.parse();
+ Ptg[] ptgs = fp.getRPNPtg();
+ assertTrue("three tokens expected, got " + ptgs.length, ptgs.length == 3);
+ assertTrue("NumberPtg", (ptgs[0] instanceof NumberPtg));
+ assertTrue("IntPtg", (ptgs[1] instanceof IntPtg));
+ assertTrue("DividePtg", (ptgs[2] instanceof DividePtg));
+
+ fp = new FormulaParser("1322E21/2", null);
+ fp.parse();
+ ptgs = fp.getRPNPtg();
+ assertTrue("three tokens expected, got " + ptgs.length, ptgs.length == 3);
+ assertTrue("NumberPtg", (ptgs[0] instanceof NumberPtg));
+ assertTrue("IntPtg", (ptgs[1] instanceof IntPtg));
+ assertTrue("DividePtg", (ptgs[2] instanceof DividePtg));
+
+ fp = new FormulaParser("1.3E1/2", null);
+ fp.parse();
+ ptgs = fp.getRPNPtg();
+ assertTrue("three tokens expected, got " + ptgs.length, ptgs.length == 3);
+ assertTrue("NumberPtg", (ptgs[0] instanceof NumberPtg));
+ assertTrue("IntPtg", (ptgs[1] instanceof IntPtg));
+ assertTrue("DividePtg", (ptgs[2] instanceof DividePtg));
+
+ }
+ public void testExponentialInSheet() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ wb.createSheet("Cash_Flow");;
+
+ HSSFSheet sheet = wb.createSheet("Test");
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cell = row.createCell((short)0);
+ String formula = null;
+
+ cell.setCellFormula("1.3E21/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1.3E21/3", formula);
+
+ cell.setCellFormula("-1.3E21/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.3E21/3", formula);
+
+ cell.setCellFormula("1322E21/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1.322E24/3", formula);
+
+ cell.setCellFormula("-1322E21/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.322E24/3", formula);
+
+ cell.setCellFormula("1.3E1/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "13.0/3", formula);
+
+ cell.setCellFormula("-1.3E1/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-13.0/3", formula);
+
+ cell.setCellFormula("1.3E-4/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1.3E-4/3", formula);
+
+ cell.setCellFormula("-1.3E-4/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.3E-4/3", formula);
+
+ cell.setCellFormula("13E-15/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1.3E-14/3", formula);
+
+ cell.setCellFormula("-13E-15/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.3E-14/3", formula);
+
+ cell.setCellFormula("1.3E3/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1300.0/3", formula);
+
+ cell.setCellFormula("-1.3E3/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1300.0/3", formula);
+
+ cell.setCellFormula("1300000000000000/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "1.3E15/3", formula);
+
+ cell.setCellFormula("-1300000000000000/3");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.3E15/3", formula);
+
+ cell.setCellFormula("-10E-1/3.1E2*4E3/3E4");
+ formula = cell.getCellFormula();
+ assertEquals("Exponential formula string", "-1.0/310.0*4000.0/30000.0", formula);
+ }
+
public static void main(String [] args) {
System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
junit.textui.TestRunner.run(TestFormulaParser.class);