SUNY Geneseo, Department of Computer Science
CSci 141 , Fall 2004
Prof. Doug Baldwin
Due
Wednesday, December 15
Please fill out the Computer
Science Interest Survey!
In this lab you will face and track down some fairly subtle bugs. In particular, they don't always show up -- with some inputs, the buggy programs produce perfectly fine results, with others they produce incorrect ones. In other words, you first need to find test data that reveal the bugs, then you can isolate and correct them.
The first thing to realize is that one test is never enough. Really testing a program requires a whole suite of test cases. Typically each test case consists of one input for the program, and a separate run of the program is needed to test each test case.
Choosing test data is a big concern in all programming. Before a programmer or software company releases a program into the world, they want to be sure that the program doesn't contain any bugs. The best way developers have of verifying that a program is bug-free is still thorough testing (in principle one can mathematically prove that a program is bug-free, but it is a tremendously difficult task given the mathematical techniques presently available). I doubt that there are any significant programs available today that don't contain bugs. This isn't because their developers didn't try to debug the programs, it's because the bug-hunters didn't test the programs on the exact combination of inputs that would have made the bugs show up.
While finding bugs is often as much a matter of luck as of skill, there are some strategies that can at least make your luck better. Here are some of them:
This lab consists of two exercises. Each requires you to test and possibly debug a program. You can find the programs in the folder named "Testing" on the "OutBoxes" server, or you can download them from our "Exercises" page on the World Wide Web.
If you get the programs from "Out Boxes", I recommend copying the entire "Testing" folder to your local disk. Inside "Testing" are sub-folders for each of the two programs. The sub-folders contain complete CodeWarrior projects for their program, i.e., you can open the programs in CodeWarrior simply by double-clicking on the project file.
If you download the programs from the Web, you will get just a Java source file for each program. These files are completely self-contained, i.e., each one contains all the definitions needed by the corresponding program. Thus it should be easy to create projects for each program in whatever development environment you like.
All the programs are set up to prompt you for an input, display some result, and then ask if you want to provide more inputs. Enter "y" or "Y" (without quotation marks) if you do, anything else if you want to stop the program.
All I will tell you right now about the two programs is that they might contain bugs. To the best of my knowledge no program contains more than one bug, but some might not contain any. Your basic job is to test each program until you either know that it has a bug, or are certain that it doesn't. If the program has a bug, you should fix it, and retest to be certain that the bug is completely fixed.
The first exercise is to test the program named "Factor". This program is supposed to print the prime factors of any integer greater than or equal to 2 that you give it. For example, if you enter the number 12, "Factor" should print
12 = 2 X 2 X 3
If you give "Factor" an input that is already prime (say, 7), it should print something like this:
7 = 7
(Recall that a prime number is one that can only be divided evenly by itself and 1; there is a theorem in number theory that says that every integer can be written as a product of prime numbers. These primes are the original number's "prime factors".)
Test the program named "Root". This program's job is to print the square root of any non-negative real number you give it, accurate to 2 decimal places. For example, if you input 4.0 to "Root", it should print 2.00. Beware, however, that real numbers are notorious for round-off error in computing, and all that "Root" guarantees is an answer that is within +/- 0.01 of the actual root. Thus, it could legally display the square root of 4.0 as 1.99, 2.01, 2.005, etc.