simple.t.c

This is an simple example of how to write a test using the library. The output of this program is:

00001    1..1
00002    # Testing basic functions
00003    ok 1 - Testing gcs()

The basic structure is: plan the number of test points using the plan() function, perform the test and write out the result of each test point using the ok() function, print out a diagnostics message using diag(), and report the result of the test by calling the exit_status() function. Observe that this test does excessive testing (see Writing unnecessarily large tests), but the test point doesn't take very long time.

00001 
00002 #include <tap.h>
00003 
00004 unsigned int gcs(unsigned int a, unsigned int b)
00005 {
00006   if (b > a) {
00007     unsigned int t = a;
00008     a = b;
00009     b = t;
00010   }
00011 
00012   while (b != 0) {
00013     unsigned int m = a % b;
00014     a = b;
00015     b = m;
00016   }
00017   return a;
00018 }
00019 
00020 int main() {
00021   unsigned int a,b;
00022   unsigned int failed;
00023   plan(1);
00024   diag("Testing basic functions");
00025   failed = 0;
00026   for (a = 1 ; a < 2000 ; ++a)
00027     for (b = 1 ; b < 2000 ; ++b)
00028     {
00029       unsigned int d = gcs(a, b);
00030       if (a % d != 0 || b % d != 0) {
00031         ++failed;
00032         diag("Failed for gcs(%4u,%4u)", a, b);
00033       }
00034     }
00035   ok(failed == 0, "Testing gcs()");
00036   return exit_status();
00037 }
00038 

Generated on Fri Oct 20 21:13:28 2006 by  doxygen 1.4.6