Assertions
Category: Assertions
Author: Jessica Miller and Marty Stepp
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. (You may abbreviate them as A, N, or S.)
public static int stuff(Random r, int m) {
int c = 0;
int t = 0;
int d = r.nextInt(m);
<span class="assertionpoint">// Point A
while (c <= 3) {
<span class="assertionpoint">// Point B
d = r.nextInt(6) + 1;
if (d <= m) {
c++;
<span class="assertionpoint">// Point C
} else {
c = 0;
<span class="assertionpoint">// Point D
}
t++;
}
<span class="assertionpoint">// Point E
return t;
}
1) c > 3
2) d <= m
3) c == 0