]> source.dussan.org Git - poi.git/commitdiff
support gcd function
authorPJ Fanning <fanningpj@apache.org>
Fri, 29 Apr 2022 22:34:20 +0000 (22:34 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 29 Apr 2022 22:34:20 +0000 (22:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1900407 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/ss/formula/functions/TestGcd.java

index 3918557382109faf20fc299ec1e489fa36776678..f476197d77dd32382b4b36a60a83702f61d20516 100644 (file)
@@ -62,24 +62,41 @@ final class TestGcd {
         confirmNumError(Arrays.asList(10, -1));
     }
 
-    private static ValueEval invokeValue(List<Number> numberList) {
+    @Test
+    void testInvalidError() {
+        confirmInvalid(Arrays.asList());
+        confirmInvalid(Arrays.asList("num"));
+        confirmInvalid(Arrays.asList(3, "num"));
+    }
+
+    private static ValueEval invokeValue(List<Object> 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<Number> numberList, double expected) {
+    private static void confirmValue(List<Object> numberList, double expected) {
         ValueEval result = invokeValue(numberList);
         assertEquals(NumberEval.class, result.getClass());
         assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.00000000000001);
     }
 
-    private static void confirmNumError(List<Number> numberList) {
+    private static void confirmNumError(List<Object> numberList) {
         ValueEval result = invokeValue(numberList);
         assertEquals(ErrorEval.class, result.getClass());
         assertEquals(ErrorEval.NUM_ERROR, result);
     }
+
+    private static void confirmInvalid(List<Object> numberList) {
+        ValueEval result = invokeValue(numberList);
+        assertEquals(ErrorEval.class, result.getClass());
+        assertEquals(ErrorEval.VALUE_INVALID, result);
+    }
 }