I am looking to sum the values of an array and make a quick calculation using the result of that sum, then use the result of that calculation to compare to an already existing number so the comparison forms the condition of the assert. Can I place the for loop and calculations next to the assert keyword, or must I create a function separately that contains the for loop call it from the assert statement?
assert
takes an expression; a for
loop is a statement. You could sum the array in an expression using a streams operation:
assert Arrays.stream(array).sum() == expectedSum;
or, as you suggested, call out to a function that does something similar.