/* * FormulaFunction_DatePartTest.java * JUnit based test * * Created on August 9, 2006, 9:50 AM */ package com.accountingenhancements.formula; import com.accountingenhancements.common.SupportParameters; import junit.framework.*; import java.text.ParseException; import java.util.HashMap; /** * * @author lofgren */ public class FormulaFunction_DatePartTest extends TestCase { public FormulaFunction_DatePartTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(FormulaFunction_DatePartTest.class); return suite; } /** * Test of solve method, of class com.accountingenhancements.formula.FormulaFunction_DatePart. */ public void testFunction() throws Exception { System.out.println("function"); FormulaVariableList variableList = null; int iteration = 0; SupportParameters supportParameters = null; FormulaFunctionList functionList = null; int resolveEverythingAboveLevel = 0; FormulaVariable result; FormulaFunction instance = null; instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"d\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(3L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"m\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(2L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"y\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(2004L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"q\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(1L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"q\",4/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(2L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"q\",7/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(3L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"q\",11/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(4L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"dayofyear\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(34L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(3L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"sunday\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(3L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"monday\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(2L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"tue\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(1L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"wed\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(7L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"thursday\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(6L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"friday\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(5L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"weekday\",2/3/04,\"saturday\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(4L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/04)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(6L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/04,\"sunday\",\"FirstJan1\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(6L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/04,\"sunday\",3)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(6L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/04,\"sunday\",\"FirstFourDays\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(5L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/04,\"sunday\",4)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(5L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/03,\"sunday\",\"FirstFourDays\")",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(6L, result.getLong().longValue()); instance = new FormulaFunction_DatePart(new FormulaVariable("","DatePart(\"week\",2/3/03,\"sunday\",5)",0,true)); result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(5L, result.getLong().longValue()); } /** * Test of getName method, of class com.accountingenhancements.formula.FormulaFunction_DatePart. */ public void testGetName()throws Exception { System.out.println("getName"); Class thisClass = Class.forName("com.accountingenhancements.formula.FormulaFunction_DatePart"); String expResult = "DatePart"; String result = (String)thisClass.getMethod("getName").invoke(thisClass); assertTrue("Was: <"+result+"> Expected: <"+expResult+">",expResult.equals(result)); } /** * Test of getRequiredSupportParameters method, of class com.accountingenhancements.formula.FormulaFunction_DatePart. */ public void testGetRequiredSupportParameters()throws Exception { System.out.println("getRequiredSupportParameters"); String[][] result = FormulaFunction_DatePart.getRequiredSupportParameters(); assertEquals(0, result.length); } /** * Test of getRequiredFormulaVariables method, of class com.accountingenhancements.formula.FormulaFunction_DatePart. */ public void testGetRequiredFormulaVariables()throws Exception { System.out.println("getRequiredFormulaVariables"); String[][] result = FormulaFunction_DatePart.getRequiredFormulaVariables(); assertEquals(0, result.length); } /** * Test of getRequiredArguments method, of class com.accountingenhancements.formula.FormulaFunction_DatePart. */ public void testGetRequiredArguments()throws Exception { System.out.println("getRequiredArguments"); int i1,i2; String[][] requiredArguments = {{"ARG1: The Interval to be extracted. [Year, Quarter (1 through 4), Month (1 through 12), DayOfYear (1 through 366), Day (of month 1 though 31) , Weekday (1 through 7), Week (of year, 1 though 52)]","TYPE_STRING"},{"ARG2: The Date","TYPE_DATE"},{"ARG3(Optional): First day of week [(Sun)day, (Mon)day, (Tue)sday, (Wed)nesday, (Thu)rsday, (Fri)day, (Sat)urday], If not specified, Sunday is assumed. This WeekDay calculation only","TYPE_STRING"},{"ARG4(Optional): First week of year. [FirstJan1(Default), FirstFourDays (First week in which at least four days are in current year), FirstFullWeek (First full week in year)]. This can also be a number reflecting the minimum number of days required in the first week of the year where 1 = 1 day (default) and 7=full week. Affects current Week (of year) only","TYPE_STRING"}}; String expResult = null; String[][] result = FormulaFunction_DatePart.getRequiredArguments(); for(i1=0;i1