--- /dev/null
+package org.apache.poi.ss.formula.functions;\r
+\r
+import java.io.IOException;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellValue;\r
+import org.apache.poi.ss.usermodel.FormulaEvaluator;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
+import org.apache.poi.ss.util.CellReference;\r
+\r
+/**\r
+ * LogicalFunction unit tests.\r
+ */\r
+public class TestLogicalFunction extends TestCase {\r
+\r
+ private FormulaEvaluator evaluator;\r
+ private Row row3;\r
+ private Cell cell1;\r
+ private Cell cell2;\r
+\r
+ @Override\r
+ public void setUp() throws IOException {\r
+ Workbook wb = new HSSFWorkbook();\r
+ try {\r
+ buildWorkbook(wb);\r
+ } finally {\r
+ wb.close();\r
+ }\r
+ }\r
+\r
+ private void buildWorkbook(Workbook wb) {\r
+ Sheet sh = wb.createSheet();\r
+ Row row1 = sh.createRow(0);\r
+ Row row2 = sh.createRow(1);\r
+ row3 = sh.createRow(2);\r
+\r
+ row1.createCell(0, Cell.CELL_TYPE_NUMERIC);\r
+ row1.createCell(1, Cell.CELL_TYPE_NUMERIC);\r
+\r
+ row2.createCell(0, Cell.CELL_TYPE_NUMERIC);\r
+ row2.createCell(1, Cell.CELL_TYPE_NUMERIC);\r
+\r
+ row3.createCell(0);\r
+ row3.createCell(1);\r
+\r
+ CellReference a1 = new CellReference("A1");\r
+ CellReference a2 = new CellReference("A2");\r
+ CellReference b1 = new CellReference("B1");\r
+ CellReference b2 = new CellReference("B2");\r
+\r
+ sh.getRow(a1.getRow()).getCell(a1.getCol()).setCellValue(35);\r
+ sh.getRow(a2.getRow()).getCell(a2.getCol()).setCellValue(0);\r
+ sh.getRow(b1.getRow()).getCell(b1.getCol()).setCellFormula("A1/A2");\r
+ sh.getRow(b2.getRow()).getCell(b2.getCol()).setCellFormula("NA()");\r
+\r
+ evaluator = wb.getCreationHelper().createFormulaEvaluator();\r
+ }\r
+\r
+ public void testIsErr() {\r
+ cell1 = row3.createCell(0);\r
+ cell1.setCellFormula("ISERR(B1)"); // produces #DIV/0!\r
+ cell2 = row3.createCell(1);\r
+ cell2.setCellFormula("ISERR(B2)"); // produces #N/A\r
+\r
+ CellValue cell1Value = evaluator.evaluate(cell1);\r
+ CellValue cell2Value = evaluator.evaluate(cell2);\r
+\r
+ assertEquals(true, cell1Value.getBooleanValue());\r
+ assertEquals(false, cell2Value.getBooleanValue());\r
+ }\r
+\r
+ public void testIsError() {\r
+ cell1 = row3.createCell(0);\r
+ cell1.setCellFormula("ISERROR(B1)"); // produces #DIV/0!\r
+ cell2 = row3.createCell(1);\r
+ cell2.setCellFormula("ISERROR(B2)"); // produces #N/A\r
+\r
+ CellValue cell1Value = evaluator.evaluate(cell1);\r
+ CellValue cell2Value = evaluator.evaluate(cell2);\r
+\r
+ assertEquals(true, cell1Value.getBooleanValue());\r
+ assertEquals(true, cell2Value.getBooleanValue());\r
+ }\r
+}\r