You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [41/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMatch.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMatch.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMatch.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMatch.java Sat May 22 20:56:44 2021
@@ -34,18 +34,18 @@ import org.junit.jupiter.api.Test;
* Test cases for MATCH()
*/
final class TestMatch {
- /** less than or equal to */
- private static final NumberEval MATCH_LARGEST_LTE = new NumberEval(1);
- private static final NumberEval MATCH_EXACT = new NumberEval(0);
- /** greater than or equal to */
- private static final NumberEval MATCH_SMALLEST_GTE = new NumberEval(-1);
+ /** less than or equal to */
+ private static final NumberEval MATCH_LARGEST_LTE = new NumberEval(1);
+ private static final NumberEval MATCH_EXACT = new NumberEval(0);
+ /** 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 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 ValueEval invokeMatch(ValueEval lookup_value, ValueEval lookup_array) {
ValueEval[] args = { lookup_value, lookup_array, };
@@ -53,78 +53,78 @@ final class TestMatch {
}
private static void confirmInt(int expected, ValueEval actualEval) {
- assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result but had " + actualEval);
- NumericValueEval nve = (NumericValueEval)actualEval;
- assertEquals(expected, nve.getNumberValue(), 0);
- }
-
- @Test
- void testSimpleNumber() {
-
- ValueEval[] values = {
- new NumberEval(4),
- new NumberEval(5),
- new NumberEval(10),
- new NumberEval(10),
- new NumberEval(25),
- };
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result but had " + actualEval);
+ NumericValueEval nve = (NumericValueEval)actualEval;
+ assertEquals(expected, nve.getNumberValue(), 0);
+ }
+
+ @Test
+ void testSimpleNumber() {
+
+ ValueEval[] values = {
+ new NumberEval(4),
+ new NumberEval(5),
+ new NumberEval(10),
+ new NumberEval(10),
+ new NumberEval(25),
+ };
- AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
+ AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
- confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
+ 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));
- confirmInt(4, invokeMatch(new NumberEval(20), ae, MATCH_LARGEST_LTE));
- assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
- }
-
- @Test
- void testReversedNumber() {
-
- ValueEval[] values = {
- new NumberEval(25),
- new NumberEval(10),
- new NumberEval(10),
- new NumberEval(10),
- new NumberEval(4),
- };
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
-
- confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_SMALLEST_GTE));
- 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));
- }
+ 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));
+ confirmInt(4, invokeMatch(new NumberEval(20), ae, MATCH_LARGEST_LTE));
+ assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
+ }
+
+ @Test
+ void testReversedNumber() {
+
+ ValueEval[] values = {
+ new NumberEval(25),
+ new NumberEval(10),
+ new NumberEval(10),
+ new NumberEval(10),
+ new NumberEval(4),
+ };
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
+
+ confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_SMALLEST_GTE));
+ 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));
+ }
- @Test
- void testSimpleString() {
+ @Test
+ void testSimpleString() {
// Arrange
- ValueEval[] values = {
- new StringEval("Albert"),
- new StringEval("Charles"),
- new StringEval("Ed"),
- new StringEval("Greg"),
- new StringEval("Ian"),
- };
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
-
- // Note String comparisons are case insensitive
- confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_LARGEST_LTE));
- confirmInt(3, invokeMatch(new StringEval("eD"), ae, MATCH_LARGEST_LTE));
- confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_EXACT));
- confirmInt(3, invokeMatch(new StringEval("ed"), ae, MATCH_EXACT));
+ ValueEval[] values = {
+ new StringEval("Albert"),
+ new StringEval("Charles"),
+ new StringEval("Ed"),
+ new StringEval("Greg"),
+ new StringEval("Ian"),
+ };
- assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
- }
+ AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
- @Test
+ // Note String comparisons are case insensitive
+ confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_LARGEST_LTE));
+ confirmInt(3, invokeMatch(new StringEval("eD"), ae, MATCH_LARGEST_LTE));
+ confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_EXACT));
+ confirmInt(3, invokeMatch(new StringEval("ed"), ae, MATCH_EXACT));
+
+ assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
+ }
+
+ @Test
void testSimpleWildcardValuesString() {
// Arrange
ValueEval[] values = {
@@ -154,7 +154,7 @@ final class TestMatch {
confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_LARGEST_LTE));
}
- @Test
+ @Test
void testTildeString() {
ValueEval[] values = {
@@ -168,107 +168,107 @@ final class TestMatch {
confirmInt(2, invokeMatch(new StringEval("all~*"), ae, MATCH_EXACT));
}
- @Test
- void testSimpleBoolean() {
+ @Test
+ void testSimpleBoolean() {
- ValueEval[] values = {
- BoolEval.FALSE,
- BoolEval.FALSE,
- BoolEval.TRUE,
- BoolEval.TRUE,
- };
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A4", values);
-
- // Note String comparisons are case insensitive
- confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
- confirmInt(1, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
- confirmInt(4, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
- confirmInt(3, invokeMatch(BoolEval.TRUE, ae, MATCH_EXACT));
- }
-
- @Test
- void testHeterogeneous() {
-
- ValueEval[] values = {
- new NumberEval(4),
- BoolEval.FALSE,
- new NumberEval(5),
- new StringEval("Albert"),
- BoolEval.FALSE,
- BoolEval.TRUE,
- new NumberEval(10),
- new StringEval("Charles"),
- new StringEval("Ed"),
- new NumberEval(10),
- new NumberEval(25),
- BoolEval.TRUE,
- new StringEval("Ed"),
- };
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A13", values);
-
- assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));
-
- confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
- confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
- confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
- confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
+ ValueEval[] values = {
+ BoolEval.FALSE,
+ BoolEval.FALSE,
+ BoolEval.TRUE,
+ BoolEval.TRUE,
+ };
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A4", values);
+
+ // Note String comparisons are case insensitive
+ confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
+ confirmInt(1, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
+ confirmInt(4, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
+ confirmInt(3, invokeMatch(BoolEval.TRUE, ae, MATCH_EXACT));
+ }
+
+ @Test
+ void testHeterogeneous() {
+
+ ValueEval[] values = {
+ new NumberEval(4),
+ BoolEval.FALSE,
+ new NumberEval(5),
+ new StringEval("Albert"),
+ BoolEval.FALSE,
+ BoolEval.TRUE,
+ new NumberEval(10),
+ new StringEval("Charles"),
+ new StringEval("Ed"),
+ new NumberEval(10),
+ new NumberEval(25),
+ BoolEval.TRUE,
+ new StringEval("Ed"),
+ };
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A13", values);
- confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
+ assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));
+
+ confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
+ confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
+ confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
+ confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
+
+ confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
//wildcard values
confirmInt(8, invokeMatch(new StringEval("CHAR*"), ae, MATCH_EXACT));
confirmInt(8, invokeMatch(new StringEval("*CHARLES"), ae, MATCH_EXACT));
- confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));
+ confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));
- confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
- confirmInt(13, invokeMatch(new StringEval("ED*"), ae, MATCH_LARGEST_LTE));
- confirmInt(13, invokeMatch(new StringEval("*ED"), ae, MATCH_LARGEST_LTE));
- confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
- confirmInt(9, invokeMatch(new StringEval("ED*"), ae, MATCH_EXACT));
-
- confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
- assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
-
- confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
- confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
- }
-
-
- /**
- * Ensures that the match_type argument can be an {@code AreaEval}.<br>
- * Bugzilla 44421
- */
- @Test
- void testMatchArgTypeArea() {
-
- ValueEval[] values = {
- new NumberEval(4),
- new NumberEval(5),
- new NumberEval(10),
- new NumberEval(10),
- new NumberEval(25),
- };
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
-
- AreaEval matchAE = EvalFactory.createAreaEval("C1:C1", new ValueEval[] { MATCH_LARGEST_LTE, });
-
- try {
- confirmInt(4, invokeMatch(new NumberEval(10), ae, matchAE));
- } catch (RuntimeException e) {
- if(e.getMessage().startsWith("Unexpected match_type type")) {
- // identified bug 44421
- fail(e.getMessage());
- }
- // some other error ??
- throw e;
- }
- }
+ confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
+ confirmInt(13, invokeMatch(new StringEval("ED*"), ae, MATCH_LARGEST_LTE));
+ confirmInt(13, invokeMatch(new StringEval("*ED"), ae, MATCH_LARGEST_LTE));
+ confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
+ confirmInt(9, invokeMatch(new StringEval("ED*"), ae, MATCH_EXACT));
- @Test
- void testInvalidMatchType() {
+ confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
+ assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
+
+ confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
+ confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
+ }
+
+
+ /**
+ * Ensures that the match_type argument can be an {@code AreaEval}.<br>
+ * Bugzilla 44421
+ */
+ @Test
+ void testMatchArgTypeArea() {
+
+ ValueEval[] values = {
+ new NumberEval(4),
+ new NumberEval(5),
+ new NumberEval(10),
+ new NumberEval(10),
+ new NumberEval(25),
+ };
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
+
+ AreaEval matchAE = EvalFactory.createAreaEval("C1:C1", new ValueEval[] { MATCH_LARGEST_LTE, });
+
+ try {
+ confirmInt(4, invokeMatch(new NumberEval(10), ae, matchAE));
+ } catch (RuntimeException e) {
+ if(e.getMessage().startsWith("Unexpected match_type type")) {
+ // identified bug 44421
+ fail(e.getMessage());
+ }
+ // some other error ??
+ throw e;
+ }
+ }
+
+ @Test
+ void testInvalidMatchType() {
ValueEval[] values = {
new NumberEval(4),
@@ -283,6 +283,6 @@ final class TestMatch {
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
assertEquals(ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID),
- "Should return #REF! for invalid match type");
- }
+ "Should return #REF! for invalid match type");
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMid.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMid.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMid.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestMid.java Sat May 22 20:56:44 2021
@@ -35,80 +35,80 @@ import org.junit.jupiter.api.Test;
final class TestMid {
- private static ValueEval invokeMid(ValueEval text, ValueEval startPos, ValueEval numChars) {
- ValueEval[] args = new ValueEval[] { text, startPos, numChars, };
- return TextFunction.MID.evaluate(args, -1, (short)-1);
- }
-
- private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, String expected) {
- ValueEval result = invokeMid(text, startPos, numChars);
- assertEquals(StringEval.class, result.getClass());
- assertEquals(expected, ((StringEval)result).getStringValue());
- }
-
- private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, ErrorEval expectedError) {
- ValueEval result = invokeMid(text, startPos, numChars);
- assertEquals(ErrorEval.class, result.getClass());
- assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
- }
-
- @Test
- void testBasic() {
-
- confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(4), "lact");
- }
-
- /**
- * Valid cases where args are not precisely (string, int, int) but can be resolved OK.
- */
- @Test
- void testUnusualArgs() {
- // startPos with fractional digits
- confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
-
- // string startPos
- confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
-
- // text (first) arg type is number, other args are strings with fractional digits
- confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
-
- // startPos is 1x1 area ref, numChars is cell ref
- AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2), } );
- RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
- confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
-
- confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
-
- confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
- confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
- confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
-
- }
-
- /**
- * Extreme values for startPos and numChars
- */
- @Test
- void testExtremes() {
- confirmMid(new StringEval("galactic"), new NumberEval(4), new NumberEval(400), "actic");
-
- confirmMid(new StringEval("galactic"), new NumberEval(30), new NumberEval(4), "");
- confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(0), "");
- }
-
- /**
- * All sorts of ways to make MID return defined errors.
- */
- @Test
- 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);
- confirmMid(new StringEval("galactic"), new NumberEval(3), ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
- confirmMid(new StringEval("galactic"), ErrorEval.DIV_ZERO, ErrorEval.NAME_INVALID, ErrorEval.DIV_ZERO);
-
- confirmMid(new StringEval("galactic"), BlankEval.instance, new NumberEval(3.1), ErrorEval.VALUE_INVALID);
-
- confirmMid(new StringEval("galactic"), new NumberEval(0), new NumberEval(4), ErrorEval.VALUE_INVALID);
- confirmMid(new StringEval("galactic"), new NumberEval(1), new NumberEval(-1), ErrorEval.VALUE_INVALID);
- }
+ private static ValueEval invokeMid(ValueEval text, ValueEval startPos, ValueEval numChars) {
+ ValueEval[] args = new ValueEval[] { text, startPos, numChars, };
+ return TextFunction.MID.evaluate(args, -1, (short)-1);
+ }
+
+ private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, String expected) {
+ ValueEval result = invokeMid(text, startPos, numChars);
+ assertEquals(StringEval.class, result.getClass());
+ assertEquals(expected, ((StringEval)result).getStringValue());
+ }
+
+ private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, ErrorEval expectedError) {
+ ValueEval result = invokeMid(text, startPos, numChars);
+ assertEquals(ErrorEval.class, result.getClass());
+ assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+ }
+
+ @Test
+ void testBasic() {
+
+ confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(4), "lact");
+ }
+
+ /**
+ * Valid cases where args are not precisely (string, int, int) but can be resolved OK.
+ */
+ @Test
+ void testUnusualArgs() {
+ // startPos with fractional digits
+ confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
+
+ // string startPos
+ confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
+
+ // text (first) arg type is number, other args are strings with fractional digits
+ confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
+
+ // startPos is 1x1 area ref, numChars is cell ref
+ AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2), } );
+ RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
+ confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
+
+ confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
+
+ confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
+ confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
+ confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
+
+ }
+
+ /**
+ * Extreme values for startPos and numChars
+ */
+ @Test
+ void testExtremes() {
+ confirmMid(new StringEval("galactic"), new NumberEval(4), new NumberEval(400), "actic");
+
+ confirmMid(new StringEval("galactic"), new NumberEval(30), new NumberEval(4), "");
+ confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(0), "");
+ }
+
+ /**
+ * All sorts of ways to make MID return defined errors.
+ */
+ @Test
+ 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);
+ confirmMid(new StringEval("galactic"), new NumberEval(3), ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
+ confirmMid(new StringEval("galactic"), ErrorEval.DIV_ZERO, ErrorEval.NAME_INVALID, ErrorEval.DIV_ZERO);
+
+ confirmMid(new StringEval("galactic"), BlankEval.instance, new NumberEval(3.1), ErrorEval.VALUE_INVALID);
+
+ confirmMid(new StringEval("galactic"), new NumberEval(0), new NumberEval(4), ErrorEval.VALUE_INVALID);
+ confirmMid(new StringEval("galactic"), new NumberEval(1), new NumberEval(-1), ErrorEval.VALUE_INVALID);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNper.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNper.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNper.java Sat May 22 20:56:44 2021
@@ -37,34 +37,34 @@ import org.junit.jupiter.api.Test;
final class TestNper {
@Test
- void testSimpleEvaluate() {
- ValueEval[] args = {
- new NumberEval(0.05),
- new NumberEval(250),
- new NumberEval(-1000),
- };
- ValueEval result = FinanceFunction.NPER.evaluate(args, 0, (short)0);
+ void testSimpleEvaluate() {
+ ValueEval[] args = {
+ new NumberEval(0.05),
+ new NumberEval(250),
+ new NumberEval(-1000),
+ };
+ ValueEval result = FinanceFunction.NPER.evaluate(args, 0, (short)0);
- assertEquals(NumberEval.class, result.getClass());
- assertEquals(4.57353557, ((NumberEval)result).getNumberValue(), 0.00000001);
- }
+ assertEquals(NumberEval.class, result.getClass());
+ assertEquals(4.57353557, ((NumberEval)result).getNumberValue(), 0.00000001);
+ }
@Test
- void testEvaluate_bug_45732() throws IOException {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("Sheet1");
- HSSFCell cell = sheet.createRow(0).createCell(0);
+ void testEvaluate_bug_45732() throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFCell cell = sheet.createRow(0).createCell(0);
- cell.setCellFormula("NPER(12,4500,100000,100000)");
- cell.setCellValue(15.0);
- assertEquals("NPER(12,4500,100000,100000)", cell.getCellFormula());
- assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
- assertEquals(15.0, cell.getNumericCellValue(), 0.0);
+ cell.setCellFormula("NPER(12,4500,100000,100000)");
+ cell.setCellValue(15.0);
+ assertEquals("NPER(12,4500,100000,100000)", cell.getCellFormula());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(15.0, cell.getNumericCellValue(), 0.0);
- HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
- fe.evaluateFormulaCell(cell);
- assertEquals(CellType.ERROR, cell.getCachedFormulaResultType());
- assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue());
- wb.close();
- }
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ fe.evaluateFormulaCell(cell);
+ assertEquals(CellType.ERROR, cell.getCachedFormulaResultType());
+ assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue());
+ wb.close();
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOct2Dec.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOct2Dec.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOct2Dec.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOct2Dec.java Sat May 22 20:56:44 2021
@@ -31,15 +31,15 @@ import org.junit.jupiter.api.Test;
final class TestOct2Dec {
private static ValueEval invokeValue(String number1) {
- ValueEval[] args = new ValueEval[] { new StringEval(number1) };
- return new Oct2Dec().evaluate(args, -1, -1);
- }
+ ValueEval[] args = new ValueEval[] { new StringEval(number1) };
+ return new Oct2Dec().evaluate(args, -1, -1);
+ }
private static void confirmValue(String msg, String number1, String expected) {
- ValueEval result = invokeValue(number1);
- assertEquals(NumberEval.class, result.getClass());
- assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
- }
+ ValueEval result = invokeValue(number1);
+ assertEquals(NumberEval.class, result.getClass());
+ assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
+ }
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
@@ -47,16 +47,16 @@ final class TestOct2Dec {
assertEquals(numError, result, msg);
}
- @Test
- void testBasic() {
- confirmValue("Converts octal '' to decimal (0)", "", "0");
- confirmValue("Converts octal 54 to decimal (44)", "54", "44");
- confirmValue("Converts octal 7777777533 to decimal (-165)", "7777777533", "-165");
- confirmValue("Converts octal 7000000000 to decimal (-134217728)", "7000000000", "-134217728");
- confirmValue("Converts octal 7776667533 to decimal (-299173)", "7776667533", "-299173");
- }
+ @Test
+ void testBasic() {
+ confirmValue("Converts octal '' to decimal (0)", "", "0");
+ confirmValue("Converts octal 54 to decimal (44)", "54", "44");
+ confirmValue("Converts octal 7777777533 to decimal (-165)", "7777777533", "-165");
+ confirmValue("Converts octal 7000000000 to decimal (-134217728)", "7000000000", "-134217728");
+ confirmValue("Converts octal 7776667533 to decimal (-299173)", "7776667533", "-299173");
+ }
- @Test
+ @Test
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/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOffset.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOffset.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOffset.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOffset.java Sat May 22 20:56:44 2021
@@ -39,67 +39,67 @@ import org.junit.jupiter.params.provider
*/
final class TestOffset {
- /**
- * Excel's double to int conversion (for function 'OFFSET()') behaves more like Math.floor().
- * Note - negative values are not symmetrical
- * Fractional values are silently truncated.
- * Truncation is toward negative infinity.
- */
- @ParameterizedTest
- @CsvSource({
- "100.09, 100", "100.01, 100", "100.00, 100", "99.99, 99", "+2.01, +2",
- "+2.00, +2", "+1.99, +1", "+1.01, +1", "+1.00, +1", "+0.99, 0",
- "+0.01, 0", "0.00, 0","-0.01, -1", "-0.99, -1", "-1.00, -1",
- "-1.01, -2", "-1.99, -2", "-2.00, -2", "-2.01, -3"
- })
- void testDoubleConversion(double doubleVal, int expected) throws EvaluationException {
- assertEquals(expected, Offset.evaluateIntArg(new NumberEval(doubleVal), -1, -1));
- }
-
- @Test
- void testLinearOffsetRange() {
- LinearOffsetRange lor;
-
- lor = new LinearOffsetRange(3, 2);
- assertEquals(3, lor.getFirstIndex());
- assertEquals(4, lor.getLastIndex());
- lor = lor.normaliseAndTranslate(0); // expected no change
- assertEquals(3, lor.getFirstIndex());
- assertEquals(4, lor.getLastIndex());
-
- lor = lor.normaliseAndTranslate(5);
- assertEquals(8, lor.getFirstIndex());
- assertEquals(9, lor.getLastIndex());
-
- // negative length
-
- lor = new LinearOffsetRange(6, -4).normaliseAndTranslate(0);
- assertEquals(3, lor.getFirstIndex());
- assertEquals(6, lor.getLastIndex());
-
-
- // bounds checking
- lor = new LinearOffsetRange(0, 100);
- assertFalse(lor.isOutOfBounds(0, 16383));
- lor = lor.normaliseAndTranslate(16300);
- assertTrue(lor.isOutOfBounds(0, 16383));
- assertFalse(lor.isOutOfBounds(0, 65535));
- }
-
- @Test
- void testOffsetWithEmpty23Arguments() throws IOException {
- try (Workbook workbook = new HSSFWorkbook()) {
- Cell cell = workbook.createSheet().createRow(0).createCell(0);
- cell.setCellFormula("OFFSET(B1,,)");
-
- String value = "EXPECTED_VALUE";
- Cell valueCell = cell.getRow().createCell(1);
- valueCell.setCellValue(value);
-
- workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
-
- assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
- assertEquals(value, cell.getStringCellValue());
- }
- }
+ /**
+ * Excel's double to int conversion (for function 'OFFSET()') behaves more like Math.floor().
+ * Note - negative values are not symmetrical
+ * Fractional values are silently truncated.
+ * Truncation is toward negative infinity.
+ */
+ @ParameterizedTest
+ @CsvSource({
+ "100.09, 100", "100.01, 100", "100.00, 100", "99.99, 99", "+2.01, +2",
+ "+2.00, +2", "+1.99, +1", "+1.01, +1", "+1.00, +1", "+0.99, 0",
+ "+0.01, 0", "0.00, 0","-0.01, -1", "-0.99, -1", "-1.00, -1",
+ "-1.01, -2", "-1.99, -2", "-2.00, -2", "-2.01, -3"
+ })
+ void testDoubleConversion(double doubleVal, int expected) throws EvaluationException {
+ assertEquals(expected, Offset.evaluateIntArg(new NumberEval(doubleVal), -1, -1));
+ }
+
+ @Test
+ void testLinearOffsetRange() {
+ LinearOffsetRange lor;
+
+ lor = new LinearOffsetRange(3, 2);
+ assertEquals(3, lor.getFirstIndex());
+ assertEquals(4, lor.getLastIndex());
+ lor = lor.normaliseAndTranslate(0); // expected no change
+ assertEquals(3, lor.getFirstIndex());
+ assertEquals(4, lor.getLastIndex());
+
+ lor = lor.normaliseAndTranslate(5);
+ assertEquals(8, lor.getFirstIndex());
+ assertEquals(9, lor.getLastIndex());
+
+ // negative length
+
+ lor = new LinearOffsetRange(6, -4).normaliseAndTranslate(0);
+ assertEquals(3, lor.getFirstIndex());
+ assertEquals(6, lor.getLastIndex());
+
+
+ // bounds checking
+ lor = new LinearOffsetRange(0, 100);
+ assertFalse(lor.isOutOfBounds(0, 16383));
+ lor = lor.normaliseAndTranslate(16300);
+ assertTrue(lor.isOutOfBounds(0, 16383));
+ assertFalse(lor.isOutOfBounds(0, 65535));
+ }
+
+ @Test
+ void testOffsetWithEmpty23Arguments() throws IOException {
+ try (Workbook workbook = new HSSFWorkbook()) {
+ Cell cell = workbook.createSheet().createRow(0).createCell(0);
+ cell.setCellFormula("OFFSET(B1,,)");
+
+ String value = "EXPECTED_VALUE";
+ Cell valueCell = cell.getRow().createCell(1);
+ valueCell.setCellValue(value);
+
+ workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
+
+ assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
+ assertEquals(value, cell.getStringCellValue());
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPmt.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPmt.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPmt.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPmt.java Sat May 22 20:56:44 2021
@@ -29,53 +29,53 @@ import org.junit.jupiter.api.Test;
final class TestPmt {
- private static void confirm(double expected, NumberEval ne) {
- // only asserting accuracy to 4 fractional digits
- assertEquals(expected, ne.getNumberValue(), 0.00005);
- }
- private static ValueEval invoke(ValueEval[] args) {
- return FinanceFunction.PMT.evaluate(args, -1, (short)-1);
- }
- /**
- * Invocation when not expecting an error result
- */
- private static NumberEval invokeNormal(ValueEval[] args) {
- ValueEval ev = invoke(args);
- assertFalse(ev instanceof ErrorEval, "Normal evaluation failed with error code: " + ev);
- return (NumberEval) ev;
- }
-
- private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) {
- ValueEval[] args = {
- new NumberEval(rate),
- new NumberEval(nper),
- new NumberEval(pv),
- new NumberEval(fv),
- new NumberEval(isBeginning ? 1 : 0),
- };
- confirm(expected, invokeNormal(args));
- }
-
- @Test
- void testBasic() {
- confirm(-1037.0321, (0.08/12), 10, 10000, 0, false);
- confirm(-1030.1643, (0.08/12), 10, 10000, 0, true);
- }
-
- @Test
- void test3args() {
-
- ValueEval[] args = {
- new NumberEval(0.005),
- new NumberEval(24),
- new NumberEval(1000),
- };
- ValueEval ev = invoke(args);
- if(ev instanceof ErrorEval) {
- ErrorEval err = (ErrorEval) ev;
- assertNotEquals(FormulaError.VALUE.getCode(), err.getErrorCode(), "Identified bug 44691");
- }
+ private static void confirm(double expected, NumberEval ne) {
+ // only asserting accuracy to 4 fractional digits
+ assertEquals(expected, ne.getNumberValue(), 0.00005);
+ }
+ private static ValueEval invoke(ValueEval[] args) {
+ return FinanceFunction.PMT.evaluate(args, -1, (short)-1);
+ }
+ /**
+ * Invocation when not expecting an error result
+ */
+ private static NumberEval invokeNormal(ValueEval[] args) {
+ ValueEval ev = invoke(args);
+ assertFalse(ev instanceof ErrorEval, "Normal evaluation failed with error code: " + ev);
+ return (NumberEval) ev;
+ }
+
+ private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) {
+ ValueEval[] args = {
+ new NumberEval(rate),
+ new NumberEval(nper),
+ new NumberEval(pv),
+ new NumberEval(fv),
+ new NumberEval(isBeginning ? 1 : 0),
+ };
+ confirm(expected, invokeNormal(args));
+ }
+
+ @Test
+ void testBasic() {
+ confirm(-1037.0321, (0.08/12), 10, 10000, 0, false);
+ confirm(-1030.1643, (0.08/12), 10, 10000, 0, true);
+ }
+
+ @Test
+ void test3args() {
+
+ ValueEval[] args = {
+ new NumberEval(0.005),
+ new NumberEval(24),
+ new NumberEval(1000),
+ };
+ ValueEval ev = invoke(args);
+ if(ev instanceof ErrorEval) {
+ ErrorEval err = (ErrorEval) ev;
+ assertNotEquals(FormulaError.VALUE.getCode(), err.getErrorCode(), "Identified bug 44691");
+ }
- confirm(-44.3206, invokeNormal(args));
- }
+ confirm(-44.3206, invokeNormal(args));
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPoisson.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPoisson.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPoisson.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestPoisson.java Sat May 22 20:56:44 2021
@@ -41,7 +41,7 @@ class TestPoisson {
valueEvals[2] = BoolEval.valueOf(cumulative);
return NumericFunction.POISSON.evaluate(valueEvals,-1,-1);
- }
+ }
@Test
void testCumulativeProbability()
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRoundFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRoundFuncs.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRoundFuncs.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRoundFuncs.java Sat May 22 20:56:44 2021
@@ -30,57 +30,57 @@ import org.junit.jupiter.api.Test;
* Test cases for ROUND(), ROUNDUP(), ROUNDDOWN()
*/
final class TestRoundFuncs {
- // github-43
- // https://github.com/apache/poi/pull/43
+ // github-43
+ // https://github.com/apache/poi/pull/43
@Disabled("ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
- @Test
- void testRoundUp() {
- assertRoundUpEquals(797.40, 3987*0.2, 2, 1e-10);
- }
-
- @Test
- void testRoundDown() {
- assertRoundDownEquals(797.40, 3987*0.2, 2, 1e-10);
- }
-
- @Test
- void testRound() {
- assertRoundEquals(797.40, 3987*0.2, 2, 1e-10);
- }
-
- @Test
- void testRoundDownWithStringArg() {
- ValueEval strArg = new StringEval("abc");
- ValueEval[] args = { strArg, new NumberEval(2), };
- ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1);
- assertEquals(ErrorEval.VALUE_INVALID, result);
- }
-
- @Test
- void testRoundUpWithStringArg() {
- ValueEval strArg = new StringEval("abc");
- ValueEval[] args = { strArg, new NumberEval(2), };
- ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1);
- assertEquals(ErrorEval.VALUE_INVALID, result);
- }
+ @Test
+ void testRoundUp() {
+ assertRoundUpEquals(797.40, 3987*0.2, 2, 1e-10);
+ }
+
+ @Test
+ void testRoundDown() {
+ assertRoundDownEquals(797.40, 3987*0.2, 2, 1e-10);
+ }
+
+ @Test
+ void testRound() {
+ assertRoundEquals(797.40, 3987*0.2, 2, 1e-10);
+ }
+
+ @Test
+ void testRoundDownWithStringArg() {
+ ValueEval strArg = new StringEval("abc");
+ ValueEval[] args = { strArg, new NumberEval(2), };
+ ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1);
+ assertEquals(ErrorEval.VALUE_INVALID, result);
+ }
+
+ @Test
+ void testRoundUpWithStringArg() {
+ ValueEval strArg = new StringEval("abc");
+ ValueEval[] args = { strArg, new NumberEval(2), };
+ ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1);
+ assertEquals(ErrorEval.VALUE_INVALID, result);
+ }
private static void assertRoundFuncEquals(Function func, double expected, double number, double places, double tolerance) {
- ValueEval[] args = { new NumberEval( number ), new NumberEval(places), };
- NumberEval result = (NumberEval) func.evaluate(args, -1, (short)-1);
- assertEquals(expected, result.getNumberValue(), tolerance);
+ ValueEval[] args = { new NumberEval( number ), new NumberEval(places), };
+ NumberEval result = (NumberEval) func.evaluate(args, -1, (short)-1);
+ assertEquals(expected, result.getNumberValue(), tolerance);
}
private static void assertRoundEquals(double expected, double number, double places, double tolerance) {
- TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUND, expected, number, places, tolerance);
+ TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUND, expected, number, places, tolerance);
}
private static void assertRoundUpEquals(double expected, double number, double places, double tolerance) {
- TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDUP, expected, number, places, tolerance);
+ TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDUP, expected, number, places, tolerance);
}
private static void assertRoundDownEquals(double expected, double number, double places, double tolerance) {
- TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDDOWN, expected, number, places, tolerance);
+ TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDDOWN, expected, number, places, tolerance);
}
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRowCol.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRowCol.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRowCol.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRowCol.java Sat May 22 20:56:44 2021
@@ -27,74 +27,74 @@ import org.junit.jupiter.api.Test;
*/
final class TestRowCol {
- @Test
- void testCol() {
- Function target = Column::evaluate;
- {
- ValueEval[] args = { EvalFactory.createRefEval("C5"), };
- double actual = NumericFunctionInvoker.invoke(target, args);
- assertEquals(3, actual, 0D);
- }
- {
- ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
- double actual = NumericFunctionInvoker.invoke(target, args);
- assertEquals(5, actual, 0D);
- }
- }
-
- @Test
- void testRow() {
- Function target = RowFunc::evaluate;
- {
- ValueEval[] args = { EvalFactory.createRefEval("C5"), };
- double actual = NumericFunctionInvoker.invoke(target, args);
- assertEquals(5, actual, 0D);
- }
- {
- ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
- double actual = NumericFunctionInvoker.invoke(target, args);
- assertEquals(2, actual, 0D);
- }
- }
-
- @Test
- void testColumns() {
-
- confirmColumnsFunc("A1:F1", 6, 1);
- confirmColumnsFunc("A1:C2", 3, 2);
- confirmColumnsFunc("A1:B3", 2, 3);
- confirmColumnsFunc("A1:A6", 1, 6);
-
- ValueEval[] args = { EvalFactory.createRefEval("C5"), };
- double actual = NumericFunctionInvoker.invoke(new Columns(), args);
- assertEquals(1, actual, 0D);
- }
-
- @Test
- void testRows() {
-
- confirmRowsFunc("A1:F1", 6, 1);
- confirmRowsFunc("A1:C2", 3, 2);
- confirmRowsFunc("A1:B3", 2, 3);
- confirmRowsFunc("A1:A6", 1, 6);
-
- ValueEval[] args = { EvalFactory.createRefEval("C5"), };
- double actual = NumericFunctionInvoker.invoke(new Rows(), args);
- assertEquals(1, actual, 0D);
- }
-
- private static void confirmRowsFunc(String areaRefStr, int nCols, int nRows) {
- ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
-
- double actual = NumericFunctionInvoker.invoke(new Rows(), args);
- assertEquals(nRows, actual, 0D);
- }
-
-
- private static void confirmColumnsFunc(String areaRefStr, int nCols, int nRows) {
- ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
-
- double actual = NumericFunctionInvoker.invoke(new Columns(), args);
- assertEquals(nCols, actual, 0D);
- }
+ @Test
+ void testCol() {
+ Function target = Column::evaluate;
+ {
+ ValueEval[] args = { EvalFactory.createRefEval("C5"), };
+ double actual = NumericFunctionInvoker.invoke(target, args);
+ assertEquals(3, actual, 0D);
+ }
+ {
+ ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
+ double actual = NumericFunctionInvoker.invoke(target, args);
+ assertEquals(5, actual, 0D);
+ }
+ }
+
+ @Test
+ void testRow() {
+ Function target = RowFunc::evaluate;
+ {
+ ValueEval[] args = { EvalFactory.createRefEval("C5"), };
+ double actual = NumericFunctionInvoker.invoke(target, args);
+ assertEquals(5, actual, 0D);
+ }
+ {
+ ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
+ double actual = NumericFunctionInvoker.invoke(target, args);
+ assertEquals(2, actual, 0D);
+ }
+ }
+
+ @Test
+ void testColumns() {
+
+ confirmColumnsFunc("A1:F1", 6, 1);
+ confirmColumnsFunc("A1:C2", 3, 2);
+ confirmColumnsFunc("A1:B3", 2, 3);
+ confirmColumnsFunc("A1:A6", 1, 6);
+
+ ValueEval[] args = { EvalFactory.createRefEval("C5"), };
+ double actual = NumericFunctionInvoker.invoke(new Columns(), args);
+ assertEquals(1, actual, 0D);
+ }
+
+ @Test
+ void testRows() {
+
+ confirmRowsFunc("A1:F1", 6, 1);
+ confirmRowsFunc("A1:C2", 3, 2);
+ confirmRowsFunc("A1:B3", 2, 3);
+ confirmRowsFunc("A1:A6", 1, 6);
+
+ ValueEval[] args = { EvalFactory.createRefEval("C5"), };
+ double actual = NumericFunctionInvoker.invoke(new Rows(), args);
+ assertEquals(1, actual, 0D);
+ }
+
+ private static void confirmRowsFunc(String areaRefStr, int nCols, int nRows) {
+ ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
+
+ double actual = NumericFunctionInvoker.invoke(new Rows(), args);
+ assertEquals(nRows, actual, 0D);
+ }
+
+
+ private static void confirmColumnsFunc(String areaRefStr, int nCols, int nRows) {
+ ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
+
+ double actual = NumericFunctionInvoker.invoke(new Columns(), args);
+ assertEquals(nCols, actual, 0D);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSlope.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSlope.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSlope.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSlope.java Sat May 22 20:56:44 2021
@@ -30,111 +30,111 @@ import org.junit.jupiter.api.Test;
* Test for Excel function SLOPE()
*/
final class TestSlope {
- private static final Function SLOPE = new Slope();
+ private static final Function SLOPE = new Slope();
- private static ValueEval invoke(Function function, ValueEval xArray, ValueEval yArray) {
- ValueEval[] args = new ValueEval[] { xArray, yArray, };
- return function.evaluate(args, -1, (short)-1);
- }
-
- private void confirm(Function function, ValueEval xArray, ValueEval yArray, double expected) {
- ValueEval result = invoke(function, xArray, yArray);
- assertEquals(NumberEval.class, result.getClass());
- assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
- }
- private void confirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
- ValueEval result = invoke(function, xArray, yArray);
- assertEquals(ErrorEval.class, result.getClass());
- assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
- }
-
- private void confirmError(ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
- confirmError(SLOPE, xArray, yArray, expectedError);
- }
-
- @Test
- void testBasic() {
- Double exp = Math.pow(10, 7.5);
- ValueEval[] yValues = {
- new NumberEval(3+exp),
- new NumberEval(4+exp),
- new NumberEval(2+exp),
- new NumberEval(5+exp),
- new NumberEval(4+exp),
- new NumberEval(7+exp),
- };
- ValueEval areaEvalY = createAreaEval(yValues);
-
- ValueEval[] xValues = {
- new NumberEval(1),
- new NumberEval(2),
- new NumberEval(3),
- new NumberEval(4),
- new NumberEval(5),
- new NumberEval(6),
- };
- ValueEval areaEvalX = createAreaEval(xValues);
- confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045);
- // Excel 2010 gives 0.775280898876405
- }
-
- /**
- * number of items in array is not limited to 30
- */
- @Test
- 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
- ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
-
- confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
- // Excel 2010 gives -1.23152709359606
- }
-
- private ValueEval[] createMockNumberArray(int size, double value) {
- ValueEval[] result = new ValueEval[size];
- for (int i = 0; i < result.length; i++) {
- result[i] = new NumberEval((i+1)%value);
- }
- return result;
- }
-
- private static ValueEval createAreaEval(ValueEval[] values) {
- String refStr = "A1:A" + values.length;
- return EvalFactory.createAreaEval(refStr, values);
- }
-
- @Test
- void testErrors() {
- ValueEval[] xValues = {
- ErrorEval.REF_INVALID,
- new NumberEval(2),
- };
- ValueEval areaEvalX = createAreaEval(xValues);
- ValueEval[] yValues = {
- new NumberEval(2),
- ErrorEval.NULL_INTERSECTION,
- };
- ValueEval areaEvalY = createAreaEval(yValues);
- ValueEval[] zValues = { // wrong size
- new NumberEval(2),
- };
- ValueEval areaEvalZ = createAreaEval(zValues);
-
- // if either arg is an error, that error propagates
- confirmError(ErrorEval.REF_INVALID, ErrorEval.NAME_INVALID, ErrorEval.REF_INVALID);
- confirmError(areaEvalX, ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
- confirmError(ErrorEval.NAME_INVALID, areaEvalX, ErrorEval.NAME_INVALID);
-
- // array sizes must match
- confirmError(areaEvalX, areaEvalZ, ErrorEval.NA);
- confirmError(areaEvalZ, areaEvalY, ErrorEval.NA);
-
- // any error in an array item propagates up
- confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
-
- // search for errors array by array, not pair by pair
- confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
- confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
- }
+ private static ValueEval invoke(Function function, ValueEval xArray, ValueEval yArray) {
+ ValueEval[] args = new ValueEval[] { xArray, yArray, };
+ return function.evaluate(args, -1, (short)-1);
+ }
+
+ private void confirm(Function function, ValueEval xArray, ValueEval yArray, double expected) {
+ ValueEval result = invoke(function, xArray, yArray);
+ assertEquals(NumberEval.class, result.getClass());
+ assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
+ }
+ private void confirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
+ ValueEval result = invoke(function, xArray, yArray);
+ assertEquals(ErrorEval.class, result.getClass());
+ assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+ }
+
+ private void confirmError(ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
+ confirmError(SLOPE, xArray, yArray, expectedError);
+ }
+
+ @Test
+ void testBasic() {
+ Double exp = Math.pow(10, 7.5);
+ ValueEval[] yValues = {
+ new NumberEval(3+exp),
+ new NumberEval(4+exp),
+ new NumberEval(2+exp),
+ new NumberEval(5+exp),
+ new NumberEval(4+exp),
+ new NumberEval(7+exp),
+ };
+ ValueEval areaEvalY = createAreaEval(yValues);
+
+ ValueEval[] xValues = {
+ new NumberEval(1),
+ new NumberEval(2),
+ new NumberEval(3),
+ new NumberEval(4),
+ new NumberEval(5),
+ new NumberEval(6),
+ };
+ ValueEval areaEvalX = createAreaEval(xValues);
+ confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045);
+ // Excel 2010 gives 0.775280898876405
+ }
+
+ /**
+ * number of items in array is not limited to 30
+ */
+ @Test
+ 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
+ ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]
+
+ confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
+ // Excel 2010 gives -1.23152709359606
+ }
+
+ private ValueEval[] createMockNumberArray(int size, double value) {
+ ValueEval[] result = new ValueEval[size];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = new NumberEval((i+1)%value);
+ }
+ return result;
+ }
+
+ private static ValueEval createAreaEval(ValueEval[] values) {
+ String refStr = "A1:A" + values.length;
+ return EvalFactory.createAreaEval(refStr, values);
+ }
+
+ @Test
+ void testErrors() {
+ ValueEval[] xValues = {
+ ErrorEval.REF_INVALID,
+ new NumberEval(2),
+ };
+ ValueEval areaEvalX = createAreaEval(xValues);
+ ValueEval[] yValues = {
+ new NumberEval(2),
+ ErrorEval.NULL_INTERSECTION,
+ };
+ ValueEval areaEvalY = createAreaEval(yValues);
+ ValueEval[] zValues = { // wrong size
+ new NumberEval(2),
+ };
+ ValueEval areaEvalZ = createAreaEval(zValues);
+
+ // if either arg is an error, that error propagates
+ confirmError(ErrorEval.REF_INVALID, ErrorEval.NAME_INVALID, ErrorEval.REF_INVALID);
+ confirmError(areaEvalX, ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
+ confirmError(ErrorEval.NAME_INVALID, areaEvalX, ErrorEval.NAME_INVALID);
+
+ // array sizes must match
+ confirmError(areaEvalX, areaEvalZ, ErrorEval.NA);
+ confirmError(areaEvalZ, areaEvalY, ErrorEval.NA);
+
+ // any error in an array item propagates up
+ confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
+
+ // search for errors array by array, not pair by pair
+ confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
+ confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestStatsLib.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestStatsLib.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestStatsLib.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestStatsLib.java Sat May 22 20:56:44 2021
@@ -220,22 +220,22 @@ class TestStatsLib extends BaseTestNumer
}
private static void confirmMode(double[] v, double expectedResult) {
- confirmMode(v, (Double)expectedResult);
+ confirmMode(v, (Double)expectedResult);
}
private static void confirmMode(double[] v, Double expectedResult) {
- double actual;
- try {
- actual = Mode.evaluate(v);
- assertNotNull(expectedResult, "Expected N/A exception was not thrown");
- } catch (EvaluationException e) {
- if (expectedResult == null) {
- assertEquals(ErrorEval.NA, e.getErrorEval());
- return;
- }
- throw new RuntimeException(e);
- }
- assertDouble("mode", expectedResult, actual);
+ double actual;
+ try {
+ actual = Mode.evaluate(v);
+ assertNotNull(expectedResult, "Expected N/A exception was not thrown");
+ } catch (EvaluationException e) {
+ if (expectedResult == null) {
+ assertEquals(ErrorEval.NA, e.getErrorEval());
+ return;
+ }
+ throw new RuntimeException(e);
+ }
+ assertDouble("mode", expectedResult, actual);
}
@Test
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSubtotal.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSubtotal.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSubtotal.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSubtotal.java Sat May 22 20:56:44 2021
@@ -43,47 +43,47 @@ import org.junit.jupiter.api.Test;
* Tests for {@link Subtotal}
*/
final class TestSubtotal {
- private static final int FUNCTION_AVERAGE = 1;
- private static final int FUNCTION_COUNT = 2;
- private static final int FUNCTION_MAX = 4;
- private static final int FUNCTION_MIN = 5;
- private static final int FUNCTION_PRODUCT = 6;
- private static final int FUNCTION_STDEV = 7;
- private static final int FUNCTION_SUM = 9;
-
- private static final double[] TEST_VALUES0 = {
- 1, 2,
- 3, 4,
- 5, 6,
- 7, 8,
- 9, 10
- };
-
- private static void confirmSubtotal(int function, double expected) {
- ValueEval[] values = new ValueEval[TEST_VALUES0.length];
- for (int i = 0; i < TEST_VALUES0.length; i++) {
- values[i] = new NumberEval(TEST_VALUES0[i]);
- }
+ private static final int FUNCTION_AVERAGE = 1;
+ private static final int FUNCTION_COUNT = 2;
+ private static final int FUNCTION_MAX = 4;
+ private static final int FUNCTION_MIN = 5;
+ private static final int FUNCTION_PRODUCT = 6;
+ private static final int FUNCTION_STDEV = 7;
+ private static final int FUNCTION_SUM = 9;
+
+ private static final double[] TEST_VALUES0 = {
+ 1, 2,
+ 3, 4,
+ 5, 6,
+ 7, 8,
+ 9, 10
+ };
+
+ private static void confirmSubtotal(int function, double expected) {
+ ValueEval[] values = new ValueEval[TEST_VALUES0.length];
+ for (int i = 0; i < TEST_VALUES0.length; i++) {
+ values[i] = new NumberEval(TEST_VALUES0[i]);
+ }
- AreaEval arg1 = EvalFactory.createAreaEval("C1:D5", values);
+ AreaEval arg1 = EvalFactory.createAreaEval("C1:D5", values);
ValueEval[] args = {new NumberEval(function), arg1};
- ValueEval result = new Subtotal().evaluate(args, 0, 0);
+ ValueEval result = new Subtotal().evaluate(args, 0, 0);
- assertEquals(NumberEval.class, result.getClass());
- assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
- }
-
- @Test
- void testBasics() {
- confirmSubtotal(FUNCTION_SUM, 55.0);
- confirmSubtotal(FUNCTION_AVERAGE, 5.5);
- confirmSubtotal(FUNCTION_COUNT, 10.0);
- confirmSubtotal(FUNCTION_MAX, 10.0);
- confirmSubtotal(FUNCTION_MIN, 1.0);
- confirmSubtotal(FUNCTION_PRODUCT, 3628800.0);
- confirmSubtotal(FUNCTION_STDEV, 3.0276503540974917);
- }
+ assertEquals(NumberEval.class, result.getClass());
+ assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
+ }
+
+ @Test
+ void testBasics() {
+ confirmSubtotal(FUNCTION_SUM, 55.0);
+ confirmSubtotal(FUNCTION_AVERAGE, 5.5);
+ confirmSubtotal(FUNCTION_COUNT, 10.0);
+ confirmSubtotal(FUNCTION_MAX, 10.0);
+ confirmSubtotal(FUNCTION_MIN, 1.0);
+ confirmSubtotal(FUNCTION_PRODUCT, 3628800.0);
+ confirmSubtotal(FUNCTION_STDEV, 3.0276503540974917);
+ }
@Test
void testAvg() throws IOException {
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumif.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumif.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumif.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumif.java Sat May 22 20:56:44 2021
@@ -34,86 +34,86 @@ import org.junit.jupiter.api.Test;
* Test cases for SUMPRODUCT()
*/
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);
- private static final NumberEval _60 = new NumberEval(60);
-
- 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) {
- assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
- NumericValueEval nve = (NumericValueEval)actualEval;
- assertEquals(expected, nve.getNumberValue(), 0);
- }
-
- @Test
- void testBasic() {
- ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 };
- ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 };
-
- AreaEval arg0;
- AreaEval arg2;
-
- arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
- arg2 = EvalFactory.createAreaEval("D1:E3", arg2values);
-
- confirm(60.0, arg0, new NumberEval(30.0));
- confirm(70.0, arg0, new NumberEval(30.0), arg2);
- confirm(100.0, arg0, new StringEval(">45"));
- confirm(100.0, arg0, new StringEval(">=45"));
- confirm(100.0, arg0, new StringEval(">=50.0"));
- confirm(140.0, arg0, new StringEval("<45"));
- confirm(140.0, arg0, new StringEval("<=45"));
- 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) {
- confirmDouble(expectedResult, invokeSumif(-1, -1, args));
- }
-
-
- /**
- * test for bug observed near svn r882931
- */
- @Test
- void testCriteriaArgRange() {
- ValueEval[] arg0values = new ValueEval[] { _50, _60, _50, _50, _50, _30, };
- ValueEval[] arg1values = new ValueEval[] { _30, _40, _50, _60, };
-
- AreaEval arg0;
- AreaEval arg1;
- ValueEval ve;
-
- arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
- arg1 = EvalFactory.createAreaEval("A2:D2", arg1values); // single row range
-
- ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1
- if (ve instanceof NumberEval) {
- NumberEval ne = (NumberEval) ve;
- assertNotEquals(30.0, ne.getNumberValue(), "identified error in SUMIF - criteria arg not evaluated properly");
- }
-
- confirmDouble(200, ve);
-
- arg0 = EvalFactory.createAreaEval("C1:D3", arg0values);
- arg1 = EvalFactory.createAreaEval("B1:B4", arg1values); // single column range
-
- ve = invokeSumif(3, 0, arg0, arg1); // invoking from cell A4
-
- confirmDouble(60, ve);
- }
-
- @Test
- void testEvaluateException() {
- assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, BlankEval.instance, new NumberEval(30.0)));
+ private static final NumberEval _30 = new NumberEval(30);
+ private static final NumberEval _40 = new NumberEval(40);
+ private static final NumberEval _50 = new NumberEval(50);
+ private static final NumberEval _60 = new NumberEval(60);
+
+ 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) {
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
+ NumericValueEval nve = (NumericValueEval)actualEval;
+ assertEquals(expected, nve.getNumberValue(), 0);
+ }
+
+ @Test
+ void testBasic() {
+ ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 };
+ ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 };
+
+ AreaEval arg0;
+ AreaEval arg2;
+
+ arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
+ arg2 = EvalFactory.createAreaEval("D1:E3", arg2values);
+
+ confirm(60.0, arg0, new NumberEval(30.0));
+ confirm(70.0, arg0, new NumberEval(30.0), arg2);
+ confirm(100.0, arg0, new StringEval(">45"));
+ confirm(100.0, arg0, new StringEval(">=45"));
+ confirm(100.0, arg0, new StringEval(">=50.0"));
+ confirm(140.0, arg0, new StringEval("<45"));
+ confirm(140.0, arg0, new StringEval("<=45"));
+ 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) {
+ confirmDouble(expectedResult, invokeSumif(-1, -1, args));
+ }
+
+
+ /**
+ * test for bug observed near svn r882931
+ */
+ @Test
+ void testCriteriaArgRange() {
+ ValueEval[] arg0values = new ValueEval[] { _50, _60, _50, _50, _50, _30, };
+ ValueEval[] arg1values = new ValueEval[] { _30, _40, _50, _60, };
+
+ AreaEval arg0;
+ AreaEval arg1;
+ ValueEval ve;
+
+ arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
+ arg1 = EvalFactory.createAreaEval("A2:D2", arg1values); // single row range
+
+ ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1
+ if (ve instanceof NumberEval) {
+ NumberEval ne = (NumberEval) ve;
+ assertNotEquals(30.0, ne.getNumberValue(), "identified error in SUMIF - criteria arg not evaluated properly");
+ }
+
+ confirmDouble(200, ve);
+
+ arg0 = EvalFactory.createAreaEval("C1:D3", arg0values);
+ arg1 = EvalFactory.createAreaEval("B1:B4", arg1values); // single column range
+
+ ve = invokeSumif(3, 0, arg0, arg1); // invoking from cell A4
+
+ confirmDouble(60, ve);
+ }
+
+ @Test
+ 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)));
assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, new NumberEval(30.0), BlankEval.instance, new NumberEval(30.0)));
assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, new NumberEval(30.0), new NumberEval(30.0), BlankEval.instance));
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumifs.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumifs.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumifs.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumifs.java Sat May 22 20:56:44 2021
@@ -42,15 +42,15 @@ final class TestSumifs {
private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
- private static ValueEval invokeSumifs(ValueEval[] args) {
- return new Sumifs().evaluate(args, EC);
- }
-
- private static void confirmDouble(double expected, ValueEval actualEval) {
- assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
- NumericValueEval nve = (NumericValueEval)actualEval;
- assertEquals(expected, nve.getNumberValue(), 0);
- }
+ private static ValueEval invokeSumifs(ValueEval[] args) {
+ return new Sumifs().evaluate(args, EC);
+ }
+
+ private static void confirmDouble(double expected, ValueEval actualEval) {
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
+ NumericValueEval nve = (NumericValueEval)actualEval;
+ assertEquals(expected, nve.getNumberValue(), 0);
+ }
private static void confirm(double expectedResult, ValueEval[] args) {
confirmDouble(expectedResult, invokeSumifs(args));
@@ -61,7 +61,7 @@ final class TestSumifs {
* http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx
*/
@Test
- void testExample1() {
+ void testExample1() {
// mimic test sample from http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx
ValueEval[] a2a9 = new ValueEval[] {
new NumberEval(5),
@@ -137,7 +137,7 @@ final class TestSumifs {
};
assertEquals(ErrorEval.VALUE_INVALID, invokeSumifs(args));
- }
+ }
/**
* Example 2 from
@@ -151,7 +151,7 @@ final class TestSumifs {
new NumberEval(8321),
new NumberEval(500)
};
- // 1% 0.5% 3% 4%
+ // 1% 0.5% 3% 4%
ValueEval[] b3e3 = new ValueEval[] {
new NumberEval(0.01),
new NumberEval(0.005),
@@ -159,7 +159,7 @@ final class TestSumifs {
new NumberEval(0.04)
};
- // 1% 1.3% 2.1% 2%
+ // 1% 1.3% 2.1% 2%
ValueEval[] b4e4 = new ValueEval[] {
new NumberEval(0.01),
new NumberEval(0.013),
@@ -167,7 +167,7 @@ final class TestSumifs {
new NumberEval(0.02)
};
- // 0.5% 3% 1% 4%
+ // 0.5% 3% 1% 4%
ValueEval[] b5e5 = new ValueEval[] {
new NumberEval(0.005),
new NumberEval(0.03),
@@ -196,14 +196,14 @@ final class TestSumifs {
*/
@Test
void testExample3() {
- //3.3 0.8 5.5 5.5
+ //3.3 0.8 5.5 5.5
ValueEval[] b2e2 = new ValueEval[] {
new NumberEval(3.3),
new NumberEval(0.8),
new NumberEval(5.5),
new NumberEval(5.5)
};
- // 55 39 39 57.5
+ // 55 39 39 57.5
ValueEval[] b3e3 = new ValueEval[] {
new NumberEval(55),
new NumberEval(39),
@@ -211,7 +211,7 @@ final class TestSumifs {
new NumberEval(57.5)
};
- // 6.5 19.5 6 6.5
+ // 6.5 19.5 6 6.5
ValueEval[] b4e4 = new ValueEval[] {
new NumberEval(6.5),
new NumberEval(19.5),
@@ -318,7 +318,7 @@ final class TestSumifs {
sheet.getRow(1).createCell(1).setCellValue("A");
setCellFormula(sheet, 0, 3, "SUMIFS(A:A,A:A,A2)");
*/
- ValueEval[] a0a1 = new ValueEval[] {
+ ValueEval[] a0a1 = new ValueEval[] {
NumberEval.ZERO,
NumberEval.ZERO
};
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumproduct.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumproduct.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumproduct.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumproduct.java Sat May 22 20:56:44 2021
@@ -33,89 +33,89 @@ import org.junit.jupiter.api.Test;
*/
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) {
- assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
- NumericValueEval nve = (NumericValueEval)actualEval;
- assertEquals(expected, nve.getNumberValue(), 0);
- }
-
- @Test
- void testScalarSimple() {
-
- RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
- ValueEval[] args = {
- refEval,
- new NumberEval(2),
- };
- ValueEval result = invokeSumproduct(args);
- confirmDouble(6D, result);
- }
-
- @Test
- void testAreaSimple() {
- ValueEval[] aValues = {
- new NumberEval(2),
- new NumberEval(4),
- new NumberEval(5),
- };
- ValueEval[] bValues = {
- new NumberEval(3),
- new NumberEval(6),
- new NumberEval(7),
- };
- AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues);
- AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues);
-
- ValueEval[] args = { aeA, aeB, };
- ValueEval result = invokeSumproduct(args);
- confirmDouble(65D, result);
- }
-
- /**
- * For scalar products, the terms may be 1x1 area refs
- */
- @Test
- void testOneByOneArea() {
-
- AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7), });
-
- ValueEval[] args = {
- ae,
- new NumberEval(2),
- };
- ValueEval result = invokeSumproduct(args);
- confirmDouble(14D, result);
- }
-
- @Test
- void testMismatchAreaDimensions() {
-
- AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]);
- AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]);
-
- ValueEval[] args;
- args = new ValueEval[] { aeA, aeB, };
- assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
-
- args = new ValueEval[] { aeA, new NumberEval(5), };
- assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
- }
-
- @Test
- void testAreaWithErrorCell() {
- ValueEval[] aValues = {
- ErrorEval.REF_INVALID,
- null,
- };
- AreaEval aeA = EvalFactory.createAreaEval("A1:A2", aValues);
- AreaEval aeB = EvalFactory.createAreaEval("B1:B2", new ValueEval[2]);
-
- ValueEval[] args = { aeA, aeB, };
- assertEquals(ErrorEval.REF_INVALID, invokeSumproduct(args));
- }
+ 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) {
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
+ NumericValueEval nve = (NumericValueEval)actualEval;
+ assertEquals(expected, nve.getNumberValue(), 0);
+ }
+
+ @Test
+ void testScalarSimple() {
+
+ RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
+ ValueEval[] args = {
+ refEval,
+ new NumberEval(2),
+ };
+ ValueEval result = invokeSumproduct(args);
+ confirmDouble(6D, result);
+ }
+
+ @Test
+ void testAreaSimple() {
+ ValueEval[] aValues = {
+ new NumberEval(2),
+ new NumberEval(4),
+ new NumberEval(5),
+ };
+ ValueEval[] bValues = {
+ new NumberEval(3),
+ new NumberEval(6),
+ new NumberEval(7),
+ };
+ AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues);
+ AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues);
+
+ ValueEval[] args = { aeA, aeB, };
+ ValueEval result = invokeSumproduct(args);
+ confirmDouble(65D, result);
+ }
+
+ /**
+ * For scalar products, the terms may be 1x1 area refs
+ */
+ @Test
+ void testOneByOneArea() {
+
+ AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7), });
+
+ ValueEval[] args = {
+ ae,
+ new NumberEval(2),
+ };
+ ValueEval result = invokeSumproduct(args);
+ confirmDouble(14D, result);
+ }
+
+ @Test
+ void testMismatchAreaDimensions() {
+
+ AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]);
+ AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]);
+
+ ValueEval[] args;
+ args = new ValueEval[] { aeA, aeB, };
+ assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
+
+ args = new ValueEval[] { aeA, new NumberEval(5), };
+ assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
+ }
+
+ @Test
+ void testAreaWithErrorCell() {
+ ValueEval[] aValues = {
+ ErrorEval.REF_INVALID,
+ null,
+ };
+ AreaEval aeA = EvalFactory.createAreaEval("A1:A2", aValues);
+ AreaEval aeB = EvalFactory.createAreaEval("B1:B2", new ValueEval[2]);
+
+ ValueEval[] args = { aeA, aeB, };
+ assertEquals(ErrorEval.REF_INVALID, invokeSumproduct(args));
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTFunc.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTFunc.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTFunc.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTFunc.java Sat May 22 20:56:44 2021
@@ -36,103 +36,103 @@ import org.junit.jupiter.api.Test;
*/
final class TestTFunc {
- /**
- * @return the result of calling function T() with the specified argument
- */
- private static ValueEval invokeT(ValueEval arg) {
- ValueEval[] args = { arg, };
- ValueEval result = new T().evaluate(args, -1, (short)-1);
- assertNotNull(result, "result may never be null");
- return result;
- }
-
- /**
- * Simulates call: T(A1)
- * where cell A1 has the specified innerValue
- */
- private ValueEval invokeTWithReference(ValueEval innerValue) {
- ValueEval arg = EvalFactory.createRefEval("$B$2", innerValue);
- return invokeT(arg);
- }
-
- private static void confirmText(String text) {
- ValueEval arg = new StringEval(text);
- ValueEval eval = invokeT(arg);
- StringEval se = (StringEval) eval;
- assertEquals(text, se.getStringValue());
- }
-
- @Test
- void testTextValues() {
- confirmText("abc");
- confirmText("");
- confirmText(" ");
- confirmText("~");
- confirmText("123");
- confirmText("TRUE");
- }
+ /**
+ * @return the result of calling function T() with the specified argument
+ */
+ private static ValueEval invokeT(ValueEval arg) {
+ ValueEval[] args = { arg, };
+ ValueEval result = new T().evaluate(args, -1, (short)-1);
+ assertNotNull(result, "result may never be null");
+ return result;
+ }
+
+ /**
+ * Simulates call: T(A1)
+ * where cell A1 has the specified innerValue
+ */
+ private ValueEval invokeTWithReference(ValueEval innerValue) {
+ ValueEval arg = EvalFactory.createRefEval("$B$2", innerValue);
+ return invokeT(arg);
+ }
+
+ private static void confirmText(String text) {
+ ValueEval arg = new StringEval(text);
+ ValueEval eval = invokeT(arg);
+ StringEval se = (StringEval) eval;
+ assertEquals(text, se.getStringValue());
+ }
+
+ @Test
+ void testTextValues() {
+ confirmText("abc");
+ confirmText("");
+ confirmText(" ");
+ confirmText("~");
+ confirmText("123");
+ confirmText("TRUE");
+ }
- private static void confirmError(ValueEval arg) {
- ValueEval eval = invokeT(arg);
+ private static void confirmError(ValueEval arg) {
+ ValueEval eval = invokeT(arg);
assertSame(arg, eval);
- }
+ }
- @Test
- void testErrorValues() {
+ @Test
+ void testErrorValues() {
- confirmError(ErrorEval.VALUE_INVALID);
- confirmError(ErrorEval.NA);
- confirmError(ErrorEval.REF_INVALID);
- }
-
- private static void confirmString(ValueEval eval, String expected) {
- assertTrue(eval instanceof StringEval);
- assertEquals(expected, ((StringEval)eval).getStringValue());
- }
-
- private static void confirmOther(ValueEval arg) {
- ValueEval eval = invokeT(arg);
- confirmString(eval, "");
- }
-
- @Test
- void testOtherValues() {
- confirmOther(new NumberEval(2));
- confirmOther(BoolEval.FALSE);
- confirmOther(BlankEval.instance); // can this particular case be verified?
- }
-
- @Test
- void testRefValues() {
- ValueEval eval;
-
- eval = invokeTWithReference(new StringEval("def"));
- confirmString(eval, "def");
- eval = invokeTWithReference(new StringEval(" "));
- confirmString(eval, " ");
-
- eval = invokeTWithReference(new NumberEval(2));
- confirmString(eval, "");
- eval = invokeTWithReference(BoolEval.TRUE);
- confirmString(eval, "");
+ confirmError(ErrorEval.VALUE_INVALID);
+ confirmError(ErrorEval.NA);
+ confirmError(ErrorEval.REF_INVALID);
+ }
+
+ private static void confirmString(ValueEval eval, String expected) {
+ assertTrue(eval instanceof StringEval);
+ assertEquals(expected, ((StringEval)eval).getStringValue());
+ }
+
+ private static void confirmOther(ValueEval arg) {
+ ValueEval eval = invokeT(arg);
+ confirmString(eval, "");
+ }
+
+ @Test
+ void testOtherValues() {
+ confirmOther(new NumberEval(2));
+ confirmOther(BoolEval.FALSE);
+ confirmOther(BlankEval.instance); // can this particular case be verified?
+ }
+
+ @Test
+ void testRefValues() {
+ ValueEval eval;
+
+ eval = invokeTWithReference(new StringEval("def"));
+ confirmString(eval, "def");
+ eval = invokeTWithReference(new StringEval(" "));
+ confirmString(eval, " ");
+
+ eval = invokeTWithReference(new NumberEval(2));
+ confirmString(eval, "");
+ eval = invokeTWithReference(BoolEval.TRUE);
+ confirmString(eval, "");
- eval = invokeTWithReference(ErrorEval.NAME_INVALID);
+ eval = invokeTWithReference(ErrorEval.NAME_INVALID);
assertSame(eval, ErrorEval.NAME_INVALID);
- }
+ }
- @Test
- void testAreaArg() {
- ValueEval[] areaValues = new ValueEval[] {
- new StringEval("abc"), new StringEval("def"),
- new StringEval("ghi"), new StringEval("jkl"),
- };
- AreaEval ae = EvalFactory.createAreaEval("C10:D11", areaValues);
-
- ValueEval ve = invokeT(ae);
- confirmString(ve, "abc");
-
- areaValues[0] = new NumberEval(5.0);
- ve = invokeT(ae);
- confirmString(ve, "");
- }
+ @Test
+ void testAreaArg() {
+ ValueEval[] areaValues = new ValueEval[] {
+ new StringEval("abc"), new StringEval("def"),
+ new StringEval("ghi"), new StringEval("jkl"),
+ };
+ AreaEval ae = EvalFactory.createAreaEval("C10:D11", areaValues);
+
+ ValueEval ve = invokeT(ae);
+ confirmString(ve, "abc");
+
+ areaValues[0] = new NumberEval(5.0);
+ ve = invokeT(ae);
+ confirmString(ve, "");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org