]> source.dussan.org Git - poi.git/commitdiff
Bug 54535: Bug in INTERCEPT and SLOPE, review and integration test added to FormulaEv...
authorCédric Walter <cedricwalter@apache.org>
Mon, 4 Nov 2013 21:27:12 +0000 (21:27 +0000)
committerCédric Walter <cedricwalter@apache.org>
Mon, 4 Nov 2013 21:27:12 +0000 (21:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1538772 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/functions/LinearRegressionFunction.java
src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java
src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java
test-data/spreadsheet/FormulaEvalTestData.xls

index a676f5b347a8ce61a5e5ad5738591aff2d36fb7f..4fed7f9e98fe8131813e6470fd7bd072ba2401f1 100644 (file)
@@ -68,7 +68,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
                        super(1);
                        _value = value;
                }
-               @Override
+
                protected ValueEval getItemInternal(int index) {
                        return _value;
                }
@@ -80,7 +80,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
                        super(1);
                        _ref = ref;
                }
-               @Override
+
                protected ValueEval getItemInternal(int index) {
                        return _ref.getInnerValueEval();
                }
@@ -95,7 +95,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
                        _ae = ae;
                        _width = ae.getWidth();
                }
-               @Override
+
                protected ValueEval getItemInternal(int index) {
                        int rowIx = index / _width;
                        int colIx = index % _width;
@@ -114,8 +114,8 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
                        ValueEval arg0, ValueEval arg1) {
                double result;
                try {
-                       ValueVector vvX = createValueVector(arg0);
-                       ValueVector vvY = createValueVector(arg1);
+                       ValueVector vvY = createValueVector(arg0);
+                       ValueVector vvX = createValueVector(arg1);
                        int size = vvX.getSize();
                        if (size == 0 || vvY.getSize() != size) {
                                return ErrorEval.NA;
@@ -137,7 +137,6 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
                ErrorEval firstXerr = null;
                ErrorEval firstYerr = null;
                boolean accumlatedSome = false;
-               double result = 0.0;
         // first pass: read in data, compute xbar and ybar
         double sumx = 0.0, sumy = 0.0;
         
index 942ab6b01945521216fa75744c3251ac772a988d..34b6d857946d7d1bdc523154a5e64d6663a26fa4 100644 (file)
@@ -59,7 +59,7 @@ public final class TestIntercept extends TestCase {
 
        public void testBasic() {
                Double exp = Math.pow(10, 7.5);
-               ValueEval[] xValues = {
+               ValueEval[] yValues = {
                        new NumberEval(3+exp),
                        new NumberEval(4+exp),
                        new NumberEval(2+exp),
@@ -67,9 +67,9 @@ public final class TestIntercept extends TestCase {
                        new NumberEval(4+exp),
                        new NumberEval(7+exp),
                };
-               ValueEval areaEvalX = createAreaEval(xValues);
+               ValueEval areaEvalY = createAreaEval(yValues);
 
-               ValueEval[] yValues = {
+               ValueEval[] xValues = {
                        new NumberEval(1),
                        new NumberEval(2),
                        new NumberEval(3),
@@ -77,7 +77,7 @@ public final class TestIntercept extends TestCase {
                        new NumberEval(5),
                        new NumberEval(6),
                };
-               ValueEval areaEvalY = createAreaEval(yValues);
+               ValueEval areaEvalX = createAreaEval(xValues);
                confirm(INTERCEPT, areaEvalX, areaEvalY, -24516534.39905822);
                // Excel 2010 gives -24516534.3990583
        }
@@ -86,9 +86,9 @@ public final class TestIntercept extends TestCase {
         * number of items in array is not limited to 30
         */
        public void testLargeArrays() {
-               ValueEval[] xValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
-               xValues[0] = new NumberEval(2.0); // Changes first element to 2
-               ValueEval[] yValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
+               ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
+               yValues[0] = new NumberEval(2.0); // Changes first element to 2
+               ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
 
                confirm(INTERCEPT, createAreaEval(xValues), createAreaEval(yValues), 51.74384236453202);
                // Excel 2010 gives 51.74384236453200
@@ -136,8 +136,8 @@ public final class TestIntercept extends TestCase {
                confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
 
                // search for errors array by array, not pair by pair
-               confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID);
-               confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION);
+               confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
+               confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
        }
 
     /**
index 2ea0332edac3a651119dfe3db0a8fa757f6e2280..db5fee109b7851feed86f0d5568f3eb6683e544e 100644 (file)
@@ -54,7 +54,7 @@ public final class TestSlope extends TestCase {
 
        public void testBasic() {
                Double exp = Math.pow(10, 7.5);
-               ValueEval[] xValues = {
+               ValueEval[] yValues = {
                        new NumberEval(3+exp),
                        new NumberEval(4+exp),
                        new NumberEval(2+exp),
@@ -62,9 +62,9 @@ public final class TestSlope extends TestCase {
                        new NumberEval(4+exp),
                        new NumberEval(7+exp),
                };
-               ValueEval areaEvalX = createAreaEval(xValues);
+               ValueEval areaEvalY = createAreaEval(yValues);
 
-               ValueEval[] yValues = {
+               ValueEval[] xValues = {
                        new NumberEval(1),
                        new NumberEval(2),
                        new NumberEval(3),
@@ -72,7 +72,7 @@ public final class TestSlope extends TestCase {
                        new NumberEval(5),
                        new NumberEval(6),
                };
-               ValueEval areaEvalY = createAreaEval(yValues);
+               ValueEval areaEvalX = createAreaEval(xValues);
                confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045);
                // Excel 2010 gives 0.775280898876405
        }
@@ -81,9 +81,9 @@ public final class TestSlope extends TestCase {
         * number of items in array is not limited to 30
         */
        public void testLargeArrays() {
-               ValueEval[] xValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
-               xValues[0] = new NumberEval(2.0); // Changes first element to 2
-               ValueEval[] yValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
+               ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
+               yValues[0] = new NumberEval(2.0); // Changes first element to 2
+               ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
 
                confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
                // Excel 2010 gives -1.23152709359606
@@ -131,7 +131,7 @@ public final class TestSlope extends TestCase {
                confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
 
                // search for errors array by array, not pair by pair
-               confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID);
-               confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION);
+               confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
+               confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
        }
 }
index f06572b62525ff42cb865aff489bf25f6ee4b5de..afe3af10a0bcfb94cba54b3e11a127227e2b78ee 100644 (file)
Binary files a/test-data/spreadsheet/FormulaEvalTestData.xls and b/test-data/spreadsheet/FormulaEvalTestData.xls differ