Assertions
Category: Assertions
Author: Victoria Kirst
Book Chapter: 5.5
Problem: Assertions
For each of the five points labeled by comments, identify each of the assertions in the table below as either being always true, never true, or sometimes true / sometimes false.
public static int antCrawl(int max) {
Random rand = new Random();
int height = 0;
int falls = 0;
<span class="assertionpoint">// Point A
while (height < max) {
int r = rand.nextInt(4);
<span class="assertionpoint">// Point B
if (r == 0 && height > 0) {
height--;
falls++;
<span class="assertionpoint">// Point C
} else {
height++;
<span class="assertionpoint">// Point D
}
}
<span class="assertionpoint">// Point E
return falls;
}
1) falls == 0
2) height > 0
3) height < max