Here’s my test:
@Test
public void randomDouble() {
int Min = -1;
int Max = 1;
double r;
for (int i = 0; i < 5; i++) {
r = Min + (Math.random() * ((Max - Min) + 1));
System.out.printf("%d %d: %.1f\n", Min, Max, r);
assertTrue(Max < r && Max > r);
}
}
It seems that the test returns after the first time the assertTrue statement within the loop is run. If I remove it, I get 5 results output. With it, I get only one.
I use this pattern in Python for fuzz testing.
there’s nothing to restrict asserts from being in loops.
some other points, though:
the test will always fail (see next item for what you probably want)
java has an assert in the language:
assert Min <= r && r <= Max : "bad range"the “+1” in
((Max - Min) + 1)seems wrong to me