CMPS 3350 Lab-8

Unit Testing

Step-1:
Start with your lab-6 challenge program.

Copy your program on Odin to your own 3350/8/ folder.

Name your program lab8.cpp

In the lab you will...
1. Choose a portion of your code that receives data and produces some result.
2. Gather some known input data and expected results.
3. Run your test and compare the actual results with the expected results. 

Step-2:
Add a testing procedure to your program.

Do this by adding a Unit-Test to your code.

It does not matter if your challenge works completely.
You are writing an automated procedure to test some functionality in your code.

1. Start by choosing a portion of your code that examines words.
   This code will receive word data, and return some kind of result.
   The result could be that the word has just one consonant, or the letters
   of the work are ordered lexicographically, or the word is a palindrome.

2. Setup a data store containing your known input values and expected results.
   Sample:

      char testdata[][16] = { "radar",     "yes",
                              "racecar",   "yes",
                              "taco",      "no",
                              "kayak",     "yes",
                              "frenchfry", "no",
                              "",          ""      };

   Notice the sentinal values used to mark the end of the test data.
   This is very handy for inserting new data or removing data, without the
   need to keep a count of the items in the list.

   Above is just one example.
   There are many different ways to setup your test data for this.


3. Write a function that will perform your Unit Test, run your data items
   through the test, and show if the actual outcome matches the expected outcome.

Your output might look something like this...
Lab-6 challenge Running unit test... radar - yes pass racecar - yes pass taco - yes <--- error kayak - yes pass frenchfry - no pass Unit test complete. Error count: 1 End of program.

Step-3:
Isolate your Unit-Test.

Isolate using preprocessor directives such as #define
                                              #ifdef
                                              #else
                                              #endif

Do not use a #define in your source code, instead use -D in your Makefile.

Create 2 executable files from your Makefile.
Your two executable files will be created from just one source file.
One executable is normal, while the other runs your Unit-Test.

Name your Unit-Test executable test_lab8

How to do it in your Makefile...

   1. Build a second target named test_lab8:
   2. On its compile line, add the option -D UNIT_TEST

Your source code will look something like this...

#ifdef UNIT_TEST
	cout << "Running Unit Test..." << endl;
	unit_test(data);
	cout << "Unit Test complete." << endl;
#else
	cout << "Lab-6 Challenge #something..." << endl;
	process_dictionary();
	show_results();
#endif

Notes:
Your files will be collected at lab end, 12:30pm.
Please make sure your program compiles and runs in normal and test mode.

I will test your programs like this...

make clean
make
./lab8
./test_lab8