Lab: Head to Head Testing

Steven J. Zeil

Last modified: Jul 24, 2014

Contents:
1. Lab Instructions
2. Problem Description: Triangle Diagnosis
There are many circumstances where you are working on a program but have

access to a working (or nearly working) executable.

Whenever you find yourself working on a system for which you already have a (nearly) working executable, you can take advantage of this by doing <span class="emph" markdown="1">head to head testing</span>, in which you

Whatever the reason, it’s the differences in outputs that are particularly interesting. Spotting those differences can be quite tricky, however, if they are buried in a sea of nearly identical outputs or if the differences are “invisible” changes like adding blanks at the ends of lines or improperly indenting output.

Luckily, there are simple tools that you can use to find and highlight those differences.

1. Lab Instructions

Recompile the program and rename the executable to triangleB.

    ./triangleA < test0.in

just to be sure things are working.

We saw the use of < to redirect input so we would not have to type everything manually in a much earlier lab.

We can also use > to redirect output into a file that otherwise would have gone to our screen. So run

    ./triangleA < test0.in > test0A.out
    ./triangleA < test1.in > test1A.out
    ./triangleB < test0.in > test0B.out
    ./triangleB < test1.in > test1B.out

You now have four output files. Inspect these with more or an editor.

Unfortunately, although “diff” tools like these are widely available, they are not a standard part of Windows distributions. They are, however, available in just about any Unix or Linux system.

diff test0A.out test0A.out

 Now, since we are comparing a file against itself, obviously there are no differences to be reported.  Then try
diff test0A.out test0B.out
diff test1A.out test1B.out

diff gives you a very quick report on the differences, if any, between two files.

   The behavior of `diff` can be tweaked by various command options. For example, 
diff -i test0A.out test0B.out

will ignore differences in upper and lower-case characters when comparing the two files. The option -w causes diff to ignore differences in white space (blanks and tabs).

sdiff test0A.out test0B.out | more
sdiff test1A.out test1B.out | more

 (Hit 'q' to exit the "more" program.)

sdiff shows the two files “side by side”. You may find it useful to make the window for your ssh session a bit wider when using this program. Lines that match exactly are shown side by side with no marker in between them. Lines that appear to have been changed have a ‘|’. Lines that appear to have been added or removed from one file but not the other are marked with a ‘<’ or ‘>’ pointing at the “extra” line.

If you are seated as a CS Dept lab Windows PC, run the program winmerge. (If you are not in a CS lab, use remote desktop to visit the CS Virtual PC lab and run winmerge there.

From the File menu, select “Open.”. Use the “Left” and “Right” controls to select the two files that you want to compare, the test0A.out and test0B.out files that you created in your Linux ssh session. ( These should be available in your Z: drive.)

If all you get is a simple report saying that the files are “different”, try selecting “Expand” from the View menu.

Winmerge is quite a useful program. You can get your own copy at WinMerge. It is also available in a portable version that can be installed on a USB flashdrive and executed on almost any Windows machine).]

2. Problem Description: Triangle Diagnosis

This is a simple program that reads in three floating-point numbers at a time. These numbers represent the lengths of the three sides of a triangle. The program interprets these to classify the triangle and prints the name of the kind of triangle that it is. You may remember these terms from a geometry class long, long ago:

In addition, there are some less obvious cases:

The program reads from the standard input, three numbers at a time, until end of input is reached. For each trio of numbers, it prints a triangle classification to the standard output.