how to sum a list
#446
Replies: 2 comments
-
|
Hi, as of now, the If you want to contribute that special |
Beta Was this translation helpful? Give feedback.
-
|
I have added this functionality in pull request #449: It is already merged and will be released with version 3.2.0. Here are some examples from the unit test: @Test
void testSumSingleArray() throws EvaluationException, ParseException {
Integer[] numbers = {1, 2, 3};
Expression expression = new Expression("SUM(numbers)").with("numbers", numbers);
assertThat(expression.evaluate().getStringValue()).isEqualTo("6");
}
@Test
void testSumMultipleArray() throws EvaluationException, ParseException {
Integer[] numbers1 = {1, 2, 3};
Integer[] numbers2 = {4, 5, 6};
Expression expression =
new Expression("SUM(numbers1, numbers2)")
.with("numbers1", numbers1)
.with("numbers2", numbers2);
assertThat(expression.evaluate().getStringValue()).isEqualTo("21");
}
@Test
void testSumMixedArrayNumber() throws EvaluationException, ParseException {
Integer[] numbers = {1, 2, 3};
Expression expression = new Expression("SUM(numbers, 4)").with("numbers", numbers);
assertThat(expression.evaluate().getStringValue()).isEqualTo("10");
}
@Test
void testSumNestedArray() throws EvaluationException, ParseException {
Integer[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
Expression expression = new Expression("SUM(numbers)").with("numbers", numbers);
assertThat(expression.evaluate().getStringValue()).isEqualTo("45");
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use sum & divide, but the result is always 0
So that, I change the array values, code like this
the result is correct
How to set the array value ?
Beta Was this translation helpful? Give feedback.
All reactions