diff options
author | Andrew C. Oliver <acoliver@apache.org> | 2002-05-01 01:11:05 +0000 |
---|---|---|
committer | Andrew C. Oliver <acoliver@apache.org> | 2002-05-01 01:11:05 +0000 |
commit | 4782d498a4bf8f3e2b2f70979e857d769892c8a5 (patch) | |
tree | f031c0870b0cb4f07f48abc8a533a613993a3207 /src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java | |
parent | a4e8ddc09d62e7a101b2ca071150b06f7c21a6fe (diff) | |
download | poi-4782d498a4bf8f3e2b2f70979e857d769892c8a5.tar.gz poi-4782d498a4bf8f3e2b2f70979e857d769892c8a5.zip |
oops left off avik's test case
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352572 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java | 97 |
1 files changed, 73 insertions, 24 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index e842f5b54a..6dd9c66728 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -206,41 +206,90 @@ extends TestCase { * */ public void testFloat() - throws Exception { - String operator = "+"; - short rownum = 0; - File file = File.createTempFile("testFormulaFloat",".xls"); - FileOutputStream out = new FileOutputStream(file); - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFCell c = null; - - for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { - r = s.createRow((short) x); - - for (short y = 1; y < 256 && y > 0; y++) { - - c = r.createCell((short) y); - c.setCellFormula("" + (100*x)+"."+y + operator + (10000*y) + - "."+x); + throws Exception { + floatTest("*"); + floatTest("/"); + } - - } + private void floatTest(String operator) + throws Exception { + short rownum = 0; + File file = File.createTempFile("testFormulaFloat",".xls"); + FileOutputStream out = new FileOutputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet(); + HSSFRow r = null; + HSSFCell c = null; + + //get our minimum values + + r = s.createRow((short)0); + c = r.createCell((short)1); + c.setCellFormula(""+Float.MIN_VALUE + operator + Float.MIN_VALUE); + + for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2) ) { + r = s.createRow((short) x); + + for (short y = 1; y < 256 && y > 0; y= (short) (y +2)) { + + c = r.createCell((short) y); + c.setCellFormula("" + x+"."+y + operator + y +"."+x); + + } + } + if (s.getLastRowNum() < Short.MAX_VALUE) { + r = s.createRow((short)0); + c = r.createCell((short)0); + c.setCellFormula("" + Float.MAX_VALUE + operator + Float.MAX_VALUE); + } + wb.write(out); + out.close(); + assertTrue("file exists",file.exists()); + out=null;wb=null; //otherwise we get out of memory error! + floatVerify(operator,file); + + } + + private void floatVerify(String operator, File file) + throws Exception { + short rownum = 0; + + FileInputStream in = new FileInputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(in); + HSSFSheet s = wb.getSheetAt(0); + HSSFRow r = null; + HSSFCell c = null; + + // dont know how to check correct result .. for the moment, we just verify that the file can be read. + + for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { + r = s.getRow((short) x); - wb.write(out); - out.close(); - assertTrue("file exists",file.exists()); - + for (short y = 1; y < 256 && y > 0; y=(short)(y+2)) { + c = r.getCell((short) y); + assertTrue("got a formula",c.getCellFormula()!=null); + + assertTrue("loop Formula is as expected "+x+"."+y+operator+y+"."+x+"!="+c.getCellFormula(),( + (""+x+"."+y+operator+y+"."+x).equals(c.getCellFormula()) )); + + } } + + in.close(); + assertTrue("file exists",file.exists()); + } public void testAreaSum() throws Exception { areaFunctionTest("SUM"); } + public void testAreaAverage() + throws Exception { + areaFunctionTest("AVERAGE"); + } private void operationRefTest(String operator) throws Exception { |