Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java Mon Dec 9 00:37:21 2019 @@ -20,16 +20,19 @@ */ package org.apache.poi.ss.formula.functions; +import static org.junit.Assert.assertTrue; + import org.apache.poi.ss.formula.functions.XYNumericFunction.Accumulator; +import org.junit.Test; /** * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * + * */ -@SuppressWarnings("ConstantConditions") public class TestMathX extends AbstractNumericTestCase { + @Test public void testAcosh() { double d; @@ -53,6 +56,7 @@ public class TestMathX extends AbstractN } + @Test public void testAsinh() { double d; @@ -79,6 +83,7 @@ public class TestMathX extends AbstractN } + @Test public void testAtanh() { double d; d = MathX.atanh(0); @@ -110,6 +115,7 @@ public class TestMathX extends AbstractN } + @Test public void testCosh() { double d; d = MathX.cosh(0); @@ -141,6 +147,7 @@ public class TestMathX extends AbstractN } + @Test public void testTanh() { double d; d = MathX.tanh(0); @@ -172,83 +179,86 @@ public class TestMathX extends AbstractN } + @Test public void testMax() { double[] d = new double[100]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + double m = MathX.max(d); assertEquals("Max ", 20.1, m); - + d = new double[1000]; m = MathX.max(d); assertEquals("Max ", 0, m); - - d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; + + d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1; d[8] = -9.1; d[9] = 10.1; d[10] = -11.1; d[11] = 12.1; d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1; - d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; + d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; m = MathX.max(d); assertEquals("Max ", 20.1, m); - + d = new double[20]; - d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; + d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1; d[8] = -9.1; d[9] = -10.1; d[10] = -11.1; d[11] = -12.1; d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1; - d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; + d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; m = MathX.max(d); assertEquals("Max ", -1.1, m); - + } + @Test public void testMin() { double[] d = new double[100]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + double m = MathX.min(d); assertEquals("Min ", 0, m); - + d = new double[20]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + m = MathX.min(d); assertEquals("Min ", 1.1, m); - + d = new double[1000]; m = MathX.min(d); assertEquals("Min ", 0, m); - - d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; + + d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1; d[8] = -9.1; d[9] = 10.1; d[10] = -11.1; d[11] = 12.1; d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1; - d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; + d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; m = MathX.min(d); assertEquals("Min ", -19.1, m); - + d = new double[20]; - d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; + d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1; d[8] = -9.1; d[9] = -10.1; d[10] = -11.1; d[11] = -12.1; d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1; - d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; + d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; m = MathX.min(d); assertEquals("Min ", -20.1, m); } + @Test public void testProduct() { assertEquals("Product ", 0, MathX.product(null)); assertEquals("Product ", 0, MathX.product(new double[] {})); @@ -259,41 +269,42 @@ public class TestMathX extends AbstractN assertEquals("Product ", 10, MathX.product(new double[] { 10, 1 })); assertEquals("Product ", -2, MathX.product(new double[] { 2, -1 })); assertEquals("Product ", 99988000209999d, MathX.product(new double[] { 99999, 99999, 9999 })); - + double[] d = new double[100]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + double m = MathX.product(d); assertEquals("Product ", 0, m); - + d = new double[20]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + m = MathX.product(d); assertEquals("Product ", 3459946360003355534d, m); - + d = new double[1000]; m = MathX.product(d); assertEquals("Product ", 0, m); - + d = new double[20]; - d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; + d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1; d[8] = -9.1; d[9] = -10.1; d[10] = -11.1; d[11] = -12.1; d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1; - d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; + d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; m = MathX.product(d); assertEquals("Product ", 3459946360003355534d, m); } + @Test public void testMod() { //example from Excel help @@ -315,106 +326,109 @@ public class TestMathX extends AbstractN assertEquals(1.0, MathX.mod(13, 12)); } + @Test public void testNChooseK() { int n=100; int k=50; double d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 1.00891344545564E29, d); - + n = -1; k = 1; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", Double.NaN, d); - + n = 1; k = -1; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", Double.NaN, d); - + n = 0; k = 1; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", Double.NaN, d); - + n = 1; k = 0; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 1, d); - + n = 10; k = 9; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 10, d); - + n = 10; k = 10; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 1, d); - + n = 10; k = 1; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 10, d); - + n = 1000; k = 1; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 1000, d); // awesome ;) - + n = 1000; k = 2; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 499500, d); // awesome ;) - + n = 13; k = 7; d = MathX.nChooseK(n, k); assertEquals("NChooseK ", 1716, d); - + } + @Test public void testSign() { final short minus = -1; final short zero = 0; final short plus = 1; double d; - - + + assertEquals("Sign ", minus, MathX.sign(minus)); assertEquals("Sign ", plus, MathX.sign(plus)); assertEquals("Sign ", zero, MathX.sign(zero)); - + d = 0; assertEquals("Sign ", zero, MathX.sign(d)); - + d = -1.000001; assertEquals("Sign ", minus, MathX.sign(d)); - + d = -.000001; assertEquals("Sign ", minus, MathX.sign(d)); - + d = -1E-200; assertEquals("Sign ", minus, MathX.sign(d)); - + d = Double.NEGATIVE_INFINITY; assertEquals("Sign ", minus, MathX.sign(d)); - + d = -200.11; assertEquals("Sign ", minus, MathX.sign(d)); - + d = -2000000000000.11; assertEquals("Sign ", minus, MathX.sign(d)); - + d = 1.000001; assertEquals("Sign ", plus, MathX.sign(d)); - + d = .000001; assertEquals("Sign ", plus, MathX.sign(d)); - + d = 1E-200; assertEquals("Sign ", plus, MathX.sign(d)); - + d = Double.POSITIVE_INFINITY; assertEquals("Sign ", plus, MathX.sign(d)); - + d = 200.11; assertEquals("Sign ", plus, MathX.sign(d)); - + d = 2000000000000.11; assertEquals("Sign ", plus, MathX.sign(d)); - + } + @Test public void testSinh() { double d; d = MathX.sinh(0); @@ -446,170 +460,176 @@ public class TestMathX extends AbstractN } + @Test public void testSum() { double[] d = new double[100]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + double s = MathX.sum(d); assertEquals("Sum ", 212, s); - + d = new double[1000]; s = MathX.sum(d); assertEquals("Sum ", 0, s); - - d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; + + d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1; d[8] = -9.1; d[9] = 10.1; d[10] = -11.1; d[11] = 12.1; d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1; - d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; + d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; s = MathX.sum(d); assertEquals("Sum ", 10, s); - - d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; + + d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1; d[8] = -9.1; d[9] = -10.1; d[10] = -11.1; d[11] = -12.1; d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1; - d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; + d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; s = MathX.sum(d); assertEquals("Sum ", -212, s); - + } + @Test public void testSumsq() { double[] d = new double[100]; - d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; + d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1; d[4] = 5.1; d[5] = 6.1; d[6] = 7.1; d[7] = 8.1; d[8] = 9.1; d[9] = 10.1; d[10] = 11.1; d[11] = 12.1; d[12] = 13.1; d[13] = 14.1; d[14] = 15.1; d[15] = 16.1; - d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; - + d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1; + double s = MathX.sumsq(d); assertEquals("Sumsq ", 2912.2, s); - + d = new double[1000]; s = MathX.sumsq(d); assertEquals("Sumsq ", 0, s); - - d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; + + d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1; d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1; d[8] = -9.1; d[9] = 10.1; d[10] = -11.1; d[11] = 12.1; d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1; - d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; + d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1; s = MathX.sumsq(d); assertEquals("Sumsq ", 2912.2, s); - - d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; + + d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1; d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1; d[8] = -9.1; d[9] = -10.1; d[10] = -11.1; d[11] = -12.1; d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1; - d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; + d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1; s = MathX.sumsq(d); assertEquals("Sumsq ", 2912.2, s); } + @Test public void testFactorial() { int n; double s; - + n = 0; s = MathX.factorial(n); assertEquals("Factorial ", 1, s); - + n = 1; s = MathX.factorial(n); assertEquals("Factorial ", 1, s); - + n = 10; s = MathX.factorial(n); assertEquals("Factorial ", 3628800, s); - + n = 99; s = MathX.factorial(n); assertEquals("Factorial ", 9.33262154439E+155, s); - + n = -1; s = MathX.factorial(n); assertEquals("Factorial ", Double.NaN, s); - + n = Integer.MAX_VALUE; s = MathX.factorial(n); assertEquals("Factorial ", Double.POSITIVE_INFINITY, s); } + @Test public void testSumx2my2() { double[] xarr; double[] yarr; - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumx2my2(xarr, yarr, 100); - + xarr = new double[]{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumx2my2(xarr, yarr, 100); - + xarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumx2my2(xarr, yarr, -100); - + xarr = new double[]{10}; yarr = new double[]{9}; confirmSumx2my2(xarr, yarr, 19); - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumx2my2(xarr, yarr, 0); } + @Test public void testSumx2py2() { double[] xarr; double[] yarr; - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumx2py2(xarr, yarr, 670); - + xarr = new double[]{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumx2py2(xarr, yarr, 670); - + xarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumx2py2(xarr, yarr, 670); - + xarr = new double[]{10}; yarr = new double[]{9}; confirmSumx2py2(xarr, yarr, 181); - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumx2py2(xarr, yarr, 770); } + @Test public void testSumxmy2() { double[] xarr; double[] yarr; - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumxmy2(xarr, yarr, 10); - + xarr = new double[]{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}; yarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; confirmSumxmy2(xarr, yarr, 1330); - + xarr = new double[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumxmy2(xarr, yarr, 10); - + xarr = new double[]{10}; yarr = new double[]{9}; confirmSumxmy2(xarr, yarr, 1); - + xarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; yarr = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; confirmSumxmy2(xarr, yarr, 0); @@ -631,64 +651,65 @@ public class TestMathX extends AbstractN for (int i = 0; i < xarr.length; i++) { result += acc.accumulate(xarr[i], yarr[i]); } - assertEquals(expectedResult, result, 0.0); + assertEquals(expectedResult, result); } - + + @Test public void testRound() { double d; int p; - + d = 0; p = 0; assertEquals("round ", 0, MathX.round(d, p)); - + d = 10; p = 0; assertEquals("round ", 10, MathX.round(d, p)); - + d = 123.23; p = 0; assertEquals("round ", 123, MathX.round(d, p)); - + d = -123.23; p = 0; assertEquals("round ", -123, MathX.round(d, p)); - + d = 123.12; p = 2; assertEquals("round ", 123.12, MathX.round(d, p)); - + d = 88.123459; p = 5; assertEquals("round ", 88.12346, MathX.round(d, p)); - + d = 0; p = 2; assertEquals("round ", 0, MathX.round(d, p)); - + d = 0; p = -1; assertEquals("round ", 0, MathX.round(d, p)); - + d = 0.01; p = -1; assertEquals("round ", 0, MathX.round(d, p)); d = 123.12; p = -2; assertEquals("round ", 100, MathX.round(d, p)); - + d = 88.123459; p = -3; assertEquals("round ", 0, MathX.round(d, p)); - + d = 49.00000001; p = -1; assertEquals("round ", 50, MathX.round(d, p)); - + d = 149.999999; p = -2; assertEquals("round ", 100, MathX.round(d, p)); - + d = 150.0; p = -2; assertEquals("round ", 200, MathX.round(d, p)); d = 2162.615d; p = 2; assertEquals("round ", 2162.62d, MathX.round(d, p)); - + d = 0.049999999999999975d; p = 2; assertEquals("round ", 0.05d, MathX.round(d, p)); d = 0.049999999999999975d; p = 1; assertEquals("round ", 0.1d, MathX.round(d, p)); - + d = Double.NaN; p = 1; assertEquals("round ", Double.NaN, MathX.round(d, p)); @@ -705,58 +726,59 @@ public class TestMathX extends AbstractN assertEquals("round ", 0.0d, MathX.round(d, p)); } + @Test public void testRoundDown() { double d; int p; - + d = 0; p = 0; assertEquals("roundDown ", 0, MathX.roundDown(d, p)); - + d = 10; p = 0; assertEquals("roundDown ", 10, MathX.roundDown(d, p)); - + d = 123.99; p = 0; assertEquals("roundDown ", 123, MathX.roundDown(d, p)); - + d = -123.99; p = 0; assertEquals("roundDown ", -123, MathX.roundDown(d, p)); - + d = 123.99; p = 2; assertEquals("roundDown ", 123.99, MathX.roundDown(d, p)); - + d = 88.123459; p = 5; assertEquals("roundDown ", 88.12345, MathX.roundDown(d, p)); - + d = 0; p = 2; assertEquals("roundDown ", 0, MathX.roundDown(d, p)); - + d = 0; p = -1; assertEquals("roundDown ", 0, MathX.roundDown(d, p)); - + d = 0.01; p = -1; assertEquals("roundDown ", 0, MathX.roundDown(d, p)); d = 199.12; p = -2; assertEquals("roundDown ", 100, MathX.roundDown(d, p)); - + d = 88.123459; p = -3; assertEquals("roundDown ", 0, MathX.roundDown(d, p)); - + d = 99.00000001; p = -1; assertEquals("roundDown ", 90, MathX.roundDown(d, p)); - + d = 100.00001; p = -2; assertEquals("roundDown ", 100, MathX.roundDown(d, p)); - + d = 150.0; p = -2; assertEquals("roundDown ", 100, MathX.roundDown(d, p)); - + d = 0.0499999999999975d; p = 2; assertEquals("roundDown ", 0.04d, MathX.roundDown(d, p)); d = 0.049999999999999975d; p = 1; assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p)); - + d = Double.NaN; p = 1; assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p)); @@ -776,58 +798,59 @@ public class TestMathX extends AbstractN assertEquals("roundDown ", 797.40, MathX.round(d, p)); } + @Test public void testRoundUp() { double d; int p; - + d = 0; p = 0; assertEquals("roundUp ", 0, MathX.roundUp(d, p)); - + d = 10; p = 0; assertEquals("roundUp ", 10, MathX.roundUp(d, p)); - + d = 123.23; p = 0; assertEquals("roundUp ", 124, MathX.roundUp(d, p)); - + d = -123.23; p = 0; assertEquals("roundUp ", -124, MathX.roundUp(d, p)); - + d = 123.12; p = 2; assertEquals("roundUp ", 123.12, MathX.roundUp(d, p)); - + d = 88.123459; p = 5; assertEquals("roundUp ", 88.12346, MathX.roundUp(d, p)); - + d = 0; p = 2; assertEquals("roundUp ", 0, MathX.roundUp(d, p)); - + d = 0; p = -1; assertEquals("roundUp ", 0, MathX.roundUp(d, p)); - + d = 0.01; p = -1; assertEquals("roundUp ", 10, MathX.roundUp(d, p)); d = 123.12; p = -2; assertEquals("roundUp ", 200, MathX.roundUp(d, p)); - + d = 88.123459; p = -3; assertEquals("roundUp ", 1000, MathX.roundUp(d, p)); - + d = 49.00000001; p = -1; assertEquals("roundUp ", 50, MathX.roundUp(d, p)); - + d = 149.999999; p = -2; assertEquals("roundUp ", 200, MathX.roundUp(d, p)); - + d = 150.0; p = -2; assertEquals("roundUp ", 200, MathX.roundUp(d, p)); - + d = 0.049999999999999975d; p = 2; assertEquals("roundUp ", 0.05d, MathX.roundUp(d, p)); d = 0.049999999999999975d; p = 1; assertEquals("roundUp ", 0.1d, MathX.roundUp(d, p)); - + d = Double.NaN; p = 1; assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p)); @@ -852,55 +875,56 @@ public class TestMathX extends AbstractN assertEquals("roundUp ", 797.40, MathX.roundUp(d, p)); } + @Test public void testCeiling() { double d; double s; - + d = 0; s = 0; assertEquals("ceiling ", 0, MathX.ceiling(d, s)); - + d = 1; s = 0; assertEquals("ceiling ", 0, MathX.ceiling(d, s)); - + d = 0; s = 1; assertEquals("ceiling ", 0, MathX.ceiling(d, s)); - + d = -1; s = 0; assertEquals("ceiling ", 0, MathX.ceiling(d, s)); - + d = 0; s = -1; assertEquals("ceiling ", 0, MathX.ceiling(d, s)); - + d = 10; s = 1.11; assertEquals("ceiling ", 11.1, MathX.ceiling(d, s)); - + d = 11.12333; s = 0.03499; assertEquals("ceiling ", 11.12682, MathX.ceiling(d, s)); - + d = -11.12333; s = 0.03499; assertEquals("ceiling ", Double.NaN, MathX.ceiling(d, s)); - + d = 11.12333; s = -0.03499; assertEquals("ceiling ", Double.NaN, MathX.ceiling(d, s)); - + d = -11.12333; s = -0.03499; assertEquals("ceiling ", -11.12682, MathX.ceiling(d, s)); - + d = 100; s = 0.001; assertEquals("ceiling ", 100, MathX.ceiling(d, s)); - + d = -0.001; s = -9.99; assertEquals("ceiling ", -9.99, MathX.ceiling(d, s)); - + d = 4.42; s = 0.05; assertEquals("ceiling ", 4.45, MathX.ceiling(d, s)); - + d = 0.05; s = 4.42; assertEquals("ceiling ", 4.42, MathX.ceiling(d, s)); - + d = 0.6666; s = 3.33; assertEquals("ceiling ", 3.33, MathX.ceiling(d, s)); - + d = 2d/3; s = 3.33; assertEquals("ceiling ", 3.33, MathX.ceiling(d, s)); @@ -937,55 +961,56 @@ public class TestMathX extends AbstractN assertEquals("ceiling ", -11.09183, MathX.ceiling(d, s)); } + @Test public void testFloor() { double d; double s; - + d = 0; s = 0; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = 1; s = 0; assertEquals("floor ", Double.NaN, MathX.floor(d, s)); - + d = 0; s = 1; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = -1; s = 0; assertEquals("floor ", Double.NaN, MathX.floor(d, s)); - + d = 0; s = -1; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = 10; s = 1.11; assertEquals("floor ", 9.99, MathX.floor(d, s)); - + d = 11.12333; s = 0.03499; assertEquals("floor ", 11.09183, MathX.floor(d, s)); - + d = -11.12333; s = 0.03499; assertEquals("floor ", Double.NaN, MathX.floor(d, s)); - + d = 11.12333; s = -0.03499; assertEquals("floor ", Double.NaN, MathX.floor(d, s)); - + d = -11.12333; s = -0.03499; assertEquals("floor ", -11.09183, MathX.floor(d, s)); - + d = 100; s = 0.001; assertEquals("floor ", 100, MathX.floor(d, s)); - + d = -0.001; s = -9.99; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = 4.42; s = 0.05; assertEquals("floor ", 4.4, MathX.floor(d, s)); - + d = 0.05; s = 4.42; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = 0.6666; s = 3.33; assertEquals("floor ", 0, MathX.floor(d, s)); - + d = 2d/3; s = 3.33; assertEquals("floor ", 0, MathX.floor(d, s));
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java Mon Dec 9 00:37:21 2019 @@ -17,7 +17,7 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; @@ -27,12 +27,14 @@ import org.apache.poi.ss.formula.eval.Nu import org.apache.poi.ss.formula.eval.RefEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + /** * Tests for Excel function MID() * * @author Josh Micich */ -public final class TestMid extends TestCase { +public final class TestMid { private static ValueEval invokeMid(ValueEval text, ValueEval startPos, ValueEval numChars) { @@ -52,6 +54,7 @@ public final class TestMid extends TestC assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); } + @Test public void testBasic() { confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(4), "lact"); @@ -60,6 +63,7 @@ public final class TestMid extends TestC /** * Valid cases where args are not precisely (string, int, int) but can be resolved OK. */ + @Test public void testUnusualArgs() { // startPos with fractional digits confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact"); @@ -86,6 +90,7 @@ public final class TestMid extends TestC /** * Extreme values for startPos and numChars */ + @Test public void testExtremes() { confirmMid(new StringEval("galactic"), new NumberEval(4), new NumberEval(400), "actic"); @@ -96,6 +101,7 @@ public final class TestMid extends TestC /** * All sorts of ways to make MID return defined errors. */ + @Test public void testErrors() { confirmMid(ErrorEval.NAME_INVALID, new NumberEval(3), new NumberEval(4), ErrorEval.NAME_INVALID); confirmMid(new StringEval("galactic"), ErrorEval.NAME_INVALID, new NumberEval(4), ErrorEval.NAME_INVALID); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java Mon Dec 9 00:37:21 2019 @@ -17,6 +17,9 @@ package org.apache.poi.ss.formula.functions; +import static org.junit.Assert.assertEquals; + +import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -27,19 +30,18 @@ import org.apache.poi.ss.formula.eval.Er import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests for {@link org.apache.poi.ss.formula.functions.Mirr} * * @author Carlos Delgado (carlos dot del dot est at gmail dot com) * @author Cedric Walter (cedric dot walter at gmail dot com) - * @see {@link org.apache.poi.ss.formula.functions.TestIrr} + * @see org.apache.poi.ss.formula.functions.TestIrr */ -public final class TestMirr extends TestCase { +public final class TestMirr { + @Test public void testMirr() { Mirr mirr = new Mirr(); double mirrValue; @@ -86,6 +88,7 @@ public final class TestMirr extends Test } + @Test public void testMirrErrors_expectDIV0() { Mirr mirr = new Mirr(); @@ -101,7 +104,7 @@ public final class TestMirr extends Test throw new AssertionFailedError("MIRR should failed with all these positives values"); } - + @Test public void testEvaluateInSheet() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); @@ -126,6 +129,7 @@ public final class TestMirr extends Test assertEquals(0.18736225093, res, 0.00000001); } + @Test public void testMirrFromSpreadsheet() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("mirrTest.xls"); HSSFSheet sheet = wb.getSheet("Mirr"); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java Mon Dec 9 00:37:21 2019 @@ -17,11 +17,17 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import junit.framework.AssertionFailedError; -import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellValue; +import org.junit.Test; /** * Tests for {@link Npv} @@ -29,8 +35,9 @@ import org.apache.poi.ss.usermodel.CellV * @author Marcel May * @see <a href="http://office.microsoft.com/en-us/excel-help/npv-HP005209199.aspx">Excel Help</a> */ -public final class TestNpv extends TestCase { +public final class TestNpv { + @Test public void testEvaluateInSheetExample2() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); @@ -52,7 +59,7 @@ public final class TestNpv extends TestC fe.clearAllCachedResultValues(); fe.evaluateFormulaCell(cell); double res = cell.getNumericCellValue(); - assertEquals(1922.06d, Math.round(res * 100d) / 100d); + assertEquals(1922.06d, Math.round(res * 100d) / 100d, 0); // Range cell.setCellFormula("NPV(A2, A4:A8)+A3"); @@ -60,13 +67,14 @@ public final class TestNpv extends TestC fe.clearAllCachedResultValues(); fe.evaluateFormulaCell(cell); res = cell.getNumericCellValue(); - assertEquals(1922.06d, Math.round(res * 100d) / 100d); + assertEquals(1922.06d, Math.round(res * 100d) / 100d, 0); } /** * evaluate formulas with NPV and compare the result with * the cached formula result pre-calculated by Excel */ + @Test public void testNpvFromSpreadsheet(){ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("IrrNpvTestCaseData.xls"); HSSFSheet sheet = wb.getSheet("IRR-NPV"); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java Mon Dec 9 00:37:21 2019 @@ -17,18 +17,20 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Tests for {@link org.apache.poi.ss.formula.functions.Oct2Dec} * * @author cedric dot walter @ gmail dot com */ -public final class TestOct2Dec extends TestCase { +public final class TestOct2Dec { private static ValueEval invokeValue(String number1) { ValueEval[] args = new ValueEval[] { new StringEval(number1) }; @@ -47,6 +49,7 @@ public final class TestOct2Dec extends T assertEquals(msg, numError, result); } + @Test public void testBasic() { confirmValue("Converts octal '' to decimal (0)", "", "0"); confirmValue("Converts octal 54 to decimal (44)", "54", "44"); @@ -55,6 +58,7 @@ public final class TestOct2Dec extends T confirmValue("Converts octal 7776667533 to decimal (-299173)", "7776667533", "-299173"); } + @Test public void testErrors() { confirmValueError("not a valid octal number","ABCDEFGH", ErrorEval.NUM_ERROR); confirmValueError("not a valid octal number","99999999", ErrorEval.NUM_ERROR); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java Mon Dec 9 00:37:21 2019 @@ -17,10 +17,12 @@ package org.apache.poi.ss.formula.functions; -import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.eval.EvaluationException; @@ -29,19 +31,20 @@ import org.apache.poi.ss.formula.functio import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Test; /** * Tests for OFFSET function implementation * * @author Josh Micich */ -public final class TestOffset extends TestCase { +public final class TestOffset { private static void confirmDoubleConvert(double doubleVal, int expected) { try { assertEquals(expected, Offset.evaluateIntArg(new NumberEval(doubleVal), -1, -1)); } catch (EvaluationException e) { - throw new AssertionFailedError("Unexpected error '" + e.getErrorEval() + "'."); + fail("Unexpected error '" + e.getErrorEval() + "'."); } } /** @@ -50,6 +53,7 @@ public final class TestOffset extends Te * Fractional values are silently truncated. * Truncation is toward negative infinity. */ + @Test public void testDoubleConversion() { confirmDoubleConvert(100.09, 100); @@ -74,6 +78,7 @@ public final class TestOffset extends Te confirmDoubleConvert(-2.01, -3); } + @Test public void testLinearOffsetRange() { LinearOffsetRange lor; @@ -103,6 +108,7 @@ public final class TestOffset extends Te assertFalse(lor.isOutOfBounds(0, 65535)); } + @Test public void testOffsetWithEmpty23Arguments() throws IOException { try (Workbook workbook = new HSSFWorkbook()) { Cell cell = workbook.createSheet().createRow(0).createCell(0); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java Mon Dec 9 00:37:21 2019 @@ -19,23 +19,26 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Test cases for PPMT() * */ -public final class TestPPMT extends TestCase { +public final class TestPPMT { /** * http://office.microsoft.com/en-001/excel-help/ppmt-function-HP010342774.aspx */ + @Test public void testFromFile() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("finance.xls"); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java Mon Dec 9 00:37:21 2019 @@ -17,18 +17,19 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.BoolEval; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Tests for Excel function POISSON(x,mean,cumulative) * @author Kalpesh Parmar */ -public class TestPoisson extends TestCase { +public class TestPoisson { private static final double DELTA = 1E-15; @@ -43,6 +44,7 @@ public class TestPoisson extends TestCas return NumericFunction.POISSON.evaluate(valueEvals,-1,-1); } + @Test public void testCumulativeProbability() { double x = 1; @@ -54,17 +56,19 @@ public class TestPoisson extends TestCas assertEquals(myResult.getNumberValue(), result, DELTA); } + @Test public void testNonCumulativeProbability() { double x = 0; double mean = 0.2; double result = 0.8187307530779818; // known result - + NumberEval myResult = (NumberEval)invokePoisson(x,mean,false); assertEquals(myResult.getNumberValue(), result, DELTA); } + @Test public void testNegativeMean() { double x = 0; @@ -75,6 +79,7 @@ public class TestPoisson extends TestCas assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), myResult.getErrorCode()); } + @Test public void testNegativeX() { double x = -1; @@ -82,11 +87,10 @@ public class TestPoisson extends TestCas ErrorEval myResult = (ErrorEval)invokePoisson(x,mean,false); - assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), myResult.getErrorCode()); + assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), myResult.getErrorCode()); } - - + @Test public void testXAsDecimalNumber() { double x = 1.1; @@ -98,6 +102,7 @@ public class TestPoisson extends TestCas assertEquals(myResult.getNumberValue(), result, DELTA); } + @Test public void testXZeroMeanZero() { double x = 0; Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java Mon Dec 9 00:37:21 2019 @@ -16,18 +16,20 @@ ==================================================================== */ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Tests for {@link Quotient} * * @author cedric dot walter @ gmail dot com */ -public class TestQuotient extends TestCase { +public class TestQuotient { private static ValueEval invokeValue(String numerator, String denominator) { ValueEval[] args = new ValueEval[]{new StringEval(numerator), new StringEval(denominator)}; return new Quotient().evaluate(args, -1, -1); @@ -45,6 +47,7 @@ public class TestQuotient extends TestCa assertEquals(msg, numError, result); } + @Test public void testBasic() { confirmValue("Integer portion of 5/2 (2)", "5", "2", "2"); confirmValue("Integer portion of 4.5/3.1 (1)", "4.5", "3.1", "1"); @@ -55,6 +58,7 @@ public class TestQuotient extends TestCa confirmValue("Integer portion of Pi/Avogadro (0)", "3.14159", "6.02214179E+23", "0"); } + @Test public void testErrors() { confirmValueError("numerator is nonnumeric", "ABCD", "", ErrorEval.VALUE_INVALID); confirmValueError("denominator is nonnumeric", "", "ABCD", ErrorEval.VALUE_INVALID); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java Mon Dec 9 00:37:21 2019 @@ -19,19 +19,22 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellReference; +import org.junit.Test; /** * Test cases for RANK() */ -public final class TestRank extends TestCase { +public final class TestRank { + @Test public void testFromFile() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("rank.xls"); @@ -39,30 +42,30 @@ public final class TestRank extends Test HSSFSheet example1 = wb.getSheet("Example 1"); HSSFCell ex1cell1 = example1.getRow(7).getCell(0); - assertEquals(3.0, fe.evaluate(ex1cell1).getNumberValue()); + assertEquals(3.0, fe.evaluate(ex1cell1).getNumberValue(), 0); HSSFCell ex1cell2 = example1.getRow(8).getCell(0); - assertEquals(5.0, fe.evaluate(ex1cell2).getNumberValue()); + assertEquals(5.0, fe.evaluate(ex1cell2).getNumberValue(), 0); HSSFSheet example2 = wb.getSheet("Example 2"); for(int rownum = 1; rownum<= 10; rownum ++){ HSSFCell cell = example2.getRow(rownum).getCell(2); double cachedResult = cell.getNumericCellValue(); //cached formula result - assertEquals(cachedResult, fe.evaluate(cell).getNumberValue()); + assertEquals(cachedResult, fe.evaluate(cell).getNumberValue(), 0); } HSSFSheet example3 = wb.getSheet("Example 3"); for(int rownum = 1; rownum<= 10; rownum ++){ HSSFCell cellD = example3.getRow(rownum).getCell(3); double cachedResultD = cellD.getNumericCellValue(); //cached formula result - assertEquals(new CellReference(cellD).formatAsString(), cachedResultD, fe.evaluate(cellD).getNumberValue()); + assertEquals(new CellReference(cellD).formatAsString(), cachedResultD, fe.evaluate(cellD).getNumberValue(), 0); HSSFCell cellE = example3.getRow(rownum).getCell(4); double cachedResultE = cellE.getNumericCellValue(); //cached formula result - assertEquals(new CellReference(cellE).formatAsString(), cachedResultE, fe.evaluate(cellE).getNumberValue()); + assertEquals(new CellReference(cellE).formatAsString(), cachedResultE, fe.evaluate(cellE).getNumberValue(), 0); HSSFCell cellF = example3.getRow(rownum).getCell(5); double cachedResultF = cellF.getNumericCellValue(); //cached formula result - assertEquals(new CellReference(cellF).formatAsString(), cachedResultF, fe.evaluate(cellF).getNumberValue()); + assertEquals(new CellReference(cellF).formatAsString(), cachedResultF, fe.evaluate(cellF).getNumberValue(), 0); } } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java Mon Dec 9 00:37:21 2019 @@ -16,19 +16,18 @@ ==================================================================== */ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; -import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.formula.CacheAreaEval; -import org.apache.poi.ss.formula.eval.*; -import org.apache.poi.ss.usermodel.CellValue; - import static org.junit.Assert.assertEquals; -public class TestRelationalOperations extends TestCase { +import org.apache.poi.ss.formula.CacheAreaEval; +import org.apache.poi.ss.formula.eval.BoolEval; +import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NumberEval; +import org.apache.poi.ss.formula.eval.RelationalOperationEval; +import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + +public class TestRelationalOperations { /** * (1, 1)(1, 1) = 1 @@ -38,6 +37,7 @@ public class TestRelationalOperations ex * (TRUE, TRUE)(TRUE, TRUE) * */ + @Test public void testEqMatrixByScalar_Numbers() { ValueEval[] values = new ValueEval[4]; for (int i = 0; i < values.length; i++) { @@ -61,6 +61,7 @@ public class TestRelationalOperations ex } } + @Test public void testEqMatrixByScalar_String() { ValueEval[] values = new ValueEval[4]; for (int i = 0; i < values.length; i++) { @@ -83,6 +84,7 @@ public class TestRelationalOperations ex } } + @Test public void testEqMatrixBy_Row() { ValueEval[] matrix = { new NumberEval(-1), new NumberEval(1), @@ -116,6 +118,7 @@ public class TestRelationalOperations ex } } + @Test public void testEqMatrixBy_Column() { ValueEval[] matrix = { new NumberEval(-1), new NumberEval(1), @@ -152,6 +155,7 @@ public class TestRelationalOperations ex } } + @Test public void testEqMatrixBy_Matrix() { // A1:B2 ValueEval[] matrix1 = { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java Mon Dec 9 00:37:21 2019 @@ -17,17 +17,19 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Tests for ROW(), ROWS(), COLUMN(), COLUMNS() * * @author Josh Micich */ -public final class TestRowCol extends TestCase { +public final class TestRowCol { + @Test public void testCol() { Function target = new Column(); { @@ -42,6 +44,7 @@ public final class TestRowCol extends Te } } + @Test public void testRow() { Function target = new RowFunc(); { @@ -56,6 +59,7 @@ public final class TestRowCol extends Te } } + @Test public void testColumns() { confirmColumnsFunc("A1:F1", 6, 1); @@ -68,6 +72,7 @@ public final class TestRowCol extends Te assertEquals(1, actual, 0D); } + @Test public void testRows() { confirmRowsFunc("A1:F1", 6, 1); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java Mon Dec 9 00:37:21 2019 @@ -19,17 +19,19 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + /** * Test for Excel function SLOPE() * * @author Johan Karlsteen */ -public final class TestSlope extends TestCase { +public final class TestSlope { private static final Function SLOPE = new Slope(); private static ValueEval invoke(Function function, ValueEval xArray, ValueEval yArray) { @@ -52,6 +54,7 @@ public final class TestSlope extends Tes confirmError(SLOPE, xArray, yArray, expectedError); } + @Test public void testBasic() { Double exp = Math.pow(10, 7.5); ValueEval[] yValues = { @@ -80,6 +83,7 @@ public final class TestSlope extends Tes /** * number of items in array is not limited to 30 */ + @Test public void testLargeArrays() { ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1] yValues[0] = new NumberEval(2.0); // Changes first element to 2 @@ -102,6 +106,7 @@ public final class TestSlope extends Tes return EvalFactory.createAreaEval(refStr, values); } + @Test public void testErrors() { ValueEval[] xValues = { ErrorEval.REF_INVALID, Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java Mon Dec 9 00:37:21 2019 @@ -21,9 +21,10 @@ package org.apache.poi.ss.formula.functions; import junit.framework.AssertionFailedError; - import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; +import org.junit.Assert; +import org.junit.Test; /** @@ -32,70 +33,72 @@ import org.apache.poi.ss.formula.eval.Ev */ public class TestStatsLib extends AbstractNumericTestCase { + @Test public void testDevsq() { double[] v = null; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.devsq(v); x = 82.5; assertEquals("devsq ", x, d); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; d = StatsLib.devsq(v); x = 0; assertEquals("devsq ", x, d); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; d = StatsLib.devsq(v); x = 0; assertEquals("devsq ", x, d); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; d = StatsLib.devsq(v); x = 2.5; assertEquals("devsq ", x, d); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; d = StatsLib.devsq(v); x = 10953.7416965767; assertEquals("devsq ", x, d); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.devsq(v); x = 82.5; assertEquals("devsq ", x, d); } + @Test public void testKthLargest() { double[] v = null; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.kthLargest(v, 3); x = 8; assertEquals("kthLargest ", x, d); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; d = StatsLib.kthLargest(v, 3); x = 1; assertEquals("kthLargest ", x, d); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; d = StatsLib.kthLargest(v, 3); x = 0; assertEquals("kthLargest ", x, d); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; d = StatsLib.kthLargest(v, 3); x = 2; assertEquals("kthLargest ", x, d); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; d = StatsLib.kthLargest(v, 3); x = 5.37828; assertEquals("kthLargest ", x, d); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.kthLargest(v, 3); x = -3; @@ -105,117 +108,122 @@ public class TestStatsLib extends Abstra public void testKthSmallest() { } + @Test public void testAvedev() { double[] v = null; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.avedev(v); x = 2.5; assertEquals("avedev ", x, d); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; d = StatsLib.avedev(v); x = 0; assertEquals("avedev ", x, d); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; d = StatsLib.avedev(v); x = 0; assertEquals("avedev ", x, d); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; d = StatsLib.avedev(v); x = 0.5; assertEquals("avedev ", x, d); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; d = StatsLib.avedev(v); x = 36.42176053333; assertEquals("avedev ", x, d); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.avedev(v); x = 2.5; assertEquals("avedev ", x, d); } + @Test public void testMedian() { double[] v = null; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.median(v); x = 5.5; assertEquals("median ", x, d); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; d = StatsLib.median(v); x = 1; assertEquals("median ", x, d); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; d = StatsLib.median(v); x = 0; assertEquals("median ", x, d); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; d = StatsLib.median(v); x = 1.5; assertEquals("median ", x, d); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; d = StatsLib.median(v); x = 5.37828; assertEquals("median ", x, d); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.median(v); x = -5.5; assertEquals("median ", x, d); - + v = new double[] {-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.median(v); x = -6; assertEquals("median ", x, d); - + v = new double[] {1,2,3,4,5,6,7,8,9}; d = StatsLib.median(v); x = 5; assertEquals("median ", x, d); } + @Test public void testMode() { double[] v; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; confirmMode(v, null); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; confirmMode(v, 1.0); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; confirmMode(v, 0.0); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; confirmMode(v, 1.0); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; confirmMode(v, null); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; confirmMode(v, null); - + v = new double[] {1,2,3,4,1,1,1,1,0,0,0,0,0}; confirmMode(v, 1.0); - + v = new double[] {0,1,2,3,4,1,1,1,0,0,0,0,1}; confirmMode(v, 0.0); } + private static void confirmMode(double[] v, double expectedResult) { confirmMode(v, new Double(expectedResult)); } + private static void confirmMode(double[] v, Double expectedResult) { double actual; try { @@ -225,50 +233,51 @@ public class TestStatsLib extends Abstra } } catch (EvaluationException e) { if (expectedResult == null) { - assertEquals(ErrorEval.NA, e.getErrorEval()); + Assert.assertEquals(ErrorEval.NA, e.getErrorEval()); return; } throw new RuntimeException(e); } assertEquals("mode", expectedResult.doubleValue(), actual); } - + @Test public void testStddev() { double[] v = null; double d, x = 0; - + v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.stdev(v); x = 3.02765035410; assertEquals("stdev ", x, d); - + v = new double[] {1,1,1,1,1,1,1,1,1,1}; d = StatsLib.stdev(v); x = 0; assertEquals("stdev ", x, d); - + v = new double[] {0,0,0,0,0,0,0,0,0,0}; d = StatsLib.stdev(v); x = 0; assertEquals("stdev ", x, d); - + v = new double[] {1,2,1,2,1,2,1,2,1,2}; d = StatsLib.stdev(v); x = 0.52704627669; assertEquals("stdev ", x, d); - + v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999}; d = StatsLib.stdev(v); x = 52.33006233652; assertEquals("stdev ", x, d); - + v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; d = StatsLib.stdev(v); x = 3.02765035410; assertEquals("stdev ", x, d); } + @Test public void testVar() { double[] v = null; double d, x = 0; @@ -294,6 +303,7 @@ public class TestStatsLib extends Abstra assertEquals("var ", x, d); } + @Test public void testVarp() { double[] v = null; double d, x = 0; Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java Mon Dec 9 00:37:21 2019 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import junit.framework.AssertionFailedError; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -27,13 +27,14 @@ import org.apache.poi.ss.formula.eval.Nu import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Test cases for SUMPRODUCT() * * @author Josh Micich */ -public final class TestSumif extends TestCase { +public final class TestSumif { private static final NumberEval _30 = new NumberEval(30); private static final NumberEval _40 = new NumberEval(40); private static final NumberEval _50 = new NumberEval(50); @@ -42,6 +43,7 @@ public final class TestSumif extends Tes private static ValueEval invokeSumif(int rowIx, int colIx, ValueEval...args) { return new Sumif().evaluate(args, rowIx, colIx); } + private static void confirmDouble(double expected, ValueEval actualEval) { if(!(actualEval instanceof NumericValueEval)) { throw new AssertionFailedError("Expected numeric result"); @@ -50,6 +52,7 @@ public final class TestSumif extends Tes assertEquals(expected, nve.getNumberValue(), 0); } + @Test public void testBasic() { ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 }; ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 }; @@ -70,7 +73,7 @@ public final class TestSumif extends Tes confirm(140.0, arg0, new StringEval("<=40.0")); confirm(160.0, arg0, new StringEval("<>40.0")); confirm(80.0, arg0, new StringEval("=40.0")); - + } private static void confirm(double expectedResult, ValueEval...args) { @@ -81,6 +84,7 @@ public final class TestSumif extends Tes /** * test for bug observed near svn r882931 */ + @Test public void testCriteriaArgRange() { ValueEval[] arg0values = new ValueEval[] { _50, _60, _50, _50, _50, _30, }; ValueEval[] arg1values = new ValueEval[] { _30, _40, _50, _60, }; @@ -110,6 +114,7 @@ public final class TestSumif extends Tes confirmDouble(60, ve); } + @Test public void testEvaluateException() { assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, BlankEval.instance, new NumberEval(30.0))); assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, BlankEval.instance, new NumberEval(30.0), new NumberEval(30.0))); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java Mon Dec 9 00:37:21 2019 @@ -19,26 +19,36 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.OperationEvaluationContext; -import org.apache.poi.ss.formula.eval.*; +import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NumberEval; +import org.apache.poi.ss.formula.eval.NumericValueEval; +import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Test cases for SUMIFS() * * @author Yegor Kozlov */ -public final class TestSumifs extends TestCase { +public final class TestSumifs { private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null); private static ValueEval invokeSumifs(ValueEval[] args, OperationEvaluationContext ec) { return new Sumifs().evaluate(args, EC); } + private static void confirmDouble(double expected, ValueEval actualEval) { if(!(actualEval instanceof NumericValueEval)) { throw new AssertionFailedError("Expected numeric result"); @@ -55,6 +65,7 @@ public final class TestSumifs extends Te * Example 1 from * http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx */ + @Test public void testExample1() { // mimic test sample from http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx ValueEval[] a2a9 = new ValueEval[] { @@ -137,6 +148,7 @@ public final class TestSumifs extends Te * Example 2 from * http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx */ + @Test public void testExample2() { ValueEval[] b2e2 = new ValueEval[] { new NumberEval(100), @@ -185,6 +197,7 @@ public final class TestSumifs extends Te * Example 3 from * http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx */ + @Test public void testExample3() { //3.3 0.8 5.5 5.5 ValueEval[] b2e2 = new ValueEval[] { @@ -228,6 +241,7 @@ public final class TestSumifs extends Te * * Criteria entered as reference and by using wildcard characters */ + @Test public void testFromFile() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("sumifs.xls"); @@ -236,18 +250,18 @@ public final class TestSumifs extends Te HSSFSheet example1 = wb.getSheet("Example 1"); HSSFCell ex1cell1 = example1.getRow(10).getCell(2); fe.evaluate(ex1cell1); - assertEquals(20.0, ex1cell1.getNumericCellValue()); + assertEquals(20.0, ex1cell1.getNumericCellValue(), 0); HSSFCell ex1cell2 = example1.getRow(11).getCell(2); fe.evaluate(ex1cell2); - assertEquals(30.0, ex1cell2.getNumericCellValue()); + assertEquals(30.0, ex1cell2.getNumericCellValue(), 0); HSSFSheet example2 = wb.getSheet("Example 2"); HSSFCell ex2cell1 = example2.getRow(6).getCell(2); fe.evaluate(ex2cell1); - assertEquals(500.0, ex2cell1.getNumericCellValue()); + assertEquals(500.0, ex2cell1.getNumericCellValue(), 0); HSSFCell ex2cell2 = example2.getRow(7).getCell(2); fe.evaluate(ex2cell2); - assertEquals(8711.0, ex2cell2.getNumericCellValue()); + assertEquals(8711.0, ex2cell2.getNumericCellValue(), 0); HSSFSheet example3 = wb.getSheet("Example 3"); HSSFCell ex3cell = example3.getRow(5).getCell(2); @@ -257,15 +271,16 @@ public final class TestSumifs extends Te HSSFSheet example4 = wb.getSheet("Example 4"); HSSFCell ex4cell = example4.getRow(8).getCell(2); fe.evaluate(ex4cell); - assertEquals(3.5, ex4cell.getNumericCellValue()); + assertEquals(3.5, ex4cell.getNumericCellValue(), 0); HSSFSheet example5 = wb.getSheet("Example 5"); HSSFCell ex5cell = example5.getRow(8).getCell(2); fe.evaluate(ex5cell); - assertEquals(625000., ex5cell.getNumericCellValue()); + assertEquals(625000., ex5cell.getNumericCellValue(), 0); } - + + @Test public void testBug56655() { ValueEval[] a2a9 = new ValueEval[] { new NumberEval(5), @@ -283,7 +298,7 @@ public final class TestSumifs extends Te ErrorEval.VALUE_INVALID, new StringEval("A*"), }; - + ValueEval result = invokeSumifs(args, EC); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); @@ -292,11 +307,12 @@ public final class TestSumifs extends Te EvalFactory.createAreaEval("A2:A9", a2a9), ErrorEval.VALUE_INVALID, }; - + result = invokeSumifs(args, EC); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); } + @Test public void testBug56655b() { /* setCellFormula(sheet, 0, 0, "B1*C1"); @@ -315,13 +331,13 @@ public final class TestSumifs extends Te EvalFactory.createAreaEval("A0:A1", a0a1), ErrorEval.VALUE_INVALID }; - + ValueEval result = invokeSumifs(args, EC); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.VALUE_INVALID, result); } - + @Test public void testBug56655c() { /* setCellFormula(sheet, 0, 0, "B1*C1"); @@ -340,7 +356,7 @@ public final class TestSumifs extends Te EvalFactory.createAreaEval("A0:A1", a0a1), ErrorEval.NAME_INVALID }; - + ValueEval result = invokeSumifs(args, EC); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.NAME_INVALID, result); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java Mon Dec 9 00:37:21 2019 @@ -17,7 +17,8 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -25,18 +26,20 @@ import org.apache.poi.ss.formula.eval.Nu import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.RefEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Test cases for SUMPRODUCT() * * @author Josh Micich */ -public final class TestSumproduct extends TestCase { +public final class TestSumproduct { private static ValueEval invokeSumproduct(ValueEval[] args) { // srcCellRow and srcCellColumn are ignored by SUMPRODUCT return new Sumproduct().evaluate(args, -1, (short)-1); } + private static void confirmDouble(double expected, ValueEval actualEval) { if(!(actualEval instanceof NumericValueEval)) { fail("Expected numeric result"); @@ -45,6 +48,7 @@ public final class TestSumproduct extend assertEquals(expected, nve.getNumberValue(), 0); } + @Test public void testScalarSimple() { RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3)); @@ -56,6 +60,7 @@ public final class TestSumproduct extend confirmDouble(6D, result); } + @Test public void testAreaSimple() { ValueEval[] aValues = { new NumberEval(2), @@ -78,6 +83,7 @@ public final class TestSumproduct extend /** * For scalar products, the terms may be 1x1 area refs */ + @Test public void testOneByOneArea() { AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7), }); @@ -90,6 +96,7 @@ public final class TestSumproduct extend confirmDouble(14D, result); } + @Test public void testMismatchAreaDimensions() { AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]); @@ -103,6 +110,7 @@ public final class TestSumproduct extend assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args)); } + @Test public void testAreaWithErrorCell() { ValueEval[] aValues = { ErrorEval.REF_INVALID, Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java Mon Dec 9 00:37:21 2019 @@ -17,16 +17,26 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; - -import org.apache.poi.ss.formula.eval.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import org.apache.poi.ss.formula.eval.AreaEval; +import org.apache.poi.ss.formula.eval.BlankEval; +import org.apache.poi.ss.formula.eval.BoolEval; +import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NumberEval; +import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Test cases for Excel function T() * * @author Josh Micich */ -public final class TestTFunc extends TestCase { +public final class TestTFunc { /** * @return the result of calling function T() with the specified argument @@ -54,6 +64,7 @@ public final class TestTFunc extends Tes assertEquals(text, se.getStringValue()); } + @Test public void testTextValues() { confirmText("abc"); confirmText(""); @@ -65,9 +76,10 @@ public final class TestTFunc extends Tes private static void confirmError(ValueEval arg) { ValueEval eval = invokeT(arg); - assertTrue(arg == eval); + assertSame(arg, eval); } + @Test public void testErrorValues() { confirmError(ErrorEval.VALUE_INVALID); @@ -85,12 +97,14 @@ public final class TestTFunc extends Tes confirmString(eval, ""); } + @Test public void testOtherValues() { confirmOther(new NumberEval(2)); confirmOther(BoolEval.FALSE); confirmOther(BlankEval.instance); // can this particular case be verified? } + @Test public void testRefValues() { ValueEval eval; @@ -105,9 +119,10 @@ public final class TestTFunc extends Tes confirmString(eval, ""); eval = invokeTWithReference(ErrorEval.NAME_INVALID); - assertTrue(eval == ErrorEval.NAME_INVALID); + assertSame(eval, ErrorEval.NAME_INVALID); } + @Test public void testAreaArg() { ValueEval[] areaValues = new ValueEval[] { new StringEval("abc"), new StringEval("def"), Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java Mon Dec 9 00:37:21 2019 @@ -17,7 +17,7 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.BoolEval; @@ -25,12 +25,14 @@ import org.apache.poi.ss.formula.eval.Er import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + /** * Tests for Excel function TRIM() * * @author Josh Micich */ -public final class TestTrim extends TestCase { +public final class TestTrim { private static ValueEval invokeTrim(ValueEval text) { @@ -50,6 +52,7 @@ public final class TestTrim extends Test assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); } + @Test public void testBasic() { confirmTrim(new StringEval(" hi "), "hi"); @@ -63,6 +66,7 @@ public final class TestTrim extends Test /** * Valid cases where text arg is not exactly a string */ + @Test public void testUnusualArgs() { // text (first) arg type is number, other args are strings with fractional digits @@ -72,6 +76,7 @@ public final class TestTrim extends Test confirmTrim(BlankEval.instance, ""); } + @Test public void testErrors() { confirmTrim(ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID); } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java Mon Dec 9 00:37:21 2019 @@ -18,9 +18,11 @@ package org.apache.poi.ss.formula.functions; import org.apache.poi.ss.formula.eval.ErrorEval; -import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Assert; +import org.junit.Test; /** * Test case for TRUNC() @@ -29,34 +31,40 @@ import org.apache.poi.ss.formula.eval.St */ public final class TestTrunc extends AbstractNumericTestCase { private static final NumericFunction F = null; + + @Test public void testTruncWithStringArg() { ValueEval strArg = new StringEval("abc"); ValueEval[] args = { strArg, new NumberEval(2) }; ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); - assertEquals(ErrorEval.VALUE_INVALID, result); + Assert.assertEquals(ErrorEval.VALUE_INVALID, result); } + @Test public void testTruncWithWholeNumber() { ValueEval[] args = { new NumberEval(200), new NumberEval(2) }; @SuppressWarnings("static-access") ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval)result).getNumberValue()); } - + + @Test public void testTruncWithDecimalNumber() { ValueEval[] args = { new NumberEval(2.612777), new NumberEval(3) }; @SuppressWarnings("static-access") ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue()); } - + + @Test public void testTruncWithDecimalNumberOneArg() { ValueEval[] args = { new NumberEval(2.612777) }; ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue()); } + @Test public void testNegative() { ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) }; @SuppressWarnings("static-access") Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java Mon Dec 9 00:37:21 2019 @@ -17,17 +17,18 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; /** * Tests for {@link Value} */ -public final class TestValue extends TestCase { +public final class TestValue { private static ValueEval invokeValue(String strText) { ValueEval[] args = new ValueEval[] { new StringEval(strText), }; @@ -46,6 +47,7 @@ public final class TestValue extends Tes assertEquals(ErrorEval.VALUE_INVALID, result); } + @Test public void testBasic() { confirmValue("100", 100); @@ -73,6 +75,7 @@ public final class TestValue extends Tes confirmValue("30 %", 0.3); } + @Test public void testErrors() { confirmValueError("1+1"); confirmValueError("1 1"); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java?rev=1871067&r1=1871066&r2=1871067&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java Mon Dec 9 00:37:21 2019 @@ -17,17 +17,19 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + /** * Tests for Excel functions SUMX2MY2(), SUMX2PY2(), SUMXMY2() * * @author Josh Micich */ -public final class TestXYNumericFunction extends TestCase { +public final class TestXYNumericFunction { private static final Function SUM_SQUARES = new Sumx2py2(); private static final Function DIFF_SQUARES = new Sumx2my2(); private static final Function SUM_SQUARES_OF_DIFFS = new Sumxmy2(); @@ -54,6 +56,7 @@ public final class TestXYNumericFunction confirmError(SUM_SQUARES_OF_DIFFS, xArray, yArray, expectedError); } + @Test public void testBasic() { ValueEval[] xValues = { new NumberEval(1), @@ -77,6 +80,7 @@ public final class TestXYNumericFunction /** * number of items in array is not limited to 30 */ + @Test public void testLargeArrays() { ValueEval[] xValues = createMockNumberArray(100, 3); ValueEval[] yValues = createMockNumberArray(100, 2); @@ -100,6 +104,7 @@ public final class TestXYNumericFunction return EvalFactory.createAreaEval(refStr, values); } + @Test public void testErrors() { ValueEval[] xValues = { ErrorEval.REF_INVALID, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org