Testing your solutions to Homework 5

A student asked on Friday if I could post some lists that could be used for testing solutions to Homework 5. Here I provide not only some examples that you can use in your testing, but a general approach supported in Python for testing your code.
  1. First take a look at Chapter 9: Unit Testing in Prof. Ted Herman's lecture notes. In particular, read the example starting on Page 81 carefully.

  2. Now suppose that I have finished solving Problem 1 and have created a function called gradeDistribution and saved this in a file called gradeDistribution.py.

  3. Now take a look at the testing file called gradeDistributionTest.py that I created. This file is in the same directory as the file gradeDistribution.py. It contains 5 tests for the function gradeDistribution.

  4. Download the file gradeDistributionTest.py and use it to test your implementation of the function gradeDistribution. Prof. Steve Miller wrote a solution to Problem 1 and I tested his solution using the test file I created. The solution passed all 5 tests and there was no output.

  5. Now I deliberately introduced an error into Prof. Miller's solution by replacing a "<=" by "<". This caused the program to incorrectly deal with the boundaries of the ranges. Specifically, 10 got included in the second range, 20 was included in the third range, etc. When I test this erroneous solution against the test file gradeDistributionTest.py, I got the following output:

    **********************************************************************
    File "gradeDistributionTest.py", line 2, in __main__
    Failed example:
        gradeDistribution([17, 25, 33, 12, 10.0, 98, 88.5])
    Expected:
        [1, 2, 1, 1, 0, 0, 0, 0, 1, 1]
    Got:
        [0, 3, 1, 1, 0, 0, 0, 0, 1, 1]
    **********************************************************************
    File "gradeDistributionTest.py", line 4, in __main__
    Failed example:
        gradeDistribution([10, 20, 30, 40, 80, 80.5, 100])
    Expected:
        [1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
    Got:
        [0, 1, 1, 1, 1, 0, 0, 0, 2, 0]
    **********************************************************************
    File "gradeDistributionTest.py", line 10, in __main__
    Failed example:
        gradeDistribution([90, 91, 0, 100])
    Expected:
        [1, 0, 0, 0, 0, 0, 0, 0, 1, 2]
    Got:
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 2]
    **********************************************************************
    1 items had failures:
       3 of   5 in __main__
    ***Test Failed*** 3 failures.
    

    This output clearly shows that three out of the 5 tests failed. If you examine the first failue and compare what was "Expected" and what was "Got" you will see that the error was because 10.0 got included in the second range, rather than the first.

    In the next day of two we plan on posting similar test files for Problems 1-3 in HW5. You should use these test files to test your functions. We plan on using these test files to automate, to a greater extent, the grading of your homeworks.