aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/formula/functions
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-09-01 23:10:43 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-09-01 23:10:43 +0000
commit2b7c0ef3ddcc448ecba72e8a2187b4797248d863 (patch)
tree166554331b5675a0400554914dfca73a5a77a624 /src/testcases/org/apache/poi/ss/formula/functions
parent82bbbed2b504dc965fcdd7fabe0eb24f0a9edd50 (diff)
downloadpoi-2b7c0ef3ddcc448ecba72e8a2187b4797248d863.tar.gz
poi-2b7c0ef3ddcc448ecba72e8a2187b4797248d863.zip
Fix DAYS360 for US/EU handling
fix forbidden api calls add TimeZone (user) override to DateUtil fix a few left open resources in the junit tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700686 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula/functions')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java82
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java102
2 files changed, 85 insertions, 99 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java b/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java
index 05c8a9bbd6..272c51a398 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java
@@ -17,51 +17,47 @@
package org.apache.poi.ss.formula.functions;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Direct tests for all implementors of <code>Function</code>.
- *
- * @author Josh Micich
*/
-public final class AllIndividualFunctionEvaluationTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllIndividualFunctionEvaluationTests.class.getName());
- result.addTestSuite(TestAverage.class);
- result.addTestSuite(TestCountFuncs.class);
- result.addTestSuite(TestDate.class);
- result.addTestSuite(TestDays360.class);
- result.addTestSuite(TestFinanceLib.class);
- result.addTestSuite(TestFind.class);
- result.addTestSuite(TestIndex.class);
- result.addTestSuite(TestIndexFunctionFromSpreadsheet.class);
- result.addTestSuite(TestIndirect.class);
- result.addTestSuite(TestIsBlank.class);
- result.addTestSuite(TestLen.class);
- result.addTestSuite(TestLookupFunctionsFromSpreadsheet.class);
- result.addTestSuite(TestMatch.class);
- result.addTestSuite(TestMathX.class);
- result.addTestSuite(TestMid.class);
- result.addTestSuite(TestNper.class);
- result.addTestSuite(TestOffset.class);
- result.addTestSuite(TestPmt.class);
- result.addTestSuite(TestRoundFuncs.class);
- result.addTestSuite(TestRowCol.class);
- result.addTestSuite(TestStatsLib.class);
- result.addTestSuite(TestSubtotal.class);
- result.addTestSuite(TestSumif.class);
- result.addTestSuite(TestSumproduct.class);
- result.addTestSuite(TestText.class);
- result.addTestSuite(TestTFunc.class);
- result.addTestSuite(TestTime.class);
- result.addTestSuite(TestTrim.class);
- result.addTestSuite(TestTrunc.class);
- result.addTestSuite(TestValue.class);
- result.addTestSuite(TestXYNumericFunction.class);
- result.addTestSuite(TestAddress.class);
- result.addTestSuite(TestClean.class);
- return result;
- }
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestAverage.class,
+ TestCountFuncs.class,
+ TestDate.class,
+ TestDays360.class,
+ TestFinanceLib.class,
+ TestFind.class,
+ TestIndex.class,
+ TestIndexFunctionFromSpreadsheet.class,
+ TestIndirect.class,
+ TestIsBlank.class,
+ TestLen.class,
+ TestLookupFunctionsFromSpreadsheet.class,
+ TestMatch.class,
+ TestMathX.class,
+ TestMid.class,
+ TestNper.class,
+ TestOffset.class,
+ TestPmt.class,
+ TestRoundFuncs.class,
+ TestRowCol.class,
+ TestStatsLib.class,
+ TestSubtotal.class,
+ TestSumif.class,
+ TestSumproduct.class,
+ TestText.class,
+ TestTFunc.class,
+ TestTime.class,
+ TestTrim.class,
+ TestTrunc.class,
+ TestValue.class,
+ TestXYNumericFunction.class,
+ TestAddress.class,
+ TestClean.class
+})
+public class AllIndividualFunctionEvaluationTests {
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
index db39c09c32..29fabef20f 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
@@ -17,52 +17,38 @@
package org.apache.poi.ss.formula.functions;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Locale;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.junit.Test;
-/**
- * @author Josh Micich
- */
-public final class TestDays360 extends TestCase {
+public final class TestDays360 {
/**
* @param month 1-based
*/
private static Date makeDate(int year, int month, int day) {
-
- Calendar cal = new GregorianCalendar(year, month-1, day, 0, 0, 0);
+ Calendar cal = Calendar.getInstance(Locale.ROOT);
+ cal.set(year, month-1, day, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
+
private static Date decrementDay(Date d) {
- Calendar c = new GregorianCalendar(Locale.ROOT);
- c.setTimeInMillis(d.getTime());
+ Calendar c = (Calendar)d.clone();
c.add(Calendar.DAY_OF_MONTH, -1);
return c.getTime();
}
- private static String fmt(Date d) {
- Calendar c = new GregorianCalendar(Locale.ROOT);
- c.setTimeInMillis(d.getTime());
- StringBuilder sb = new StringBuilder();
- sb.append(c.get(Calendar.YEAR));
- sb.append("/");
- sb.append(c.get(Calendar.MONTH)+1);
- sb.append("/");
- sb.append(c.get(Calendar.DAY_OF_MONTH));
- return sb.toString();
- }
-
+ @Test
public void testBasic() {
confirm(120, 2009, 1, 15, 2009, 5, 15);
confirm(158, 2009, 1, 26, 2009, 7, 4);
@@ -74,37 +60,47 @@ public final class TestDays360 extends TestCase {
// longer time spans
confirm(562, 2008, 8, 11, 2010, 3, 3);
confirm(916, 2007, 2, 23, 2009, 9, 9);
+
+ // other tests
+ confirm(1, makeDate(1993, 2, 28), makeDate(1993, 3, 1), false);
+ confirm(1, makeDate(1996, 2, 29), makeDate(1996, 3, 1), false);
+ confirm(-2, makeDate(1993, 2, 28), makeDate(1993, 2, 28), false);
+ confirm(3, makeDate(1993, 2, 28), makeDate(1993, 3, 1), true);
+ confirm(2, makeDate(1996, 2, 29), makeDate(1996, 3, 1), true);
}
private static void confirm(int expResult, int y1, int m1, int d1, int y2, int m2, int d2) {
confirm(expResult, makeDate(y1, m1, d1), makeDate(y2, m2, d2), false);
confirm(-expResult, makeDate(y2, m2, d2), makeDate(y1, m1, d1), false);
-
}
+
/**
* The <tt>method</tt> parameter only makes a difference when the second parameter
* is the last day of the month that does <em>not</em> have 30 days.
*/
- public void DISABLED_testMonthBoundaries() {
+ @Test
+ public void testMonthBoundaries() {
// jan
- confirmMonthBoundary(false, 1, 0, 0, 2, 3, 4);
- confirmMonthBoundary(true, 1, 0, 0, 1, 3, 4);
+ confirmMonthBoundary(false, 2001, 1, 0, 0, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 1, 0, 0, 1, 2, 3);
// feb
- confirmMonthBoundary(false, 2,-2, 1, 2, 3, 4);
- confirmMonthBoundary(true, 2, 0, 1, 2, 3, 4);
+ confirmMonthBoundary(false, 2001, 2,-2, 1, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 2, 0, 1, 2, 3, 4);
// mar
- confirmMonthBoundary(false, 3, 0, 0, 2, 3, 4);
- confirmMonthBoundary(true, 3, 0, 0, 1, 3, 4);
+ confirmMonthBoundary(false, 2001, 3, 0, 0, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 3, 0, 0, 1, 2, 3);
// apr
- confirmMonthBoundary(false, 4, 0, 1, 2, 3, 4);
- confirmMonthBoundary(true, 4, 0, 1, 2, 3, 4);
+ confirmMonthBoundary(false, 2001, 4, 0, 1, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 4, 0, 1, 2, 3, 4);
// may
- confirmMonthBoundary(false, 5, 0, 0, 2, 3, 4);
- confirmMonthBoundary(true, 5, 0, 0, 1, 3, 4);
+ confirmMonthBoundary(false, 2001, 5, 0, 0, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 5, 0, 0, 1, 2, 3);
// jun
- confirmMonthBoundary(false, 6, 0, 1, 2, 3, 4);
- confirmMonthBoundary(true, 6, 0, 1, 2, 3, 4);
- // etc...
+ confirmMonthBoundary(false, 2001, 6, 0, 1, 2, 3, 4);
+ confirmMonthBoundary(true, 2001, 6, 0, 1, 2, 3, 4);
+ // leap year
+ confirmMonthBoundary(false, 2012, 2, -1, 1, 2, 3, 4);
+ confirmMonthBoundary(true, 2012, 2, 0, 1, 2, 3, 4);
}
@@ -112,13 +108,12 @@ public final class TestDays360 extends TestCase {
* @param monthNo 1-based
* @param diffs
*/
- private static void confirmMonthBoundary(boolean method, int monthNo, int...diffs) {
- Date firstDayOfNextMonth = makeDate(2001, monthNo+1, 1);
+ private static void confirmMonthBoundary(boolean method, int year, int monthNo, int...diffs) {
+ Date firstDayOfNextMonth = makeDate(year, monthNo+1, 1);
Date secondArg = decrementDay(firstDayOfNextMonth);
Date firstArg = secondArg;
- for (int i = 0; i < diffs.length; i++) {
- int expResult = diffs[i];
+ for (int expResult : diffs) {
confirm(expResult, firstArg, secondArg, method);
firstArg = decrementDay(firstArg);
}
@@ -133,22 +128,17 @@ public final class TestDays360 extends TestCase {
} else {
ve = invokeDays360(convert(firstArg), convert(secondArg));
}
- if (ve instanceof NumberEval) {
-
- NumberEval numberEval = (NumberEval) ve;
- if (numberEval.getNumberValue() != expResult) {
- throw new AssertionFailedError(fmt(firstArg) + " " + fmt(secondArg) + " " + method +
- " wrong result got (" + numberEval.getNumberValue()
- + ") but expected (" + expResult + ")");
- }
- // System.err.println(fmt(firstArg) + " " + fmt(secondArg) + " " + method + " success got (" + expResult + ")");
- return;
- }
- throw new AssertionFailedError("wrong return type (" + ve.getClass().getName() + ")");
+ assertTrue("wrong return type (" + ve.getClass().getName() + ")", ve instanceof NumberEval);
+
+ NumberEval numberEval = (NumberEval) ve;
+ String err = String.format(Locale.ROOT, "days360(%tF,%tF,%b) wrong result", firstArg, secondArg, method);
+ assertEquals(err, expResult, numberEval.getNumberValue(), 0);
}
+
private static ValueEval invokeDays360(ValueEval...args) {
return new Days360().evaluate(args, -1, -1);
}
+
private static NumberEval convert(Date d) {
return new NumberEval(HSSFDateUtil.getExcelDate(d));
}