Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68770 - trunk/libs/random/test
From: steven_at_[hidden]
Date: 2011-02-10 21:14:07


Author: steven_watanabe
Date: 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
New Revision: 68770
URL: http://svn.boost.org/trac/boost/changeset/68770

Log:
Refactor distribution tests. Remove spurious dependency on boost/random.hpp
Text files modified:
   trunk/libs/random/test/statistic_tests.hpp | 3
   trunk/libs/random/test/test_binomial.cpp | 118 ++++----------------------------------
   trunk/libs/random/test/test_chi_squared.cpp | 102 ++------------------------------
   trunk/libs/random/test/test_extreme_value.cpp | 109 ++++-------------------------------
   trunk/libs/random/test/test_fisher_f.cpp | 106 +++-------------------------------
   trunk/libs/random/test/test_gamma.cpp | 109 ++++-------------------------------
   trunk/libs/random/test/test_negative_binomial.cpp | 121 ++++-----------------------------------
   trunk/libs/random/test/test_normal.cpp | 109 ++++-------------------------------
   trunk/libs/random/test/test_old_uniform_real.cpp | 1
   trunk/libs/random/test/test_piecewise_linear.cpp | 1
   trunk/libs/random/test/test_poisson.cpp | 115 ++-----------------------------------
   trunk/libs/random/test/test_real_distribution.ipp | 6 +
   trunk/libs/random/test/test_student_t.cpp | 100 ++------------------------------
   trunk/libs/random/test/test_uniform_int.cpp | 2
   trunk/libs/random/test/test_weibull.cpp | 109 ++++-------------------------------
   15 files changed, 126 insertions(+), 985 deletions(-)

Modified: trunk/libs/random/test/statistic_tests.hpp
==============================================================================
--- trunk/libs/random/test/statistic_tests.hpp (original)
+++ trunk/libs/random/test/statistic_tests.hpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -19,9 +19,10 @@
 #include <algorithm>
 #include <cmath>
 
-#include <boost/random.hpp>
 #include <boost/config.hpp>
 #include <boost/bind.hpp>
+#include <boost/random/uniform_01.hpp>
+#include <boost/random/variate_generator.hpp>
 
 #include "integrate.hpp"
 

Modified: trunk/libs/random/test/test_binomial.cpp
==============================================================================
--- trunk/libs/random/test/test_binomial.cpp (original)
+++ trunk/libs/random/test/test_binomial.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -12,111 +12,19 @@
 #include <boost/random/binomial_distribution.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
 #include <boost/math/distributions/binomial.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "chi_squared_test.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::binomial_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME binomial
