From 46e32166e46f93a32a9f30e8a4072670831b3e6b Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Wed, 1 May 2002 01:41:51 +0000 Subject: [PATCH] wow... I thought I was doing test first....but um...it turns out it already works. Avik ROCKS!!! git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352575 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/TestFormulas.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index aa049e082..437eaa431 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -291,6 +291,16 @@ extends TestCase { areaFunctionTest("AVERAGE"); } + public void testRefArraySum() + throws Exception { + refArrayFunctionTest("SUM"); + } + + public void testAreaArraySum() + throws Exception { + refAreaArrayFunctionTest("SUM"); + } + private void operationRefTest(String operator) @@ -609,6 +619,85 @@ extends TestCase { in.close(); } + /** + * Writes a function then tests to see if its correct + * + */ + public void refArrayFunctionTest(String function) + throws Exception { + + short rownum = 0; + File file = File.createTempFile("testFormulaArrayFunction"+function,".xls"); + FileOutputStream out = new FileOutputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet(); + HSSFRow r = null; + HSSFCell c = null; + + + r = s.createRow((short) 0); + + c = r.createCell((short) 0); + c.setCellFormula(function+"(A2,A3)"); + + + wb.write(out); + out.close(); + assertTrue("file exists",file.exists()); + + FileInputStream in = new FileInputStream(file); + wb = new HSSFWorkbook(in); + s = wb.getSheetAt(0); + r = s.getRow(0); + c = r.getCell((short)0); + + assertTrue("function ="+function+"(A2,A3)", + ( (function+"(A2,A3)").equals((function+"(A2,A3)")) ) + ); + in.close(); + } + + + /** + * Writes a function then tests to see if its correct + * + */ + public void refAreaArrayFunctionTest(String function) + throws Exception { + + short rownum = 0; + File file = File.createTempFile("testFormulaAreaArrayFunction"+function,".xls"); + FileOutputStream out = new FileOutputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet(); + HSSFRow r = null; + HSSFCell c = null; + + + r = s.createRow((short) 0); + + c = r.createCell((short) 0); + c.setCellFormula(function+"(A2:A4,B2:B4)"); + + + wb.write(out); + out.close(); + assertTrue("file exists",file.exists()); + + FileInputStream in = new FileInputStream(file); + wb = new HSSFWorkbook(in); + s = wb.getSheetAt(0); + r = s.getRow(0); + c = r.getCell((short)0); + + assertTrue("function ="+function+"(A2:A4,B2:B4)", + ( (function+"(A2:A4,B2:B4)").equals((function+"(A2:A4,B2:B4)")) ) + ); + in.close(); + } + + + public static void main(String [] args) { System.out