You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/09/11 20:52:30 UTC
svn commit: r1702535 - in /poi/trunk/src:
java/org/apache/poi/ss/formula/functions/Match.java
testcases/org/apache/poi/ss/formula/functions/TestMatch.java
Author: centic
Date: Fri Sep 11 18:52:29 2015
New Revision: 1702535
URL: http://svn.apache.org/r1702535
Log:
Bug 58353: Return correct value in Match-Function with match-type == -1
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Match.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Match.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Match.java?rev=1702535&r1=1702534&r2=1702535&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Match.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Match.java Fri Sep 11 18:52:29 2015
@@ -228,18 +228,10 @@ public final class Match extends Var2or3
return i-1;
}
}
-
- throw new EvaluationException(ErrorEval.NA);
+ return size-1;
}
private static LookupValueComparer createLookupComparer(ValueEval lookupValue, boolean matchExact) {
return LookupUtils.createLookupComparer(lookupValue, matchExact, true);
}
-
- private static boolean isLookupValueWild(String stringValue) {
- if(stringValue.indexOf('?') >=0 || stringValue.indexOf('*') >=0) {
- return true;
- }
- return false;
- }
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java?rev=1702535&r1=1702534&r2=1702535&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java Fri Sep 11 18:52:29 2015
@@ -17,10 +17,6 @@
package org.apache.poi.ss.formula.functions;
-import junit.framework.TestCase;
-
-import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
@@ -28,7 +24,8 @@ 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.apache.poi.ss.usermodel.CellValue;
+
+import junit.framework.TestCase;
/**
* Test cases for MATCH()
@@ -40,14 +37,21 @@ public final class TestMatch extends Tes
/** greater than or equal to */
private static final NumberEval MATCH_SMALLEST_GTE = new NumberEval(-1);
+ private static final StringEval MATCH_INVALID = new StringEval("blabla");
private static ValueEval invokeMatch(ValueEval lookup_value, ValueEval lookup_array, ValueEval match_type) {
ValueEval[] args = { lookup_value, lookup_array, match_type, };
return new Match().evaluate(args, -1, (short)-1);
}
- private static void confirmInt(int expected, ValueEval actualEval) {
+
+ private static ValueEval invokeMatch(ValueEval lookup_value, ValueEval lookup_array) {
+ ValueEval[] args = { lookup_value, lookup_array, };
+ return new Match().evaluate(args, -1, (short)-1);
+ }
+
+ private static void confirmInt(int expected, ValueEval actualEval) {
if(!(actualEval instanceof NumericValueEval)) {
- fail("Expected numeric result");
+ fail("Expected numeric result but had " + actualEval);
}
NumericValueEval nve = (NumericValueEval)actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
@@ -66,6 +70,7 @@ public final class TestMatch extends Tes
AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
+ confirmInt(2, invokeMatch(new NumberEval(5), ae));
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new NumberEval(10), ae, MATCH_LARGEST_LTE));
confirmInt(3, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
@@ -89,6 +94,7 @@ public final class TestMatch extends Tes
confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new NumberEval(9), ae, MATCH_SMALLEST_GTE));
confirmInt(1, invokeMatch(new NumberEval(20), ae, MATCH_SMALLEST_GTE));
+ confirmInt(5, invokeMatch(new NumberEval(3), ae, MATCH_SMALLEST_GTE));
assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(26), ae, MATCH_SMALLEST_GTE));
}
@@ -251,4 +257,22 @@ public final class TestMatch extends Tes
throw e;
}
}
+
+ public void testInvalidMatchType() {
+
+ ValueEval[] values = {
+ new NumberEval(4),
+ new NumberEval(5),
+ new NumberEval(10),
+ new NumberEval(10),
+ new NumberEval(25),
+ };
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
+
+ confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
+
+ assertEquals("Should return #REF! for invalid match type",
+ ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org