


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
Testing and debugging strategies for csci-1200 computer science ii lab 4. It emphasizes the importance of writing test code, using cout statements, and debugging tools like the debugger. The document also provides instructions for using visual studio and gdb debuggers. The lab context involves determining which 2d points are in which 2d rectangles.
Typology: Lab Reports
1 / 4
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 rectangles. For rectangles, we will assume they are aligned with the coordinate axes, as shown in Figure ??. This makes it easy to represent and to test if a point is inside. Our code will store points in rectangles and determine which points are in which rectangles. This is a toy example of problems that must be addressed in graphics and robotics.
Figure 1: Example of a rectange aligned with the coordinate axes — the only type of rectangle considered here. The rectangle 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.
Please download the following 3 files needed for this lab:
http://www.cs.rpi.edu/academics/courses/fall07/cs2/labs/lab03/Point2D.h http://www.cs.rpi.edu/academics/courses/fall07/cs2/labs/lab03/Rectangle.h http://www.cs.rpi.edu/academics/courses/fall07/cs2/labs/lab03/Rectangle.cpp
Start by creating a project and adding the files Point2D.h, Rectangle.h, and Rectangle.cpp. Examine 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. Do not worry if you can not, but do not fix it in the code if you do! To complete this checkpoint: Complete the implementation of the Rectangle.cpp class. Look through Rectangle.h and Rectangle.cpp to determine what functions need to be added. Then, compile these files and remove any compilation errors.
Create a new file called 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. If there is non-trivial logic in a function, you should provide multiple inputs in the test code to test as many possible conditions as you can. 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. After doing this you should be able to spot that there is an error in the provided code (as well as, perhaps, errors in your own code). Even if you know where the bug or bugs occur, please do not fix them yet.
Now, we need to practice using the debugger to find and fix errors. Visual Studio has an associated visual debugger. If you compile with g++ on cygwin, you can use the separate command-line debugger gdb. Other debuggers are available, many of them built on top of gdb. Of special note, gdb may be run from inside of the emacs and xemacs editors. In the following outline, Step 1 is for everyone. Step 2 shows you how to get started, and has separate instructions for using the Visual Studio debugger and using cygwin/g++/gdb. Steps 3 and beyond are written primarily for Visual Studio. Those of you using other debuggers should read the Visual Studio instructions and then adapt them to your debugger. Specific pointers to gdb commands are provided at the end of each item. You may use your internet connection to read reference material specific to your debugger & development environment.
Please note that this lab has only given you a brief introduction to debugging. You will learn much more through extensive practice. When you visit the TAs or instructor in office hours to ask for help in debugging your assignments, we will constantly be asking you to show us how you have attempted to find the problem on your own. This will include combinations of the four steps listed at the start of the lab.