You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by GitBox <gi...@apache.org> on 2022/04/29 05:05:27 UTC

[GitHub] [poi] sfisque opened a new pull request, #330: Patch averageif

sfisque opened a new pull request, #330:
URL: https://github.com/apache/poi/pull/330

   adds missing support for singular AverageIf function


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113667443

   could you cover example2 from M$ too?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r862012906


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   the M$ examples are rubbish - very focused on a small number of happy path and occasionally an exception case but at least using them as a guide is better than ignoring them and focusing a use case that suits you amand maybe noone else



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque closed pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque closed pull request #330: Patch averageif
URL: https://github.com/apache/poi/pull/330


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113722315

   Can you close this PR? - all this code is  merged to Apache trunk and I have been fixing your bugs and code formatting issues.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r861795347


##########
poi/src/main/java/org/apache/poi/ss/formula/functions/AverageIf.java:
##########
@@ -0,0 +1,133 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.formula.functions;
+
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.AreaEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate;
+
+/**
+ * Handler for singular AverageIf which has different operand handling than
+ * the generic AverageIfs version.
+ */
+public class AverageIf
+extends Baseifs
+{

Review Comment:
   ok. i've never been a fan of K&R formatting, but i can make that change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r862012906


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   the M$ examples are rubbish - very focused on a small number of happy path cases and occasionally an exception case but at least using them as a guide is better than ignoring them and focusing a use case that suits you and maybe noone else



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque-synodex commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque-synodex commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113668970

   ok.  but i'm not aware of "ignoring" the code format request.  i moved all the braces and other bits.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113671308

   I've merged what you've done so far after reformatting the code but with example2 being tested, the new code is suspect and liable for removal


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque-synodex commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque-synodex commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113672581

   i was in the process of adding ex.2 to the test.  should i continue?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113668092

   and you ignored the review comment asking you to respect the code format


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] centic9 commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
centic9 commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r861492974


##########
poi/src/main/java/org/apache/poi/ss/formula/functions/AverageIf.java:
##########
@@ -0,0 +1,133 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.formula.functions;
+
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.AreaEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate;
+
+/**
+ * Handler for singular AverageIf which has different operand handling than
+ * the generic AverageIfs version.
+ */
+public class AverageIf
+extends Baseifs
+{

Review Comment:
   We try to follow a code-style where brackets are on the previous line, can you re-format this class to follow that, also "extends" is usually on the same line as the class, i.e. 
   
   public class AverageIf extends Baseifs {



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r861796135


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   yes.  the danger of cut/paste coding (i stole the UT from averageifs) for expedience.  i can make the change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r862011973


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   can you use the examples from https://support.microsoft.com/en-us/office/averageif-function-faec8e2e-0dec-4308-af69-f5576d8ac642 though - ie the data and test scenarios?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque-synodex commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque-synodex commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113728080

   i do not appear to have that privilege.  i cannot find the close button.  you have my permission to close it if you have that privilege.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113732083

   no worries, i forgot that i forked it under a different user-id.  closed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r861502408


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   should this link be https://support.microsoft.com/en-us/office/averageif-function-faec8e2e-0dec-4308-af69-f5576d8ac642 ? the test data does not match either of the examples on that doc page though



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113731068

   I don't have a direct way to close this. I have un ugly way to close it but may avoid it. It's more important that you verify the apache poi trunk code to verify it works for you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] sfisque commented on a diff in pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
sfisque commented on code in PR #330:
URL: https://github.com/apache/poi/pull/330#discussion_r861796135


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestAverageIf.java:
##########
@@ -0,0 +1,106 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.formula.functions;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+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.FormulaError;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Test cases for AVERAGEIFS()
+ */
+final class TestAverageIf {
+
+    private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null);
+
+    private static ValueEval invokeAverageif(ValueEval[] args) {
+        return new AverageIf().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, invokeAverageif(args));
+    }
+
+    private static void confirmError(ErrorEval errorEval, ValueEval[] args) {
+        ValueEval actualEval = invokeAverageif(args);
+        assertEquals(errorEval, actualEval);
+    }
+
+    /**
+     *  Example 1 from
+     *  https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883

Review Comment:
   yes.  the danger of cut/paste coding (i stole the UT from averageifs for expedience.  i can make the change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[GitHub] [poi] pjfanning commented on pull request #330: Patch averageif

Posted by GitBox <gi...@apache.org>.
pjfanning commented on PR #330:
URL: https://github.com/apache/poi/pull/330#issuecomment-1113701291

   new code is incorrect - I have provided a pull request to your repo - if the example2 is left broken, i will remove all the new code


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org