Bug 54535: Bug in INTERCEPT and SLOPE, review and integration test added to FormulaEvalTestData.xls

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1538772 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Cédric Walter 2013-11-04 21:27:12 +00:00
parent 6cb3b01753
commit eab0adda8b
4 changed files with 23 additions and 24 deletions

View File

@ -68,7 +68,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
super(1); super(1);
_value = value; _value = value;
} }
@Override
protected ValueEval getItemInternal(int index) { protected ValueEval getItemInternal(int index) {
return _value; return _value;
} }
@ -80,7 +80,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
super(1); super(1);
_ref = ref; _ref = ref;
} }
@Override
protected ValueEval getItemInternal(int index) { protected ValueEval getItemInternal(int index) {
return _ref.getInnerValueEval(); return _ref.getInnerValueEval();
} }
@ -95,7 +95,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
_ae = ae; _ae = ae;
_width = ae.getWidth(); _width = ae.getWidth();
} }
@Override
protected ValueEval getItemInternal(int index) { protected ValueEval getItemInternal(int index) {
int rowIx = index / _width; int rowIx = index / _width;
int colIx = index % _width; int colIx = index % _width;
@ -114,8 +114,8 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
ValueEval arg0, ValueEval arg1) { ValueEval arg0, ValueEval arg1) {
double result; double result;
try { try {
ValueVector vvX = createValueVector(arg0); ValueVector vvY = createValueVector(arg0);
ValueVector vvY = createValueVector(arg1); ValueVector vvX = createValueVector(arg1);
int size = vvX.getSize(); int size = vvX.getSize();
if (size == 0 || vvY.getSize() != size) { if (size == 0 || vvY.getSize() != size) {
return ErrorEval.NA; return ErrorEval.NA;
@ -137,7 +137,6 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction {
ErrorEval firstXerr = null; ErrorEval firstXerr = null;
ErrorEval firstYerr = null; ErrorEval firstYerr = null;
boolean accumlatedSome = false; boolean accumlatedSome = false;
double result = 0.0;
// first pass: read in data, compute xbar and ybar // first pass: read in data, compute xbar and ybar
double sumx = 0.0, sumy = 0.0; double sumx = 0.0, sumy = 0.0;

View File

@ -59,7 +59,7 @@ public final class TestIntercept extends TestCase {
public void testBasic() { public void testBasic() {
Double exp = Math.pow(10, 7.5); Double exp = Math.pow(10, 7.5);
ValueEval[] xValues = { ValueEval[] yValues = {
new NumberEval(3+exp), new NumberEval(3+exp),
new NumberEval(4+exp), new NumberEval(4+exp),
new NumberEval(2+exp), new NumberEval(2+exp),
@ -67,9 +67,9 @@ public final class TestIntercept extends TestCase {
new NumberEval(4+exp), new NumberEval(4+exp),
new NumberEval(7+exp), new NumberEval(7+exp),
}; };
ValueEval areaEvalX = createAreaEval(xValues); ValueEval areaEvalY = createAreaEval(yValues);
ValueEval[] yValues = { ValueEval[] xValues = {
new NumberEval(1), new NumberEval(1),
new NumberEval(2), new NumberEval(2),
new NumberEval(3), new NumberEval(3),
@ -77,7 +77,7 @@ public final class TestIntercept extends TestCase {
new NumberEval(5), new NumberEval(5),
new NumberEval(6), new NumberEval(6),
}; };
ValueEval areaEvalY = createAreaEval(yValues); ValueEval areaEvalX = createAreaEval(xValues);
confirm(INTERCEPT, areaEvalX, areaEvalY, -24516534.39905822); confirm(INTERCEPT, areaEvalX, areaEvalY, -24516534.39905822);
// Excel 2010 gives -24516534.3990583 // 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 * number of items in array is not limited to 30
*/ */
public void testLargeArrays() { public void testLargeArrays() {
ValueEval[] xValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1] ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
xValues[0] = new NumberEval(2.0); // Changes first element to 2 yValues[0] = new NumberEval(2.0); // Changes first element to 2
ValueEval[] yValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100] ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
confirm(INTERCEPT, createAreaEval(xValues), createAreaEval(yValues), 51.74384236453202); confirm(INTERCEPT, createAreaEval(xValues), createAreaEval(yValues), 51.74384236453202);
// Excel 2010 gives 51.74384236453200 // Excel 2010 gives 51.74384236453200
@ -136,8 +136,8 @@ public final class TestIntercept extends TestCase {
confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID); confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
// search for errors array by array, not pair by pair // search for errors array by array, not pair by pair
confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID); confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION); confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
} }
/** /**

View File

@ -54,7 +54,7 @@ public final class TestSlope extends TestCase {
public void testBasic() { public void testBasic() {
Double exp = Math.pow(10, 7.5); Double exp = Math.pow(10, 7.5);
ValueEval[] xValues = { ValueEval[] yValues = {
new NumberEval(3+exp), new NumberEval(3+exp),
new NumberEval(4+exp), new NumberEval(4+exp),
new NumberEval(2+exp), new NumberEval(2+exp),
@ -62,9 +62,9 @@ public final class TestSlope extends TestCase {
new NumberEval(4+exp), new NumberEval(4+exp),
new NumberEval(7+exp), new NumberEval(7+exp),
}; };
ValueEval areaEvalX = createAreaEval(xValues); ValueEval areaEvalY = createAreaEval(yValues);
ValueEval[] yValues = { ValueEval[] xValues = {
new NumberEval(1), new NumberEval(1),
new NumberEval(2), new NumberEval(2),
new NumberEval(3), new NumberEval(3),
@ -72,7 +72,7 @@ public final class TestSlope extends TestCase {
new NumberEval(5), new NumberEval(5),
new NumberEval(6), new NumberEval(6),
}; };
ValueEval areaEvalY = createAreaEval(yValues); ValueEval areaEvalX = createAreaEval(xValues);
confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045); confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045);
// Excel 2010 gives 0.775280898876405 // 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 * number of items in array is not limited to 30
*/ */
public void testLargeArrays() { public void testLargeArrays() {
ValueEval[] xValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1] ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
xValues[0] = new NumberEval(2.0); // Changes first element to 2 yValues[0] = new NumberEval(2.0); // Changes first element to 2
ValueEval[] yValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100] ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059); confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
// Excel 2010 gives -1.23152709359606 // Excel 2010 gives -1.23152709359606
@ -131,7 +131,7 @@ public final class TestSlope extends TestCase {
confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID); confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
// search for errors array by array, not pair by pair // search for errors array by array, not pair by pair
confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID); confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION); confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
} }
} }