mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
mismatched array sizes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
abcf2c07e2
commit
eea430a5aa
@ -66,9 +66,13 @@ public class Correl extends Fixed2ArgFunction {
|
||||
private List<DoubleList> getNumberArrays(ValueEval operand0, ValueEval operand1) throws EvaluationException {
|
||||
double[] retval0 = collectValuesWithBlanks(operand0).toArray();
|
||||
double[] retval1 = collectValuesWithBlanks(operand1).toArray();
|
||||
if (retval0.length != retval1.length) {
|
||||
throw new EvaluationException(ErrorEval.NA);
|
||||
}
|
||||
DoubleList filtered0 = new DoubleList();
|
||||
DoubleList filtered1 = new DoubleList();
|
||||
for (int i = 0; i < retval0.length; i++) {
|
||||
int len = Math.min(retval0.length, retval1.length);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Double.isNaN(retval0[i]) || Double.isNaN(retval1[i])) {
|
||||
//ignore
|
||||
} else {
|
||||
|
||||
@ -22,12 +22,14 @@ 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.FormulaError;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.apache.poi.ss.util.Utils.addRow;
|
||||
import static org.apache.poi.ss.util.Utils.assertDouble;
|
||||
import static org.apache.poi.ss.util.Utils.assertError;
|
||||
|
||||
/**
|
||||
* Tests for {@link Correl}
|
||||
@ -68,6 +70,18 @@ final class TestCorrel {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMismatch() throws IOException {
|
||||
try (HSSFWorkbook wb = initWorkbook1()) {
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFRow row = sheet.getRow(0);
|
||||
HSSFCell cell = row.createCell(100);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
assertError(fe, cell, "CORREL(A2:A6,B2:B5)", FormulaError.NA);
|
||||
assertError(fe, cell, "CORREL(A2:B6,B2:B6)", FormulaError.NA);
|
||||
}
|
||||
}
|
||||
|
||||
private HSSFWorkbook initWorkbook1() {
|
||||
return initWorkbook1(Double.valueOf(15));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user