Next: , Up: (dir)

Scripting Languages G22.3033-002 Summer 2008


Previous: Top, Up: Top

Scripting Languages G22.3033-002 Summer 2008 Example solutions for hw09

Assigned Th 7/17/2008, due Mo 7/28 at 9pm. 50 points.

http://www.cs.nyu.edu/courses/summer08/G22.3033-002/


Next: , Up: solutions-hw09

Instructions for example solutions

These are example solutions. Please keep in mind that often, there is not just one correct solution to a question. If you come up with different answers, then it may be that both your answers and these answers here are correct. Of course, these answers here may also contain mistakes. If you spot a mistake, please let me know so I can correct it.


Previous: Instructions, Up: solutions-hw09

Example solutions for Homework 9


Next: , Up: Solutions-hw09

solutions-hw09-1 Scientific Method

  1.           initial input:
               2 1 3
               0 1 1
               4 1 2
              expected output:
               2 1 3
               0 1 1
               4 1 2
               2 1 2
              actual output:
               2 1 3
               0 1 1
               4 1 2
               1 1 2
         
  2.           1 Hypothesis  compute_avg returns wrong value
                            (expected value would be 2 1 2)
                Experiment  perl -wd script.pl
                            b 17
                            c
                            p @result
                Observation 1 1 2
                Conclusion  @result is wrong, hypothesis verified
              2 Hypothesis  at Line 15, numerator $sums[0] is wrong;
                            (expected value would be 2+0+4 == 6)
                Experiment  perl -wd script.pl
                            b 15
                            c
                            p $i, " ", $sums[$i]
                Observation 0 2
                Conclusion  $i == 0 and $sums[$i] == 2 != 6
                            $sums[0] is wrong, hypothesis verified
              3 Hypothesis  Line 10 adds the wrong numbers into $sums[0]
                            (expected 3 iterations with $j==0, values 2 0 4)
                Experiment  perl -wd script.pl
                            a 10 print "==> " . $row->[$j] . "\n" if $j==0;
                            c
                Observation ==> 2
                            ==> 0
                            Debugged program terminated.
                Conclusion  Line 10 adds the correct values from the first two
                            rows, but is missing the value from the third row.
              4 Hypothesis  the outer loop iterates for the wrong number of rows
                            (expected $nrows would be 3)
                Experiment  perl -wd script.pl
                            b 7
                            c
                            p $nrows
                Observation 2
                Conclusion  $nrows == 2, but should be == 3
              5 Hypothesis  the defect is in Line 6, since $#_ gives the index
                            of the last element, but we want the size, which is
                            one larger
                Experiment  change Line 6 to:
                              my $nrows = @_;
                            then rerun script
                Observation expected output and actual output are identical
                Conclusion  done, the bug is fixed
         


Previous: solutions-hw09-1, Up: Solutions-hw09

solutions-hw09-3 Delta Debugging

No example solutions.