Lines 17-22
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.poi.hssf.model; |
18 |
package org.apache.poi.hssf.model; |
19 |
|
19 |
|
|
|
20 |
import java.io.FileOutputStream; |
21 |
|
20 |
import junit.framework.TestCase; |
22 |
import junit.framework.TestCase; |
21 |
|
23 |
|
22 |
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; |
24 |
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; |
Lines 38-43
Link Here
|
38 |
import org.apache.poi.hssf.record.formula.UnaryMinusPtg; |
40 |
import org.apache.poi.hssf.record.formula.UnaryMinusPtg; |
39 |
import org.apache.poi.hssf.record.formula.UnaryPlusPtg; |
41 |
import org.apache.poi.hssf.record.formula.UnaryPlusPtg; |
40 |
import org.apache.poi.hssf.usermodel.HSSFCell; |
42 |
import org.apache.poi.hssf.usermodel.HSSFCell; |
|
|
43 |
import org.apache.poi.hssf.usermodel.HSSFRichTextString; |
41 |
import org.apache.poi.hssf.usermodel.HSSFRow; |
44 |
import org.apache.poi.hssf.usermodel.HSSFRow; |
42 |
import org.apache.poi.hssf.usermodel.HSSFSheet; |
45 |
import org.apache.poi.hssf.usermodel.HSSFSheet; |
43 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
46 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
Lines 404-410
Link Here
|
404 |
|
407 |
|
405 |
} |
408 |
} |
406 |
|
409 |
|
407 |
public static void main(String [] args) { |
410 |
// bug 38396 : Formula with exponential numbers not parsed correctly. |
|
|
411 |
public void testExponentialParsing() { |
412 |
FormulaParser fp = new FormulaParser("1.3E21/2", null); |
413 |
fp.parse(); |
414 |
Ptg[] ptgs = fp.getRPNPtg(); |
415 |
assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); |
416 |
assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); |
417 |
assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); |
418 |
assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); |
419 |
|
420 |
fp = new FormulaParser("1322E21/2", null); |
421 |
fp.parse(); |
422 |
ptgs = fp.getRPNPtg(); |
423 |
assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); |
424 |
assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); |
425 |
assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); |
426 |
assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); |
427 |
|
428 |
fp = new FormulaParser("1.3E1/2", null); |
429 |
fp.parse(); |
430 |
ptgs = fp.getRPNPtg(); |
431 |
assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); |
432 |
assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); |
433 |
assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); |
434 |
assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); |
435 |
|
436 |
} |
437 |
public void testExponentialInSheet() throws Exception { |
438 |
HSSFWorkbook wb = new HSSFWorkbook(); |
439 |
|
440 |
wb.createSheet("Cash_Flow");; |
441 |
|
442 |
HSSFSheet sheet = wb.createSheet("Test"); |
443 |
HSSFRow row = sheet.createRow(0); |
444 |
HSSFCell cell = row.createCell((short)0); |
445 |
String formula = null; |
446 |
|
447 |
cell.setCellFormula("1.3E21/3"); |
448 |
formula = cell.getCellFormula(); |
449 |
assertEquals("Exponential formula string", "1.3E21/3", formula); |
450 |
|
451 |
cell.setCellFormula("1322E21/3"); |
452 |
formula = cell.getCellFormula(); |
453 |
assertEquals("Exponential formula string", "1.322E24/3", formula); |
454 |
|
455 |
cell.setCellFormula("1.3E1/3"); |
456 |
formula = cell.getCellFormula(); |
457 |
assertEquals("Exponential formula string", "13.0/3", formula); |
458 |
|
459 |
cell.setCellFormula("1.3E-4/3"); |
460 |
formula = cell.getCellFormula(); |
461 |
assertEquals("Exponential formula string", "1.3E-4/3", formula); |
462 |
|
463 |
cell.setCellFormula("13E-15/3"); |
464 |
formula = cell.getCellFormula(); |
465 |
assertEquals("Exponential formula string", "1.3E-14/3", formula); |
466 |
|
467 |
cell.setCellFormula("1.3E3/3"); |
468 |
formula = cell.getCellFormula(); |
469 |
assertEquals("Exponential formula string", "1300.0/3", formula); |
470 |
|
471 |
} |
472 |
|
473 |
public static void main(String [] args) { |
408 |
System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); |
474 |
System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); |
409 |
junit.textui.TestRunner.run(TestFormulaParser.class); |
475 |
junit.textui.TestRunner.run(TestFormulaParser.class); |
410 |
} |
476 |
} |