Hi all I was wondering how do I put an entire block of code within an assertion?
For example, I have an array and I would like to do assertions on each value of the array. This is what my code looks like:
for (int value : values) {
assert Within(value, x, y);
}
But of course if I run the program without -ea whereby the assertions are turned off, the loop still exists.
I was wondering how do I put the entire loop in an assertion statement?
EDIT:
argh dang Java is really too rigid at times, I ended up doing something functional like this:
assert Every(value, new F1<Boolean, Integer>() {
Boolean Call(Integer value) {
return Within(value, 0, 255);
}
});
You can use a method
Another approach is to test for assertion if you have lots of checks