+#define BOOST_MATH_DISTRIBUTION boost::math::binomial
+#define BOOST_RANDOM_ARG1_TYPE int
+#define BOOST_RANDOM_ARG1_NAME n
+#define BOOST_RANDOM_ARG1_DEFAULT 100000
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_int<>(0, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME p
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_01<>()
+#define BOOST_RANDOM_DISTRIBUTION_MAX n
 
-bool do_test(int n, double p, long long max) {
- std::cout << "running binomial(" << n << ", " << p << ")" << " " << max << " times: " << std::flush;
-
- std::vector<double> expected(n+1);
- {
- boost::math::binomial dist(n, p);
- for(int i = 0; i <= n; ++i) {
- expected[i] = pdf(dist, i);
- }
- }
-
- boost::random::binomial_distribution<int, double> dist(n, p);
- boost::mt19937 gen;
- std::vector<long long> results(n + 1);
- for(long long i = 0; i < max; ++i) {
- ++results[dist(gen)];
- }
-
- long long sum = std::accumulate(results.begin(), results.end(), 0ll);
- if(sum != max) {
- std::cout << "*** Failed: incorrect total: " << sum << " ***" << std::endl;
- return false;
- }
- double chsqr = chi_squared_test(results, expected, max);
-
- bool result = chsqr < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << chsqr << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, int max_n, long long trials) {
- boost::mt19937 gen;
- boost::uniform_int<> idist(0, max_n);
- boost::uniform_01<> rdist;
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(idist(gen), rdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_binomial_distribution -r <repeat> -n <max n> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- int max_n = 100000;
- long long trials = 1000000ll;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'n', max_n)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_n, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_chi_squared.cpp
==============================================================================
--- trunk/libs/random/test/test_chi_squared.cpp (original)
+++ trunk/libs/random/test/test_chi_squared.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,99 +10,15 @@
  */
 
 #include <boost/random/chi_squared_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/chi_squared.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::chi_squared_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME chi_squared
+#define BOOST_MATH_DISTRIBUTION boost::math::chi_squared
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME n
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double n, int max) {
- std::cout << "running chi_squared(" << n << ")" << " " << max << " times: " << std::flush;
-
- boost::math::chi_squared expected(n);
-
- boost::random::chi_squared_distribution<> dist(n);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::chi_squared_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_n, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> ndist(0.00001, max_n);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(ndist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_chi_squared -r <repeat> -n <max n> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_n = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'n', max_n)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_n, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_extreme_value.cpp
==============================================================================
--- trunk/libs/random/test/test_extreme_value.cpp (original)
+++ trunk/libs/random/test/test_extreme_value.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,102 +10,19 @@
  */
 
 #include <boost/random/extreme_value_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/extreme_value.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::extreme_value_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME extreme_value
+#define BOOST_MATH_DISTRIBUTION boost::math::extreme_value
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME a
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME b
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double a, double b, int max) {
- std::cout << "running extreme_value(" << a << ", " << b << ")" << " " << max << " times: " << std::flush;
-
- boost::math::extreme_value_distribution<> expected(a, b);
-
- boost::random::extreme_value_distribution<> dist(a, b);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::extreme_value_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_a, double max_b, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> adist(0.00001, max_a);
- boost::uniform_real<> bdist(0.00001, max_b);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(adist(gen), bdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_extreme_value -r <repeat> -a <max a> -b <max b> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_a = 1000.0;
- double max_b = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'a', max_a)
- && !handle_option(argc, argv, 'b', max_b)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_a, max_b, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_fisher_f.cpp
==============================================================================
--- trunk/libs/random/test/test_fisher_f.cpp (original)
+++ trunk/libs/random/test/test_fisher_f.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -11,100 +11,18 @@
 
 #include <boost/random/fisher_f_distribution.hpp>
 #include <boost/random/uniform_real.hpp>
-#include <boost/random/mersenne_twister.hpp>
 #include <boost/math/distributions/fisher_f.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::fisher_f_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME fisher_f
+#define BOOST_MATH_DISTRIBUTION boost::math::fisher_f
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME m
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME n
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double m, double n, int max) {
- std::cout << "running fisher_f(" << m << ", " << n << ")" << " " << max << " times: " << std::flush;
-
- boost::math::fisher_f expected(m, n);
-
- boost::random::fisher_f_distribution<> dist(m, n);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::fisher_f_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_m, double max_n, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> mdist(0.00001, max_m);
- boost::uniform_real<> ndist(0.00001, max_n);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(mdist(gen), ndist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_fisher_f -r <repeat> -m <max m> -n <max n> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_m = 1000.0;
- double max_n = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'm', max_m)
- && !handle_option(argc, argv, 'n', max_n)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_m, max_n, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_gamma.cpp
==============================================================================
--- trunk/libs/random/test/test_gamma.cpp (original)
+++ trunk/libs/random/test/test_gamma.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,102 +10,19 @@
  */
 
 #include <boost/random/gamma_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/gamma.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::gamma_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME gamma
+#define BOOST_MATH_DISTRIBUTION boost::math::gamma_distribution<>
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME alpha
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME beta
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double alpha, double beta, int max) {
- std::cout << "running gamma(" << alpha << ", " << beta << ")" << " " << max << " times: " << std::flush;
-
- boost::math::gamma_distribution<> expected(alpha, beta);
-
- boost::random::gamma_distribution<> dist(alpha, beta);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::gamma_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_alpha, double max_beta, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> adist(0.00001, max_alpha);
- boost::uniform_real<> bdist(0.00001, max_beta);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(adist(gen), bdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_gamma -r <repeat> -a <max alpha> -b <max beta> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_alpha = 1000.0;
- double max_beta = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'a', max_alpha)
- && !handle_option(argc, argv, 'b', max_beta)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_alpha, max_beta, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_negative_binomial.cpp
==============================================================================
--- trunk/libs/random/test/test_negative_binomial.cpp (original)
+++ trunk/libs/random/test/test_negative_binomial.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -12,113 +12,20 @@
 #include <boost/random/negative_binomial_distribution.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
 #include <boost/math/distributions/negative_binomial.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "chi_squared_test.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::negative_binomial_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME negative_binomial
+#define BOOST_MATH_DISTRIBUTION boost::math::negative_binomial
+#define BOOST_RANDOM_ARG1_TYPE int
+#define BOOST_RANDOM_ARG1_NAME n
+#define BOOST_RANDOM_ARG1_DEFAULT 100000
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_int<>(0, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME p
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_01<>()
+#define BOOST_RANDOM_DISTRIBUTION_MAX n
+#define BOOST_RANDOM_P_CUTOFF 0.995
 
-bool do_test(int n, double p, long long max) {
- std::cout << "running negative_binomial(" << n << ", " << p << ")" << " " << max << " times: " << std::flush;
-
- int max_value = static_cast<int>(4*n*std::ceil((1-p)/p));
- std::vector<double> expected(max_value+1);
- {
- boost::math::negative_binomial dist(n, p);
- for(int i = 0; i <= max_value; ++i) {
- expected[i] = pdf(dist, i);
- }
- expected.back() += 1-cdf(dist,max_value);
- }
-
- boost::random::negative_binomial_distribution<int, double> dist(n, p);
- boost::mt19937 gen;
- std::vector<long long> results(max_value + 1);
- for(long long i = 0; i < max; ++i) {
- ++results[std::min(dist(gen), max_value)];
- }
-
- long long sum = std::accumulate(results.begin(), results.end(), 0ll);
- if(sum != max) {
- std::cout << "*** Failed: incorrect total: " << sum << " ***" << std::endl;
- return false;
- }
- double chsqr = chi_squared_test(results, expected, max);
-
- bool result = chsqr < 0.995;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << chsqr << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, int max_n, long long trials) {
- boost::mt19937 gen;
- boost::uniform_int<> idist(0, max_n);
- boost::uniform_01<> rdist;
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(idist(gen), rdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_negative_binomial_distribution -r <repeat> -n <max n> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- int max_n = 100000;
- long long trials = 1000000ll;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'n', max_n)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_n, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_normal.cpp
==============================================================================
--- trunk/libs/random/test/test_normal.cpp (original)
+++ trunk/libs/random/test/test_normal.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,102 +10,19 @@
  */
 
 #include <boost/random/normal_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/normal.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::normal_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME normal
+#define BOOST_MATH_DISTRIBUTION boost::math::normal
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME m
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(-n, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME s
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double m, double s, int max) {
- std::cout << "running normal(" << m << ", " << s << ")" << " " << max << " times: " << std::flush;
-
- boost::math::normal expected(m, s);
-
- boost::random::normal_distribution<> dist(m, s);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::normal_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_m, double max_s, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> mdist(-max_m, max_m);
- boost::uniform_real<> sdist(0.00001, max_s);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(mdist(gen), sdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_normal -r <repeat> -m <max mean> -s <max sigma> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_m = 1000.0;
- double max_s = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'm', max_m)
- && !handle_option(argc, argv, 's', max_s)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_m, max_s, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_old_uniform_real.cpp
==============================================================================
--- trunk/libs/random/test/test_old_uniform_real.cpp (original)
+++ trunk/libs/random/test/test_old_uniform_real.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,7 +10,6 @@
  */
 
 #include <boost/random/uniform_real.hpp>
-#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/uniform.hpp>
 
 #define BOOST_RANDOM_DISTRIBUTION boost::uniform_real<>

Modified: trunk/libs/random/test/test_piecewise_linear.cpp
==============================================================================
--- trunk/libs/random/test/test_piecewise_linear.cpp (original)
+++ trunk/libs/random/test/test_piecewise_linear.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -12,6 +12,7 @@
 #include <boost/random/piecewise_linear_distribution.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/exception/diagnostic_information.hpp>
 #include <boost/range/algorithm/lower_bound.hpp>

Modified: trunk/libs/random/test/test_poisson.cpp
==============================================================================
--- trunk/libs/random/test/test_poisson.cpp (original)
+++ trunk/libs/random/test/test_poisson.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -11,112 +11,15 @@
 
 #include <boost/random/poisson_distribution.hpp>
 #include <boost/random/uniform_real.hpp>
-#include <boost/random/mersenne_twister.hpp>
 #include <boost/math/distributions/poisson.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "chi_squared_test.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::poisson_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME poisson
+#define BOOST_MATH_DISTRIBUTION boost::math::poisson
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME mean
+#define BOOST_RANDOM_ARG1_DEFAULT 100000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(1e-15, n)
+#define BOOST_RANDOM_DISTRIBUTION_MAX static_cast<int>(mean * 4)
 
-bool do_test(double mean, long long max) {
- std::cout << "running poisson(" << mean << ")" << " " << max << " times: " << std::flush;
-
- int max_value = static_cast<int>(mean * 4);
- std::vector<double> expected(max_value+1);
- {
- boost::math::poisson dist(mean);
- for(int i = 0; i <= max_value; ++i) {
- expected[i] = pdf(dist, i);
- }
- expected.back() += 1 - cdf(dist, max_value);
- }
-
- boost::random::poisson_distribution<int, double> dist(mean);
- boost::mt19937 gen;
- std::vector<long long> results(max_value + 1);
- for(long long i = 0; i < max; ++i) {
- ++results[std::min(dist(gen), max_value)];
- }
-
- long long sum = std::accumulate(results.begin(), results.end(), 0ll);
- if(sum != max) {
- std::cout << "*** Failed: incorrect total: " << sum << " ***" << std::endl;
- return false;
- }
- double chsqr = chi_squared_test(results, expected, max);
-
- bool result = chsqr < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << chsqr << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_mean, long long trials) {
- boost::mt19937 gen;
- boost::uniform_real<> rdist(1e-15, max_mean);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(rdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_poisson -r <repeat> -m <max mean> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_mean = 100000;
- long long trials = 1000000ll;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'm', max_mean)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_mean, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_real_distribution.ipp
==============================================================================
--- trunk/libs/random/test/test_real_distribution.ipp (original)
+++ trunk/libs/random/test/test_real_distribution.ipp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -25,6 +25,10 @@
 #endif
 #endif
 
+#ifndef BOOST_RANDOM_P_CUTOFF
+#define BOOST_RANDOM_P_CUTOFF 0.99
+#endif
+
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/exception/diagnostic_information.hpp>
@@ -86,7 +90,7 @@
 
 #endif
 
- bool result = prob < 0.99;
+ bool result = prob < BOOST_RANDOM_P_CUTOFF;
     const char* err = result? "" : "*";
     std::cout << std::setprecision(17) << prob << err << std::endl;
 

Modified: trunk/libs/random/test/test_student_t.cpp
==============================================================================
--- trunk/libs/random/test/test_student_t.cpp (original)
+++ trunk/libs/random/test/test_student_t.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,99 +10,15 @@
  */
 
 #include <boost/random/student_t_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
 #include <boost/random/uniform_real.hpp>
-#include <boost/random/mersenne_twister.hpp>
 #include <boost/math/distributions/students_t.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::student_t_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME student_t
+#define BOOST_MATH_DISTRIBUTION boost::math::students_t
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME n
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double n, int max) {
- std::cout << "running student_t(" << n << ")" << " " << max << " times: " << std::flush;
-
- boost::math::students_t expected(n);
-
- boost::random::student_t_distribution<> dist(n);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::student_t_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_n, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> ndist(0.00001, max_n);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(ndist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_student_t -r <repeat> -n <max n> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_n = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'n', max_n)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_n, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"

Modified: trunk/libs/random/test/test_uniform_int.cpp
==============================================================================
--- trunk/libs/random/test/test_uniform_int.cpp (original)
+++ trunk/libs/random/test/test_uniform_int.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,7 +10,7 @@
  */
 
 #include <boost/random/uniform_int_distribution.hpp>
-#include <boost/random/uniform_real.hpp>
+#include <boost/random/uniform_int.hpp>
 #include <boost/math/distributions/uniform.hpp>
 
 #define BOOST_RANDOM_DISTRIBUTION boost::random::uniform_int_distribution<>

Modified: trunk/libs/random/test/test_weibull.cpp
==============================================================================
--- trunk/libs/random/test/test_weibull.cpp (original)
+++ trunk/libs/random/test/test_weibull.cpp 2011-02-10 21:13:59 EST (Thu, 10 Feb 2011)
@@ -10,102 +10,19 @@
  */
 
 #include <boost/random/weibull_distribution.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/uniform_01.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
 #include <boost/math/distributions/weibull.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/exception/diagnostic_information.hpp>
-#include <vector>
-#include <iostream>
-#include <numeric>
 
-#include "statistic_tests.hpp"
+#define BOOST_RANDOM_DISTRIBUTION boost::random::weibull_distribution<>
+#define BOOST_RANDOM_DISTRIBUTION_NAME weibull
+#define BOOST_MATH_DISTRIBUTION boost::math::weibull
+#define BOOST_RANDOM_ARG1_TYPE double
+#define BOOST_RANDOM_ARG1_NAME a
+#define BOOST_RANDOM_ARG1_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
+#define BOOST_RANDOM_ARG2_TYPE double
+#define BOOST_RANDOM_ARG2_NAME b
+#define BOOST_RANDOM_ARG2_DEFAULT 1000.0
+#define BOOST_RANDOM_ARG2_DISTRIBUTION(n) boost::uniform_real<>(0.00001, n)
 
-bool do_test(double a, double b, int max) {
- std::cout << "running weibull(" << a << ", " << b << ")" << " " << max << " times: " << std::flush;
-
- boost::math::weibull_distribution<> expected(a, b);
-
- boost::random::weibull_distribution<> dist(a, b);
- boost::mt19937 gen;
- kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > vgen(gen, dist);
-
- double prob = test.probability(test.run(vgen, expected));
-
- bool result = prob < 0.99;
- const char* err = result? "" : "*";
- std::cout << std::setprecision(17) << prob << err << std::endl;
-
- std::cout << std::setprecision(6);
-
- return result;
-}
-
-bool do_tests(int repeat, double max_a, double max_b, int trials) {
- boost::mt19937 gen;
- boost::uniform_real<> adist(0.00001, max_a);
- boost::uniform_real<> bdist(0.00001, max_b);
- int errors = 0;
- for(int i = 0; i < repeat; ++i) {
- if(!do_test(adist(gen), bdist(gen), trials)) {
- ++errors;
- }
- }
- if(errors != 0) {
- std::cout << "*** " << errors << " errors detected ***" << std::endl;
- }
- return errors == 0;
-}
-
-int usage() {
- std::cerr << "Usage: test_weibull -r <repeat> -a <max a> -b <max b> -t <trials>" << std::endl;
- return 2;
-}
-
-template<class T>
-bool handle_option(int& argc, char**& argv, char opt, T& value) {
- if(argv[0][1] == opt && argc > 1) {
- --argc;
- ++argv;
- value = boost::lexical_cast<T>(argv[0]);
- return true;
- } else {
- return false;
- }
-}
-
-int main(int argc, char** argv) {
- int repeat = 10;
- double max_a = 1000.0;
- double max_b = 1000.0;
- int trials = 1000000;
-
- if(argc > 0) {
- --argc;
- ++argv;
- }
- while(argc > 0) {
- if(argv[0][0] != '-') return usage();
- else if(!handle_option(argc, argv, 'r', repeat)
- && !handle_option(argc, argv, 'a', max_a)
- && !handle_option(argc, argv, 'b', max_b)
- && !handle_option(argc, argv, 't', trials)) {
- return usage();
- }
- --argc;
- ++argv;
- }
-
- try {
- if(do_tests(repeat, max_a, max_b, trials)) {
- return 0;
- } else {
- return EXIT_FAILURE;
- }
- } catch(...) {
- std::cerr << boost::current_exception_diagnostic_information() << std::endl;
- return EXIT_FAILURE;
- }
-}
+#include "test_real_distribution.ipp"


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk