Homework 10: Unit Testing

Due: Tuesday 4/17 by 11:59pm


Practice black-box unit testing on a function that someone else implemented.


In our group classwork, Classwork 13, different parts of the calendar program were implemented by different students. In the classwork, the parts were tested by checking if they work with the main program. For small programs, this can work well. For larger programs, it would be too complicated to test a function using the entire program. It is also difficult to fully exercise the function using the main program, since you might not be able to manipulate the values of the parameters directly.

Instead, we can write a separate program whose sole purpose is to exercise the function and check if it does what it is supposed to do. This is called "unit testing" (because we are testing the function as a separate unit). Sometimes the source code for the function is available. This is called "white-box testing". For this assignment, you are only given the object code, the .o file. This is called "black-box testing" because you can only test the input/output behavior of the function and are not able to look "inside the box" at the source code.


In Classwork 13, we implemented a function called Jan1Dow() that returns the day of the week for January 1 of the specified year. Your assignment is to test two implementations of this function to see if they are correct.

Copy these 3 files to your current directory:

   cp /afs/umbc.edu/users/c/h/chang/pub/cs104/jan1_dow_A.o .
   cp /afs/umbc.edu/users/c/h/chang/pub/cs104/jan1_dow_B.o .
   cp /afs/umbc.edu/users/c/h/chang/pub/cs104/jan1.h .

The function implemented in jan1_dow_A.o is called Jan1DoWA(). The one in jan1_dow_B.o is called Jan1DoWB(). (They have different names so you can tell them apart.) The header file jan1.h has the function prototypes of the two functions.

Write a main program (call it driver.c) that tests the two functions. At least one of them is buggy. Be mean and try to "break" the function. Think of cases that the programmer may not have considered and did not handle properly. Be creative.

In a plain text file called conclusions.txt, summarize your findings. Explain how you tried to test the functions. Say which implementation you think is buggy and why.



Use the script command to record yourself compiling and running the main program. Then submit your main program, your summary explanation and the typescript file:

submit cs104_chang hw10 driver.c conclusions.txt typescript