# include # include # include # include # include # include "asa152.hpp" using namespace std; int main ( ); void test01 ( ); void test02 ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // asa152_test() tests asa152(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 January 2008 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "asa152_test():\n"; cout << " C++ version\n"; cout << " Test asa152().\n"; test01 ( ); test02 ( ); // // Terminate. // cout << "\n"; cout << "asa152_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test01 ( ) //****************************************************************************80 // // Purpose: // // test01() tests chyper() for cumulative probabilities. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 January 2008 // // Author: // // John Burkardt // { double fx; double fx2; int ifault; int n_data; bool point; int pop; int sam; int suc; int x; cout << "\n"; cout << "test01():\n"; cout << " chyper() computes cumulative probablities\n"; cout << " of the hypergeometric PDF.\n"; cout << " Compare to tabulated values.\n"; cout << "\n"; cout << " SAM SUC POP X " << " CDF CDF DIFF\n"; cout << " " << " (tabulated) (CHYPER)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { hypergeometric_cdf_values ( &n_data, &sam, &suc, &pop, &x, &fx ); if ( n_data == 0 ) { break; } point = false; fx2 = chyper ( point, sam, x, pop, suc, &ifault ); cout << " " << setw(4) << sam << " " << setw(4) << suc << " " << setw(4) << pop << " " << setw(4) << x << " " << setprecision(16) << setw(24) << fx << " " << setprecision(16) << setw(24) << fx2 << " " << setprecision(4) << setw(10) << fabs ( fx - fx2 ) << "\n"; } return; } //****************************************************************************80 void test02 ( ) //****************************************************************************80 // // Purpose: // // test02() tests chyper() for point probabilities. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 January 2008 // // Author: // // John Burkardt // { double fx; double fx2; int ifault; int n_data; bool point; int pop; int sam; int suc; int x; cout << "\n"; cout << "test02():\n"; cout << " chyper() computes point probablities\n"; cout << " of the hypergeometric PDF.\n"; cout << " Compare to tabulated values.\n"; cout << "\n"; cout << " SAM SUC POP X " << " PDF PDF DIFF\n"; cout << " " << " (tabulated) (CHYPER)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { hypergeometric_pdf_values ( &n_data, &sam, &suc, &pop, &x, &fx ); if ( n_data == 0 ) { break; } point = true; fx2 = chyper ( point, sam, x, pop, suc, &ifault ); cout << " " << setw(4) << sam << " " << setw(4) << suc << " " << setw(4) << pop << " " << setw(4) << x << " " << setprecision(16) << setw(24) << fx << " " << setprecision(16) << setw(24) << fx2 << " " << setprecision(4) << setw(10) << fabs ( fx - fx2 ) << "\n"; } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // TIMESTAMP prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 September 2003 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); cout << time_buffer << "\n"; return; # undef TIME_SIZE }