CSC300: Debugging

Contents [0/2]

Video [1/2]
Debugging Demo [2/2]

(Click here for one slide per page)


Video [1/2]

Open Playlist

00:00 The example problem
05:00 Debugging with print messages
07:41 Debugging with an interactive debugger
08:52 Setting a breakpoint
09:51 The debugging perspective
11:16 Stepping in the debugger
15:44 Finding the bug!

Debugging Demo [2/2]

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package algs11;
import stdlib.*;
import java.util.Arrays;
public class Playground {
  public static int divThreeMinusDivFive (double[] a) {
    //StdOut.format ("a=%s\n", Arrays.toString(a));
    int div3 = 0;
    int div5 = 0;
    for (int i = 0; i < a.length; i += 1) {
      if (a[i]%3 == 0) { div3 += 1; }
      else if (a[i]%5 == 0) { div3 += 1; }
      //StdOut.format ("  i=%d, div3=%d, div5=%d\n", i, div3, div5);
    }
    return div3 - div5;
  }
  public static void testDivThreeMinusDivFive (int expected, double[] list) {
    int actual = divThreeMinusDivFive (list);
    if (expected != actual) {
      StdOut.format ("Failed: Expecting [%d] Actual [%d] with argument %s\n", expected, actual, Arrays.toString (list));
    }
  }
  public static void main (String[] args) {
    testDivThreeMinusDivFive (2, new double[] { 3, 6 });
    testDivThreeMinusDivFive (-2, new double[] { 5, 10 });
    testDivThreeMinusDivFive (0, new double[] { 3, 5, 6, 10 });   
    testDivThreeMinusDivFive (1, new double[] { 3 });
    testDivThreeMinusDivFive (-1, new double[] { 5 });
    testDivThreeMinusDivFive (0, new double[] { 15 });
    StdOut.println ("Finished tests");
  }
}

You can find a tutorial on debugging in eclipse on the course homepage


Revised: 2008/03/17 13:01