Exercise 4 Ė Practice debugging using a test framework


Reminder:  Look at <file:/home/jake/CSC/index.html> for updates or corrections!


Goal: Get a feel for how tests can help you develop better code faster


First, create a local copy of the exercise files.



   tar xf ~jake/CSC/exercise4.tar

   cd exercise4

   source setup.sh


The program is meant to count the numbers that are both squares and cubes within a range. Iíve started development for you by sketching out the class FindVals, along with a test suite in the TestFindVals class.


numInRange is the primary method this class will provide to users; thatís the one that people will invoke.  There are two internal service methods for calculating whether a number is a square (isSquare) and a cube (isCube).  Those were created in company with some tests. 


Youíre picking up these classes in the midst of development.  The isSquare routine has been improved to the point where it passes its tests. Unfortunately, a bug fix we made in isSquare was accidentally not made in isCube, so isCube is not passing its tests.


To compile and run the test suite:



  java TestFindVals g


To get some experience with debugging using a test suite, please


1)    Run the tests, and fix the failures in isCube.  Add some more tests if there are cases you think should be checked.


2)    There are some tests of the important numInRange function further on in the test class, but some of their logic has been replaced with ďÖĒ. Add the appropriate test logic, based on the description in each test.  Then get the FindVals class to pass them.


3)    Add some more tests of the search range, convincing yourself that youíve really got a functioning FindVals class.




*) Just before I turned this development project over to you, I added a "floor" to the isSquare calculation.  Take a look at the failing isCube, and note that itís different.


*) Sometimes the CPU will compute the square-root of a number like 9 and get 2.999999.  "floor" and "round" treat that result differently.