From: PJ Fanning Date: Fri, 29 Apr 2022 22:34:20 +0000 (+0000) Subject: support gcd function X-Git-Tag: REL_5_2_3~334 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=34d047108e8e310881d868a8883b536fcf6b14da;p=poi.git support gcd function git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1900407 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestGcd.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestGcd.java index 3918557382..f476197d77 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestGcd.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestGcd.java @@ -62,24 +62,41 @@ final class TestGcd { confirmNumError(Arrays.asList(10, -1)); } - private static ValueEval invokeValue(List numberList) { + @Test + void testInvalidError() { + confirmInvalid(Arrays.asList()); + confirmInvalid(Arrays.asList("num")); + confirmInvalid(Arrays.asList(3, "num")); + } + + private static ValueEval invokeValue(List numberList) { ValueEval[] args = new ValueEval[numberList.size()]; int i = 0; - for (Number num : numberList) { - args[i++] = new NumberEval(num.doubleValue()); + for (Object obj : numberList) { + if (obj instanceof Number) { + args[i++] = new NumberEval(((Number)obj).doubleValue()); + } else { + args[i++] = new StringEval(obj.toString()); + } } return Gcd.instance.evaluate(args, ec); } - private static void confirmValue(List numberList, double expected) { + private static void confirmValue(List numberList, double expected) { ValueEval result = invokeValue(numberList); assertEquals(NumberEval.class, result.getClass()); assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.00000000000001); } - private static void confirmNumError(List numberList) { + private static void confirmNumError(List numberList) { ValueEval result = invokeValue(numberList); assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.NUM_ERROR, result); } + + private static void confirmInvalid(List numberList) { + ValueEval result = invokeValue(numberList); + assertEquals(ErrorEval.class, result.getClass()); + assertEquals(ErrorEval.VALUE_INVALID, result); + } }