

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The strategies for testing and debugging in computer science ii - spring 2006 lab 4. The lab focuses on determining what 2d points are in what 2d rectangles. Students are required to write test code, read the code carefully, use the debugger, and complete several checkpoints. The document also provides instructions on how to use the debugger in visual studio.
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Testing and debugging are important steps in programming. Loosely, you can think of testing as verifying that your program works and debugging as finding and fixing errors once you’ve discovered it does not. Writing test code is an important (and sometimes tedious) step. Many software libraries have “regression tests” that run automatically to verify that code is behaving the way it should. Here are four strategies for testing and debugging:
The programming context for this lab is the problem of determining what 2D points are in what 2D rect- angles. For rectangles, we will assume they are aligned with the coordinate axes (a.k.a. axis-aligned). This makes it easy to represent and to test if a point is inside. Our code will create points and rectangles and determine which points are in which rectangles. This type of problem is common in graphics and robotics. The rectangle below is specified by its upper right corner point, (17, 9), and its lower left corner point, (4, 3). The point (9, 3 .5) is inside the rectangle, whereas the point (8, 10) is outside.
y
x
(4,3)
(17,9)
(9,3.5)
(8,10)
Please download the following 3 files needed for this lab and then turn off your internet connection:
http://www.cs.rpi.edu/academics/courses/spring06/cs2/labs/04_debugging/point2D.h http://www.cs.rpi.edu/academics/courses/spring06/cs2/labs/04_debugging/rectangle.h http://www.cs.rpi.edu/academics/courses/spring06/cs2/labs/04_debugging/rectangle.cpp
Start by creating a project and adding the files Point2D.h, Rectangle.h, and Rectangle.cpp. Exam- ine these files briefly. Point2D.h has a simple, self-contained class for representing point coordinates in
two-dimensions. No associated .cpp file is needed because all member functions are defined in the class declaration. Rectangle.h and Rectangle.cpp contain the start to the Rectangle class. They also contain a bug. Please read the code now to see if you can find it. Don’t worry if you can not, but don’t fix it in the code if you do!
To complete this checkpoint: Look through Rectangle.h and Rectangle.cpp to determine what function need to be added and finish the implementation. Compile these files and remove any compilation errors.
Create a new file in Visual Studio within the current project and call it test rectangle.cpp. Create a main function within this file. In the main function, write code to test each of the member functions. For example, write code to create several rectangles, and print their contents right after they are created. Write code that should produce both true and false in the function is point within. When there is non-trivial logic in a function, multiple inputs to the test code should be attempted to test every path through the program. Write code to add points (or not) to a rectangle. Write code to find what points are contained in both rectangles.
To complete this checkpoint: Show a TA your test cases and the error(s) that those test cases reveal in the provided code. Even if you know how to fix the bugs, please do not fix them yet.
Now, we need to practice using the debugger to find and fix errors. The instructions below are specific to Visual Studio, but you may use any debugger that that works with your particular development environment. Make sure you learn how to do each of the tasks described below in your debugger.