From 90118b657cadc9df20f7202817ca329a5a88c1d6 Mon Sep 17 00:00:00 2001 From: Oswaldo Baptista Vicente Junior <45291656+oswaldobapvicjr@users.noreply.github.com> Date: Wed, 25 Sep 2024 23:27:14 -0300 Subject: [PATCH] Add Markdown and test variants --- docs/references/functions.md | 2 +- .../ezylang/evalex/functions/basic/AverageFunction.java | 2 +- .../ezylang/evalex/functions/basic/AverageArrayTest.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/references/functions.md b/docs/references/functions.md index cfb9d03..e50630d 100644 --- a/docs/references/functions.md +++ b/docs/references/functions.md @@ -14,7 +14,7 @@ Available through the _ExpressionConfiguration.StandardFunctionsDictionary_ cons | Name | Description | |---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------| | ABS(value) | Absolute (non-negative) value | -| AVERAGE(value, ...) | Returns the average (arithmetic mean) of all parameters. | +| AVERAGE(value, ...) | Returns the average (arithmetic mean) of all parameters. If a parameter is of type _ARRAY_, the average of all elements is calculated. | | CEILING(value) | Rounds the given value an integer using the rounding mode CEILING | | COALESCE(value, ...) | Returns the first non-null parameter, or NULL if all parameters are null | | FACT(base) | Calculates the factorial of a base value | diff --git a/src/main/java/com/ezylang/evalex/functions/basic/AverageFunction.java b/src/main/java/com/ezylang/evalex/functions/basic/AverageFunction.java index c726ebd..9eac51d 100644 --- a/src/main/java/com/ezylang/evalex/functions/basic/AverageFunction.java +++ b/src/main/java/com/ezylang/evalex/functions/basic/AverageFunction.java @@ -49,7 +49,7 @@ private BigDecimal average(MathContext mathContext, EvaluationValue... parameter } private SumAndCount recursiveSumAndCount(EvaluationValue parameter) { - SumAndCount aux = new SumAndCount(BigDecimal.ZERO, BigDecimal.ZERO); + SumAndCount aux = new SumAndCount(); if (parameter.isArrayValue()) { for (EvaluationValue element : parameter.getArrayValue()) { aux = aux.plus(recursiveSumAndCount(element)); diff --git a/src/test/java/com/ezylang/evalex/functions/basic/AverageArrayTest.java b/src/test/java/com/ezylang/evalex/functions/basic/AverageArrayTest.java index 9d3e87f..b188c18 100644 --- a/src/test/java/com/ezylang/evalex/functions/basic/AverageArrayTest.java +++ b/src/test/java/com/ezylang/evalex/functions/basic/AverageArrayTest.java @@ -17,6 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.List; + import com.ezylang.evalex.EvaluationException; import com.ezylang.evalex.Expression; import com.ezylang.evalex.parser.ParseException; @@ -40,8 +42,8 @@ void testAverageSingleArray() throws EvaluationException, ParseException { @Test void testAverageMultipleArray() throws EvaluationException, ParseException { - Integer[] numbers1 = {1, 2, 3}; - Integer[] numbers2 = {4, 5, 6}; + List numbers1 = List.of(1, 2, 3); + List numbers2 = List.of(4, 5, 6); Expression expression = new Expression("AVERAGE(numbers1, numbers2)") @@ -53,7 +55,7 @@ void testAverageMultipleArray() throws EvaluationException, ParseException { @Test void testAverageMixedArrayNumber() throws EvaluationException, ParseException { - Integer[] numbers = {1, 2, 3}; + Double[] numbers = {1.0, 2.0, 3.0}; Expression expression = new Expression("AVERAGE(numbers, 4)").with("numbers", numbers);