Subject: [CS60] Testing Tips From: "HAKAN YILDIZ" Date: Sun, 19 Apr 2009 14:28:55 -0700 (PDT) To: cs60@lists.cs.ucsb.edu Dear CS60 Students, I feel that some of you are not testing their programs properly. Testing a program is a simple task although it needs some care. A programmer is expected to test his code thoroughly in real world. This is what we expect from you, too. Testing is not just trying one input and seeing if your program works or not. An ideal test would be to try all possible inputs to see if your program works. However, it is inapplicable in most cases. Thus, what most programmers do(or should do) is to try the program with a relatively small but a well-chosen set of inputs. What is a well-chosen input set? First, if you have sample inputs, you should try them. Second, try a few similar inputs that has different outputs. Third, now you should try some simple input cases: An "input case" is a set of inputs in which some property holds. For example, consider a program in which two integers are input. Depending on what the program does, the following may be some input cases: - The input integers are the same. - The input integers are not the same. - The first integer is zero. - The second integer is zero. - The first integer is less than second one. ... Fourth, you should try some input cases for scalability. If your program depends on a parameter or an input N which has a defined range, try your program for both small and high values of it. Fifth, not only you can try input cases but also output cases. For example, consider a program in which two integers are output. Depending on what the program does, the following may be some output cases: - The input integers are the same. - The input integers are not the same. ... Of course, you'll have to find an input that correspond to a desired output. Sixth, randomly try some inputs that does not look the similar. In other words, try a variety of inputs. This is also be applicable for outputs. Seventh, if you think that there is an invalid input which will make your program behave in a certain way, feel free to try it. Observe the expected behaviour of your program. Some more techniques: - You may print some more output, to see if the intermediate values are correctly calculated. This is also a good way of testing. - Be careful while testing. Even more careful than while your programming. - Check every piece of your output while testing. If your program is not scoring 10/10 but you believe that it is correct, this suggests that you haven't tried 10 well-chosen inputs to try your program(which is what grading does). Yours, Hakan _______________________________________________ cs60 mailing list cs60@lists.cs.ucsb.edu https://lists.cs.ucsb.edu/mailman/listinfo/cs60