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