_ivanovich_
5 years agoFrequent Contributor
How to validate all element from an array are less than a value?
Hi,
say we have an array like this
def my_array = [ [45.26], [44.6],[47.25] ]
def expected = 50 as Float
how do you validate that each element are less than 50
i tried this:
assert my_array .every {it < expected }
It throws:
groovy.lang.GroovyRuntimeException: Cannot compare java.util.ArrayList with value '[45.26]' and java.lang.Float with value '50' error at line: ...
It's comparing this value [45.26] instead of this 45.26
i tried this:
assert my_array.max() < expected
- Hi _ivanovich_,
I know youve resolved your issue, but i have a quick question if thats ok for my education really.
In your array each value was separated by individual square brackets.....why was you doing that? I wouldve thought (without testing your code myself) that your original code wouldve worked if you didnt include the square brackets around each value.....???
Nice one,
Rich