Lab: Experimenting with Testing (Part II)


Instructions:Omitted

Getting Ready:Omitted

1. The Stages of Testing: This part of the lab will help you understand the benefit of performing unit testing before integration testing.
  1. Edit the SectionComparator class.
  2. Compile the SectionComparator class.
  3. What errors did the compiler find? How did you fix them?

    I replaced bMin = oMin with bMin == oMin and I initialized oMin to Statistics.min(otherGrades).

  4. Edit the SectionComparatorDriver class.
  5. Compile and execute the SectionComparatorDriver.
  6. Which test cases failed?

    Test case A should have returned a 1, test case B should have returned a -1 and test case C should have returned a 1.

  7. bMean and oMean are initialized incorrectly. Fix these faults.
  8. What changes did you make?

    Initialized bMean to Statistics.mean(bernsteinGrades)

    Initialized oMean to Statistics.mean(otherGrades)

  9. Compile and execute the SectionComparatorDriver.
  10. Which test cases failed?

    Same as above.

  11. result is initialized incorrectly. Fix this fault.
  12. What changes did you make?

    Initialized result to 1 (which is the default case given the if statements that follow).

  13. Compile and execute the SectionComparatorDriver.
  14. Which test cases failed?

    Test case B should have returned a -1.

  15. Edit the Statistics class.
  16. There is a fault in the Statistics.min(int[]) method. Specifically, result is initialized incorrectly. Fix this fault by initializing result to data[0].
  17. Compile the Statistics class and execute the SectionComparatorDriver.
  18. Which test cases failed?

    None.

  19. What kind of test case is clearly missing?

    One in which the result is 0.

  20. Add the following initializations to the SectionComparatorDriver:
           int[]              bD = {50, 60, 70};
           int[]              oD = {70, 60, 50};
        

    and add code that uses this test case.

  21. Compile and execute the SectionComparatorDriver class.
  22. What should the result of test case D be and what is it?

    It should be 0 but it is 1.

  23. It is now impossible to know whether this failure is a result of faults in the Statistics class or faults in the SectionComparatorDriver class.
  24. Test the Statistics.max(int[]) method.
  25. What test cases did you use?

  26. What fault(s) did you discover and how did you fix them?

    It didn't work correctly when the maximum was the last element in the array. I changed data.length-1 to data.length.

  27. Compile and execute the SectionComparatorDriver class.
  28. Are there any failures?

    No.

2. The Importance of Unit Testing: This part of the lab will help you understand why you need to complete all unit tests before moving to integration testing.
  1. In spite of the fact that the SectionComparator now appears to work, there is a fault in the Statistics.mean(int[]) method.
  2. Test the Statistics.mean(int[]) method.
  3. What test cases did you use?

  4. What fault(s) did you discover and how did you fix them?

    It doesn't work properly when the array has a no elements.

3. Additional Practice: This part of the lab is optional; complete it on your own if you think you need more practice with testing.
  1. Test the Statistics.mean(int[]) method.
  2. What test cases did you use?

  3. What fault(s) did you discover and how did you fix them?

    It does not work properly for positive numbers.

  4. Test the Statistics.max(int, int) method.
  5. What test cases did you use?

  6. What fault(s) did you discover and how did you fix them?

    It does not work properly when the two values are the same.

  7. Test the Statistics.min(int, int) method.
  8. What test cases did you use?

  9. What fault(s) did you discover and how did you fix them?

    It only works properly when the two values are the same.

  10. Test the Statistics.sign(double) method.
  11. What test cases did you use?

  12. What fault(s) did you discover and how did you fix them?

    It does not work properly for 0.

Copyright 2010