/* * FormulaFunctionTest.java * JUnit based test * * Created on August 8, 2006, 11:53 AM */ package com.accountingenhancements.formula; import com.accountingenhancements.common.SupportParameters; import junit.framework.*; import java.text.ParseException; import java.util.*; /** * * @author lofgren */ public class FormulaFunctionTest extends TestCase { public FormulaFunctionTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(FormulaFunctionTest.class); return suite; } /** * Test of function method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testFunction() throws Exception { System.out.println("function"); FormulaVariableStack functionArgumentStack = null; FormulaVariableList variableList = null; int iteration = 0; SupportParameters supportParameters = null; FormulaFunctionList functionList = null; int resolveEverythingAboveLevel = 0; FormulaFunction instance = new FormulaFunction("5,4,3,2,1"); FormulaVariable expResult = null; FormulaVariable result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result); functionArgumentStack=instance.getFunctionArgumentStack(); result = instance.function(functionArgumentStack,variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result); } /** * Test of getName method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetName()throws Exception { System.out.println("getName"); String expResult = ""; String result = FormulaFunction.getName(); assertEquals(expResult, result); } /** * Test of getRequiredSupportParameters method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetRequiredSupportParameters()throws Exception { System.out.println("getRequiredSupportParameters"); String[][] result = FormulaFunction.getRequiredSupportParameters(); assertEquals(0,result.length); } /** * Test of getRequiredFormulaVariables method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetRequiredFormulaVariables()throws Exception { System.out.println("getRequiredFormulaVariables"); String[][] result = FormulaFunction.getRequiredFormulaVariables(); assertEquals(0, result.length); } /** * Test of getRequiredArguments method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetRequiredArguments()throws Exception { System.out.println("getRequiredArguments"); String[][] result = FormulaFunction.getRequiredArguments(); assertEquals(0, result.length); } /** * Test of getReturnValueDescription method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetReturnValueDescription()throws Exception { System.out.println("getReturnValueDescription"); String[] result = FormulaFunction.getReturnValueDescription(); assertEquals(0, result.length); } /** * Test of getFunctionArgumentStack method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetFunctionArgumentStack()throws Exception { System.out.println("getFunctionArgumentStack"); FormulaFunction instance = new FormulaFunction("5,4,3,2,1"); FormulaVariableStack result = instance.getFunctionArgumentStack(); assertNotNull(result); } /** * Test of setFunctionArgumentStack method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testSetFunctionArgumentStack()throws Exception { System.out.println("setFunctionArgumentStack"); FormulaVariableStack functionArgumentStack = new FormulaVariableStack(); FormulaFunction instance = new FormulaFunction("5,4,3,2,1"); instance.setFunctionArgumentStack(functionArgumentStack); assertEquals(functionArgumentStack,instance.getFunctionArgumentStack()); //Testing for whether it is the same object, not the same contents. } /** * Test of getFunctionArgumentStackFromFunctionVariable method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testGetFunctionArgumentStackFromFunctionVariable() throws Exception { System.out.println("getFunctionArgumentStackFromFunctionVariable"); FormulaVariable functionVariable = new FormulaVariable("","IIF(5!=4,3,2)",0,true); FormulaVariable argumentVariable; FormulaVariableStack result = FormulaFunction.getFunctionArgumentStackFromFunctionVariable(functionVariable); assertNotNull(result); assertEquals(3,result.size()); argumentVariable=result.get(0); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <5!=4>",argumentVariable.getString().equals("5!=4")); assertEquals(FormulaVariable.TYPE_FORMULA,argumentVariable.getVariableType()); argumentVariable=result.get(1); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <3",argumentVariable.getString().equals("3")); assertEquals(FormulaVariable.TYPE_LONG,argumentVariable.getVariableType()); argumentVariable=result.get(2); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <2>",argumentVariable.getString().equals("2")); assertEquals(FormulaVariable.TYPE_LONG,argumentVariable.getVariableType()); } /** * Test of parseCommaDelimitedFunctionFields method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testParseCommaDelimitedFunctionFields() throws Exception { System.out.println("parseCommaDelimitedFunctionFields"); String formulaSegment = "5!=4,3,2"; int level = 0; FormulaVariable argumentVariable; FormulaVariableStack result = FormulaFunction.parseCommaDelimitedFunctionFields(formulaSegment, level); assertNotNull(result); assertEquals(3,result.size()); argumentVariable=result.get(0); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <5!=4>",argumentVariable.getString().equals("5!=4")); argumentVariable=result.get(1); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <3",argumentVariable.getString().equals("3")); argumentVariable=result.get(2); assertNotNull(argumentVariable); assertTrue("Was: <"+argumentVariable.getString()+"> Expected: <2>",argumentVariable.getString().equals("2")); } /** * Test of solve method, of class com.accountingenhancements.formula.FormulaFunction. */ public void testSolve() throws Exception { System.out.println("solve"); FormulaVariableList variableList = null; int iteration = 0; SupportParameters supportParameters = null; FormulaFunctionList functionList = null; int resolveEverythingAboveLevel = 0; FormulaFunction instance = new FormulaFunction("5,4,3,2,1"); FormulaVariable expResult = null; FormulaVariable result = instance.solve(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result); } }