Assertions
Category: Assertions
Author: 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. public static int randomWalk(int steps) { Random rand = new Random(); int x = 0; int r = rand.nextInt(2); <span class="assertionpoint">// Point A while (steps > 0 || x == 0) { <span class="assertionpoint">// Point B if (r == 0) { x++; <span class="assertionpoint">// Point C } else { x = 0; <span class="assertionpoint">// Point D } steps--; r = rand.nextInt(2); } <span class="assertionpoint">// Point E return x; }
1) steps > 0
2) x > 0
3) r > 0