View Single Post
Old Jan 20th, 2006, 10:33 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by sixstringartist
Im afraid Im not exactly sure what you mean by platform so I will ramble off some things and hope it helps. The previous program was written in C, using a UNIX command shell with the vi editor. compiled with gcc in UNIX.
Unit tests are a way of automatically checking your programs for correctness. There are a number of frameworks around that make building unit tests easier.

The first result for "C unit tests" in Google comes up with the Check framework, which seems a good place to start. Check seems to be designed with Linux/Unix in mind, which was why I was asking your platform. There might even be a precompiled Check package for your system. On the Check website, there is tutorial which seems to be fairly straightforward.

Typically, these frameworks have a number of tests, sometimes grouped together in one or more test suites so that many tests can be run at once. The frameworks also supply some form of testing the output of functions. For instance, under Check, you have the fail_unless and fail_if functions. Perhaps something like this will work:

START_TEST (test_primes) {
    fail_unless(your_prime_function(17), "17 should be classed as prime");
    fail_if(your_prime_function(6), "6 should be classed as not prime");
}
END_TEST
If your_prime_function returns true when passed 17, and false when passed 6, then the unit tests will pass. If they fail, then detailed information will be printed by the test runner, telling you exactly what failed and in what way. Of course, your unit tests are likely to be a little more complicated than this!

See if that helps any.
Arevos is offline   Reply With Quote