test_uniform.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. // Copyright Paul Bristow 2007.
  2. // Copyright John Maddock 2006.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // test_uniform.cpp
  8. #include <pch.hpp>
  9. #ifdef _MSC_VER
  10. # pragma warning(disable: 4127) // conditional expression is constant.
  11. # pragma warning(disable: 4100) // unreferenced formal parameter.
  12. #endif
  13. #include <boost/math/concepts/real_concept.hpp> // for real_concept
  14. #define BOOST_TEST_MAIN
  15. #include <boost/test/unit_test.hpp> // Boost.Test
  16. #include <boost/test/tools/floating_point_comparison.hpp>
  17. #include <boost/math/distributions/uniform.hpp>
  18. using boost::math::uniform_distribution;
  19. #include <boost/math/tools/test.hpp>
  20. #include "test_out_of_range.hpp"
  21. #include <iostream>
  22. #include <iomanip>
  23. using std::cout;
  24. using std::endl;
  25. using std::setprecision;
  26. #include <limits>
  27. using std::numeric_limits;
  28. template <class RealType>
  29. void check_uniform(RealType lower, RealType upper, RealType x, RealType p, RealType q, RealType tol)
  30. {
  31. BOOST_CHECK_CLOSE_FRACTION(
  32. ::boost::math::cdf(
  33. uniform_distribution<RealType>(lower, upper), // distribution.
  34. x), // random variable.
  35. p, // probability.
  36. tol); // tolerance.
  37. BOOST_CHECK_CLOSE_FRACTION(
  38. ::boost::math::cdf(
  39. complement(
  40. uniform_distribution<RealType>(lower, upper), // distribution.
  41. x)), // random variable.
  42. q, // probability complement.
  43. tol); // tolerance.
  44. BOOST_CHECK_CLOSE_FRACTION(
  45. ::boost::math::quantile(
  46. uniform_distribution<RealType>(lower, upper), // distribution.
  47. p), // probability.
  48. x, // random variable.
  49. tol); // tolerance.
  50. BOOST_CHECK_CLOSE_FRACTION(
  51. ::boost::math::quantile(
  52. complement(
  53. uniform_distribution<RealType>(lower, upper), // distribution.
  54. q)), // probability complement.
  55. x, // random variable.
  56. tol); // tolerance.
  57. } // void check_uniform
  58. template <class RealType>
  59. void test_spots(RealType)
  60. {
  61. // Basic sanity checks
  62. //
  63. // These test values were generated for the normal distribution
  64. // using the online calculator at
  65. // http://espse.ed.psu.edu/edpsych/faculty/rhale/hale/507Mat/statlets/free/pdist.htm
  66. //
  67. // Tolerance is just over 5 decimal digits expressed as a fraction:
  68. // that's the limit of the test data.
  69. RealType tolerance = 2e-5f;
  70. cout << "Tolerance for type " << typeid(RealType).name() << " is " << tolerance << "." << endl;
  71. using std::exp;
  72. // Tests for PDF
  73. //
  74. BOOST_CHECK_CLOSE_FRACTION( // x == upper
  75. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0)),
  76. static_cast<RealType>(1),
  77. tolerance);
  78. BOOST_CHECK_CLOSE_FRACTION( // x == lower
  79. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(1)),
  80. static_cast<RealType>(1),
  81. tolerance);
  82. BOOST_CHECK_CLOSE_FRACTION( // x > upper
  83. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(-1)),
  84. static_cast<RealType>(0),
  85. tolerance);
  86. BOOST_CHECK_CLOSE_FRACTION( // x < lower
  87. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(2)),
  88. static_cast<RealType>(0),
  89. tolerance);
  90. if(std::numeric_limits<RealType>::has_infinity)
  91. { // BOOST_CHECK tests for infinity using std::numeric_limits<>::infinity()
  92. // Note that infinity is not implemented for real_concept, so these tests
  93. // are only done for types, like built-in float, double.. that have infinity.
  94. // Note that these assume that BOOST_MATH_OVERFLOW_ERROR_POLICY is NOT throw_on_error.
  95. // #define BOOST_MATH_OVERFLOW_ERROR_POLICY == throw_on_error would give a throw here.
  96. // #define BOOST_MATH_DOMAIN_ERROR_POLICY == throw_on_error IS defined, so the throw path
  97. // of error handling is tested below with BOOST_MATH_CHECK_THROW tests.
  98. BOOST_MATH_CHECK_THROW( // x == infinity should NOT be OK.
  99. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(std::numeric_limits<RealType>::infinity())),
  100. std::domain_error);
  101. BOOST_MATH_CHECK_THROW( // x == minus infinity should be OK too.
  102. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(-std::numeric_limits<RealType>::infinity())),
  103. std::domain_error);
  104. }
  105. if(std::numeric_limits<RealType>::has_quiet_NaN)
  106. { // BOOST_CHECK tests for NaN using std::numeric_limits<>::has_quiet_NaN() - should throw.
  107. BOOST_MATH_CHECK_THROW(
  108. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(std::numeric_limits<RealType>::quiet_NaN())),
  109. std::domain_error);
  110. BOOST_MATH_CHECK_THROW(
  111. pdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(-std::numeric_limits<RealType>::quiet_NaN())),
  112. std::domain_error);
  113. } // test for x = NaN using std::numeric_limits<>::quiet_NaN()
  114. // cdf
  115. BOOST_CHECK_EQUAL( // x < lower
  116. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(-1)),
  117. static_cast<RealType>(0) );
  118. BOOST_CHECK_CLOSE_FRACTION(
  119. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0)),
  120. static_cast<RealType>(0),
  121. tolerance);
  122. BOOST_CHECK_CLOSE_FRACTION(
  123. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.5)),
  124. static_cast<RealType>(0.5),
  125. tolerance);
  126. BOOST_CHECK_CLOSE_FRACTION(
  127. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.1)),
  128. static_cast<RealType>(0.1),
  129. tolerance);
  130. BOOST_CHECK_CLOSE_FRACTION(
  131. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.9)),
  132. static_cast<RealType>(0.9),
  133. tolerance);
  134. BOOST_CHECK_EQUAL( // x > upper
  135. cdf(uniform_distribution<RealType>(0, 1), static_cast<RealType>(2)),
  136. static_cast<RealType>(1));
  137. // cdf complement
  138. BOOST_CHECK_EQUAL( // x < lower
  139. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0))),
  140. static_cast<RealType>(1));
  141. BOOST_CHECK_EQUAL( // x == 0
  142. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0))),
  143. static_cast<RealType>(1));
  144. BOOST_CHECK_CLOSE_FRACTION( // x = 0.1
  145. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.1))),
  146. static_cast<RealType>(0.9),
  147. tolerance);
  148. BOOST_CHECK_CLOSE_FRACTION( // x = 0.5
  149. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.5))),
  150. static_cast<RealType>(0.5),
  151. tolerance);
  152. BOOST_CHECK_EQUAL( // x == 1
  153. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(1))),
  154. static_cast<RealType>(0));
  155. BOOST_CHECK_EQUAL( // x > upper
  156. cdf(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(2))),
  157. static_cast<RealType>(0));
  158. // quantile
  159. BOOST_CHECK_CLOSE_FRACTION(
  160. quantile(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.9)),
  161. static_cast<RealType>(0.9),
  162. tolerance);
  163. BOOST_CHECK_CLOSE_FRACTION(
  164. quantile(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.1)),
  165. static_cast<RealType>(0.1),
  166. tolerance);
  167. BOOST_CHECK_CLOSE_FRACTION(
  168. quantile(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.5)),
  169. static_cast<RealType>(0.5),
  170. tolerance);
  171. BOOST_CHECK_CLOSE_FRACTION(
  172. quantile(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0)),
  173. static_cast<RealType>(0),
  174. tolerance);
  175. BOOST_CHECK_CLOSE_FRACTION(
  176. quantile(uniform_distribution<RealType>(0, 1), static_cast<RealType>(1)),
  177. static_cast<RealType>(1),
  178. tolerance);
  179. // quantile complement
  180. BOOST_CHECK_CLOSE_FRACTION(
  181. quantile(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.1))),
  182. static_cast<RealType>(0.9),
  183. tolerance);
  184. BOOST_CHECK_CLOSE_FRACTION(
  185. quantile(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.9))),
  186. static_cast<RealType>(0.1),
  187. tolerance);
  188. BOOST_CHECK_CLOSE_FRACTION(
  189. quantile(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0.5))),
  190. static_cast<RealType>(0.5),
  191. tolerance);
  192. BOOST_CHECK_CLOSE_FRACTION(
  193. quantile(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(0))),
  194. static_cast<RealType>(1),
  195. tolerance);
  196. BOOST_CHECK_CLOSE_FRACTION(
  197. quantile(complement(uniform_distribution<RealType>(0, 1), static_cast<RealType>(1))),
  198. static_cast<RealType>(0),
  199. tolerance);
  200. // Some tests using a different location & scale, neight zero or unity.
  201. BOOST_CHECK_CLOSE_FRACTION( // x == mid
  202. pdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(1)),
  203. static_cast<RealType>(0.3333333333333333333333333333333333333333333333333333),
  204. tolerance);
  205. BOOST_CHECK_CLOSE_FRACTION( // x == upper
  206. pdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(+2)),
  207. static_cast<RealType>(0.3333333333333333333333333333333333333333333333333333), // 1 / (2 - -1) = 1/3
  208. tolerance);
  209. BOOST_CHECK_CLOSE_FRACTION( // x == lower
  210. cdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(-1)),
  211. static_cast<RealType>(0),
  212. tolerance);
  213. BOOST_CHECK_CLOSE_FRACTION( // x == upper
  214. cdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(0)),
  215. static_cast<RealType>(0.3333333333333333333333333333333333333333333333333333),
  216. tolerance);
  217. BOOST_CHECK_CLOSE_FRACTION( // x == upper
  218. cdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(1)),
  219. static_cast<RealType>(0.6666666666666666666666666666666666666666666666666667),
  220. tolerance);
  221. BOOST_CHECK_CLOSE_FRACTION( // x == lower
  222. cdf(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(2)),
  223. static_cast<RealType>(1),
  224. tolerance);
  225. BOOST_CHECK_CLOSE_FRACTION( // x == upper
  226. quantile(uniform_distribution<RealType>(-1, 2), static_cast<RealType>(0.6666666666666666666666666666666666666666666666666667)),
  227. static_cast<RealType>(1),
  228. tolerance);
  229. check_uniform(
  230. static_cast<RealType>(0), // lower
  231. static_cast<RealType>(1), // upper
  232. static_cast<RealType>(0.5), // x
  233. static_cast<RealType>(0.5), // p
  234. static_cast<RealType>(1 - 0.5), // q
  235. tolerance);
  236. // Some Not-standard uniform tests.
  237. check_uniform(
  238. static_cast<RealType>(-1), // lower
  239. static_cast<RealType>(1), // upper
  240. static_cast<RealType>(0), // x
  241. static_cast<RealType>(0.5), // p
  242. static_cast<RealType>(1 - 0.5), // q = 1 - p
  243. tolerance);
  244. check_uniform(
  245. static_cast<RealType>(1), // lower
  246. static_cast<RealType>(3), // upper
  247. static_cast<RealType>(2), // x
  248. static_cast<RealType>(0.5), // p
  249. static_cast<RealType>(1 - 0.5), // q = 1 - p
  250. tolerance);
  251. check_uniform(
  252. static_cast<RealType>(-1), // lower
  253. static_cast<RealType>(2), // upper
  254. static_cast<RealType>(1), // x
  255. static_cast<RealType>(0.66666666666666666666666666666666666666666667), // p
  256. static_cast<RealType>(0.33333333333333333333333333333333333333333333), // q = 1 - p
  257. tolerance);
  258. tolerance = (std::max)(
  259. boost::math::tools::epsilon<RealType>(),
  260. static_cast<RealType>(boost::math::tools::epsilon<double>())) * 5; // 5 eps as a fraction.
  261. cout << "Tolerance (as fraction) for type " << typeid(RealType).name() << " is " << tolerance << "." << endl;
  262. uniform_distribution<RealType> distu01(0, 1);
  263. RealType x = static_cast<RealType>(0.5);
  264. using namespace std; // ADL of std names.
  265. // mean:
  266. BOOST_CHECK_CLOSE_FRACTION(
  267. mean(distu01), static_cast<RealType>(0.5), tolerance);
  268. // variance:
  269. BOOST_CHECK_CLOSE_FRACTION(
  270. variance(distu01), static_cast<RealType>(0.0833333333333333333333333333333333333333333), tolerance);
  271. // std deviation:
  272. BOOST_CHECK_CLOSE_FRACTION(
  273. standard_deviation(distu01), sqrt(variance(distu01)), tolerance);
  274. // hazard:
  275. BOOST_CHECK_CLOSE_FRACTION(
  276. hazard(distu01, x), pdf(distu01, x) / cdf(complement(distu01, x)), tolerance);
  277. // cumulative hazard:
  278. BOOST_CHECK_CLOSE_FRACTION(
  279. chf(distu01, x), -log(cdf(complement(distu01, x))), tolerance);
  280. // coefficient_of_variation:
  281. BOOST_CHECK_CLOSE_FRACTION(
  282. coefficient_of_variation(distu01), standard_deviation(distu01) / mean(distu01), tolerance);
  283. // mode:
  284. BOOST_CHECK_CLOSE_FRACTION(
  285. mode(distu01), static_cast<RealType>(0), tolerance);
  286. BOOST_CHECK_CLOSE_FRACTION(
  287. median(distu01), static_cast<RealType>(0.5), tolerance);
  288. // skewness:
  289. BOOST_CHECK_EQUAL(
  290. skewness(distu01), static_cast<RealType>(0));
  291. // kertosis:
  292. BOOST_CHECK_CLOSE_FRACTION(
  293. kurtosis(distu01), kurtosis_excess(distu01) + static_cast<RealType>(3), tolerance);
  294. // kertosis excess:
  295. BOOST_CHECK_CLOSE_FRACTION(
  296. kurtosis_excess(distu01), static_cast<RealType>(-1.2), tolerance);
  297. if(std::numeric_limits<RealType>::has_infinity)
  298. { // BOOST_CHECK tests for infinity using std::numeric_limits<>::infinity()
  299. // Note that infinity is not implemented for real_concept, so these tests
  300. // are only done for types, like built-in float, double, long double, that have infinity.
  301. // Note that these assume that BOOST_MATH_OVERFLOW_ERROR_POLICY is NOT throw_on_error.
  302. // #define BOOST_MATH_OVERFLOW_ERROR_POLICY == throw_on_error would give a throw here.
  303. // #define BOOST_MATH_DOMAIN_ERROR_POLICY == throw_on_error IS defined, so the throw path
  304. // of error handling is tested below with BOOST_MATH_CHECK_THROW tests.
  305. BOOST_MATH_CHECK_THROW(pdf(distu01, std::numeric_limits<RealType>::infinity()), std::domain_error);
  306. BOOST_MATH_CHECK_THROW(pdf(distu01, -std::numeric_limits<RealType>::infinity()), std::domain_error);
  307. } // test for infinity using std::numeric_limits<>::infinity()
  308. else
  309. { // real_concept case, does has_infinfity == false, so can't check it throws.
  310. // cout << std::numeric_limits<RealType>::infinity() << ' '
  311. // << (boost::math::fpclassify)(std::numeric_limits<RealType>::infinity()) << endl;
  312. // value of std::numeric_limits<RealType>::infinity() is zero, so FPclassify is zero,
  313. // so (boost::math::isfinite)(std::numeric_limits<RealType>::infinity()) does not detect infinity.
  314. // so these tests would never throw.
  315. //BOOST_MATH_CHECK_THROW(pdf(distu01, std::numeric_limits<RealType>::infinity()), std::domain_error);
  316. //BOOST_MATH_CHECK_THROW(pdf(distu01, std::numeric_limits<RealType>::quiet_NaN()), std::domain_error);
  317. // BOOST_MATH_CHECK_THROW(pdf(distu01, boost::math::tools::max_value<RealType>() * 2), std::domain_error); // Doesn't throw.
  318. BOOST_CHECK_EQUAL(pdf(distu01, boost::math::tools::max_value<RealType>()), 0);
  319. }
  320. // Special cases:
  321. BOOST_CHECK(pdf(distu01, 0) == 1);
  322. BOOST_CHECK(cdf(distu01, 0) == 0);
  323. BOOST_CHECK(pdf(distu01, 1) == 1);
  324. BOOST_CHECK(cdf(distu01, 1) == 1);
  325. BOOST_CHECK(cdf(complement(distu01, 0)) == 1);
  326. BOOST_CHECK(cdf(complement(distu01, 1)) == 0);
  327. BOOST_CHECK(quantile(distu01, 0) == 0);
  328. BOOST_CHECK(quantile(complement(distu01, 0)) == 1);
  329. BOOST_CHECK(quantile(distu01, 1) == 1);
  330. BOOST_CHECK(quantile(complement(distu01, 1)) == 0);
  331. // Error checks:
  332. if(std::numeric_limits<RealType>::has_quiet_NaN)
  333. { // BOOST_CHECK tests for constructing with quiet_NaN (not for real_concept, for example - see notes above).
  334. BOOST_MATH_CHECK_THROW(uniform_distribution<RealType>(0, std::numeric_limits<RealType>::quiet_NaN()), std::domain_error);
  335. BOOST_MATH_CHECK_THROW(uniform_distribution<RealType>(0, -std::numeric_limits<RealType>::quiet_NaN()), std::domain_error);
  336. }
  337. BOOST_MATH_CHECK_THROW(uniform_distribution<RealType>(1, 0), std::domain_error); // lower > upper!
  338. BOOST_MATH_CHECK_THROW(uniform_distribution<RealType>(1, 1), std::domain_error); // lower == upper!
  339. check_out_of_range<uniform_distribution<RealType> >(1, 5);
  340. } // template <class RealType>void test_spots(RealType)
  341. BOOST_AUTO_TEST_CASE( test_main )
  342. {
  343. // Check that can construct uniform distribution using the two convenience methods:
  344. using namespace boost::math;
  345. uniform unistd; // Using typedef
  346. // == uniform_distribution<double> unistd;
  347. BOOST_CHECK_EQUAL(unistd.lower(), 0); // Check defaults.
  348. BOOST_CHECK_EQUAL(unistd.upper(), 1);
  349. uniform_distribution<> myu01(0, 1); // Using default RealType double.
  350. BOOST_CHECK_EQUAL(myu01.lower(), 0); // Check defaults again.
  351. BOOST_CHECK_EQUAL(myu01.upper(), 1);
  352. // Test on extreme values of random variate x, using just double because it has numeric_limit infinity etc..
  353. // No longer allow x to be + or - infinity, then these tests should throw.
  354. BOOST_MATH_CHECK_THROW(pdf(unistd, +std::numeric_limits<double>::infinity()), std::domain_error); // x = + infinity
  355. BOOST_MATH_CHECK_THROW(pdf(unistd, -std::numeric_limits<double>::infinity()), std::domain_error); // x = - infinity
  356. BOOST_MATH_CHECK_THROW(cdf(unistd, +std::numeric_limits<double>::infinity()), std::domain_error); // x = + infinity
  357. BOOST_MATH_CHECK_THROW(cdf(unistd, -std::numeric_limits<double>::infinity()), std::domain_error); // x = - infinity
  358. BOOST_CHECK_EQUAL(pdf(unistd, +(std::numeric_limits<double>::max)()), 0); // x = + max
  359. BOOST_CHECK_EQUAL(pdf(unistd, -(std::numeric_limits<double>::min)()), 0); // x = - min
  360. BOOST_CHECK_EQUAL(cdf(unistd, +(std::numeric_limits<double>::max)()), 1); // x = + max
  361. BOOST_CHECK_EQUAL(cdf(unistd, -(std::numeric_limits<double>::min)()), 0); // x = - min
  362. #ifndef BOOST_NO_EXCEPTIONS
  363. BOOST_MATH_CHECK_THROW(uniform_distribution<> zinf(0, +std::numeric_limits<double>::infinity()), std::domain_error); // zero to infinity using default RealType double.
  364. #else
  365. BOOST_MATH_CHECK_THROW(uniform_distribution<>(0, +std::numeric_limits<double>::infinity()), std::domain_error); // zero to infinity using default RealType double.
  366. #endif
  367. uniform_distribution<> zmax(0, +(std::numeric_limits<double>::max)()); // zero to max using default RealType double.
  368. BOOST_CHECK_EQUAL(zmax.lower(), 0); // Check defaults again.
  369. BOOST_CHECK_EQUAL(zmax.upper(), +(std::numeric_limits<double>::max)());
  370. BOOST_CHECK_EQUAL(pdf(zmax, -1), 0); // pdf is 1/(0 - max) = almost zero for all x
  371. BOOST_CHECK_EQUAL(pdf(zmax, 0), (std::numeric_limits<double>::min)()/4); // x =
  372. BOOST_CHECK_EQUAL(pdf(zmax, 1), (std::numeric_limits<double>::min)()/4); // x =
  373. BOOST_MATH_CHECK_THROW(pdf(zmax, +std::numeric_limits<double>::infinity()), std::domain_error); // pdf is 1/(0 - infinity) = zero for all x
  374. BOOST_MATH_CHECK_THROW(pdf(zmax, -std::numeric_limits<double>::infinity()), std::domain_error);
  375. BOOST_CHECK_EQUAL(pdf(zmax, +(std::numeric_limits<double>::max)()), (std::numeric_limits<double>::min)()/4); // x =
  376. BOOST_CHECK_EQUAL(pdf(zmax, -(std::numeric_limits<double>::max)()), 0); // x =
  377. #ifndef BOOST_NO_EXCEPTIONS
  378. // Ensure NaN throws an exception.
  379. BOOST_MATH_CHECK_THROW(uniform_distribution<> zNaN(0, std::numeric_limits<double>::quiet_NaN()), std::domain_error);
  380. BOOST_MATH_CHECK_THROW(pdf(unistd, std::numeric_limits<double>::quiet_NaN()), std::domain_error);
  381. #else
  382. BOOST_MATH_CHECK_THROW(uniform_distribution<>(0, std::numeric_limits<double>::quiet_NaN()), std::domain_error);
  383. BOOST_MATH_CHECK_THROW(pdf(unistd, std::numeric_limits<double>::quiet_NaN()), std::domain_error);
  384. #endif
  385. // Basic sanity-check spot values.
  386. // (Parameter value, arbitrarily zero, only communicates the floating point type).
  387. test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
  388. test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
  389. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  390. test_spots(0.0L); // Test long double.
  391. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0582))
  392. test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
  393. #endif
  394. #else
  395. std::cout << "<note>The long double tests have been disabled on this platform "
  396. "either because the long double overloads of the usual math functions are "
  397. "not available at all, or because they are too inaccurate for these tests "
  398. "to pass.</note>" << std::endl;
  399. #endif
  400. } // BOOST_AUTO_TEST_CASE( test_main )
  401. /*
  402. Output:
  403. Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_uniform.exe"
  404. Running 1 test case...
  405. Tolerance for type float is 2e-005.
  406. Tolerance (as fraction) for type float is 5.96046e-007.
  407. Tolerance for type double is 2e-005.
  408. Tolerance (as fraction) for type double is 1.11022e-015.
  409. Tolerance for type long double is 2e-005.
  410. Tolerance (as fraction) for type long double is 1.11022e-015.
  411. Tolerance for type class boost::math::concepts::real_concept is 2e-005.
  412. Tolerance (as fraction) for type class boost::math::concepts::real_concept is 1.11022e-015.
  413. *** No errors detected
  414. */