test_laplace.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. // Copyright Thijs van den Berg, 2008.
  2. // Copyright John Maddock 2008.
  3. // Copyright Paul A. Bristow 2008, 2009, 2014.
  4. // Use, modification and distribution are subject to the
  5. // Boost Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // add few more tests for farther out than 2??
  8. // long double test
  9. // add test for convenience typedef laplace.
  10. // Permit infinity arguments.
  11. #ifdef _MSC_VER
  12. #pragma warning (disable : 4127) // conditional expression is constant.
  13. #endif
  14. /*
  15. This module tests the Laplace distribution.
  16. Test 1: test_pdf_cdf_ocatave()
  17. Compare pdf, cdf agains results obtained from GNU Octave.
  18. Test 2: test_cdf_quantile_symmetry()
  19. Checks if quantile is the inverse of cdf by testing
  20. quantile(cdf(x)) == x
  21. Test 3: test_hazard_pdf_cdf_symmetry()
  22. Checks the relation between hazard, pdf and cdf.
  23. hazard = pdf/(1-cdf)
  24. Test 4: test_location_scale_symmetry()
  25. Checks the pdf, cdf invariant for translation and scaling invariant
  26. cdf(x,location,scale) = cdf( (x-location)/scale, 0, 1)
  27. scale * pdf(x,location,scale) = pdf( (x-location)/scale, 0, 1)
  28. Test 5: test_mmm_moments()
  29. Tests...
  30. mean == location
  31. mode == location
  32. median == location
  33. standard_deviation = sqrt(2)*scale
  34. skewness == 0
  35. kurtoris == 6
  36. excess kurtoris == 3
  37. Test 6: test_complemented()
  38. Test the cdf an quantile complemented function.
  39. cdf(L,x) + cdf(complement(l,x)) == 1
  40. quantile(L,p) == quantile(complement(l,1-p))
  41. Test 7: test_bad_dist_parameters()
  42. Test invalid distribution construction.
  43. Test 8: test_extreme_function_arguments()
  44. Test x = +/- inf. for cdf(), pdf()
  45. Test p ={0,1} for quantile()
  46. */
  47. #define BOOST_TEST_MAIN
  48. #include <boost/test/unit_test.hpp>
  49. #include <boost/math/tools/test.hpp>
  50. #include <boost/math/constants/constants.hpp>
  51. #include <boost/math/distributions/laplace.hpp>
  52. #include "test_out_of_range.hpp"
  53. using boost::math::laplace_distribution;
  54. /*
  55. #include <iostream>
  56. using std::cout;
  57. using std::endl;
  58. using std::setprecision;
  59. #include <limits>
  60. using std::numeric_limits;
  61. */
  62. /*
  63. This function test various values of the standard Laplace distribution pdf,cdf
  64. against values generated by GNU Octave
  65. The test code is generated woth the following Octave script:
  66. f = fopen('octave_boost_laplace.cpp', 'w');
  67. for x = [real(-2.0), real(-1.0), real(-0.5), real(0.0), real(0.5), real(1.0), real(2.0)]
  68. # pdf tests
  69. # -----------------------
  70. fdisp(f, " BOOST_CHECK_CLOSE(" ),;
  71. fdisp(f, (sprintf (" pdf(laplace_distribution<RealType>(), static_cast<RealType>(%16.14fL)),", x)));
  72. fdisp(f, (sprintf (" static_cast<RealType>(%16.14fL),", laplace_pdf(x) )) );
  73. fdisp(f, " tolerance);" );
  74. fdisp(f, "" );
  75. # cdf tests
  76. # -----------------------
  77. fdisp(f, " BOOST_CHECK_CLOSE(" );
  78. fdisp(f, (sprintf (" cdf(laplace_distribution<RealType>(), static_cast<RealType>(%16.14fL)),", x)));
  79. fdisp(f, (sprintf (" static_cast<RealType>(%16.14fL),", laplace_cdf(x) )) );
  80. fdisp(f, " tolerance);" );
  81. fdisp(f, "" );
  82. endfor
  83. fclose(f);
  84. Laplace distribution values version 2.0
  85. Using NTL version 5.4 and the formula in Wikipedia Paul A. Bristow
  86. NTL class RR precision 150 bits.
  87. NTL class RR output precision 50 decimal digits OK.
  88. Laplace pdf
  89. -10 0.22699964881242425767795757780275305118959044437696e-4
  90. -9.5 0.37425914943850295735594659677277583056493449453316e-4
  91. -9 0.61704902043339774748818345365016913036076416123496e-4
  92. -8.5 0.00010173418450532208718446671524353319364865576338509
  93. -8 0.00016773131395125591941069456289043050965545006686111
  94. -7.5 0.00027654218507391679155100004426517859890566829114007
  95. -7 0.00045594098277725810400156804220464131323686226383407
  96. -6.5 0.00075171959648878622369145166608382691500025647887521
  97. -6 0.0012393760883331792115225837154083339457532397924584
  98. -5.5 0.0020433857192320334967323513423603842041953283241185
  99. -5 0.0033689734995427335483180242115742121244247925136568
  100. -4.5 0.0055544982691211532480715671434652638857696337503689
  101. -4 0.0091578194443670901468590106366206211059560337810038
  102. -3.5 0.015098691711159250369893146181809922535830266119032
  103. -3 0.024893534183931971489671207825030888315849796096331
  104. -2.5 0.041042499311949397584764337233579903918902060509316
  105. -2 0.067667641618306345946999747486242201703815772944649
  106. -1.5 0.11156508007421491446664023538200626067108581471131
  107. -1 0.18393972058572116079776188508073043372290556554506
  108. -0.5 0.30326532985631671180189976749559022672095906778368
  109. 0 0.5
  110. 0.5 0.30326532985631671180189976749559022672095906778368
  111. 1 0.18393972058572116079776188508073043372290556554506
  112. 1.5 0.11156508007421491446664023538200626067108581471131
  113. 2 0.067667641618306345946999747486242201703815772944649
  114. 2.5 0.041042499311949397584764337233579903918902060509316
  115. 3 0.024893534183931971489671207825030888315849796096331
  116. 3.5 0.015098691711159250369893146181809922535830266119032
  117. 4 0.0091578194443670901468590106366206211059560337810038
  118. 4.5 0.0055544982691211532480715671434652638857696337503689
  119. 5 0.0033689734995427335483180242115742121244247925136568
  120. 5.5 0.0020433857192320334967323513423603842041953283241185
  121. 6 0.0012393760883331792115225837154083339457532397924584
  122. 6.5 0.00075171959648878622369145166608382691500025647887521
  123. 7 0.00045594098277725810400156804220464131323686226383407
  124. 7.5 0.00027654218507391679155100004426517859890566829114007
  125. 8 0.00016773131395125591941069456289043050965545006686111
  126. 8.5 0.00010173418450532208718446671524353319364865576338509
  127. 9 0.61704902043339774748818345365016913036076416123496e-4
  128. 9.5 0.37425914943850295735594659677277583056493449453316e-4
  129. 10 0.22699964881242425767795757780275305118959044437696e-4
  130. Laplace cdf
  131. -10 0.9999773000351187575742322042422197246948810411152
  132. -9.5 0.99996257408505614970426440534032272241694350636029
  133. -9 0.99993829509795666022525118165463498308696392404693
  134. -8.5 0.99989826581549467791281553328475646680635134420916
  135. -8 0.99983226868604874408058930543710956949034454956485
  136. -7.5 0.9997234578149260832084489999557348214010943317417
  137. -7 0.99954405901722274189599843195779535868676313746042
  138. -6.5 0.99924828040351121377630854833391617308499974328643
  139. -6 0.99876062391166682078847741628459166605424676032523
  140. -5.5 0.99795661428076796650326764865763961579580467117776
  141. -5 0.99663102650045726645168197578842578787557520756024
  142. -4.5 0.9944455017308788467519284328565347361142303666328
  143. -4 0.99084218055563290985314098936337937889404396651458
  144. -3.5 0.98490130828884074963010685381819007746416973359633
  145. -3 0.9751064658160680285103287921749691116841502037504
  146. -2.5 0.95895750068805060241523566276642009608109793962206
  147. -2 0.93233235838169365405300025251375779829618422688019
  148. -1.5 0.8884349199257850855333597646179937393289141857266
  149. -1 0.81606027941427883920223811491926956627709443427977
  150. -0.5 0.69673467014368328819810023250440977327904093221632
  151. 0 0.5
  152. 0.5 0.30326532985631671180189976749559022672095906778368
  153. 1 0.18393972058572116079776188508073043372290556572023
  154. 1.5 0.11156508007421491446664023538200626067108581462372
  155. 2 0.067667641618306345946999747486242201703815773119812
  156. 2.5 0.041042499311949397584764337233579903918902060377944
  157. 3 0.024893534183931971489671207825030888315849796249598
  158. 3.5 0.015098691711159250369893146181809922535830266053346
  159. 4 0.009157819444367090146859010636620621105956033835742
  160. 4.5 0.005554498269121153248071567143465263885769633717526
  161. 5 0.0033689734995427335483180242115742121244247924397602
  162. 5.5 0.0020433857192320334967323513423603842041953284719117
  163. 6 0.0012393760883331792115225837154083339457532396747712
  164. 6.5 0.00075171959648878622369145166608382691500025636324071
  165. 7 0.00045594098277725810400156804220464131323686218925325
  166. 7.5 0.00027654218507391679155100004426517859890566825829713
  167. 8 0.00016773131395125591941069456289043050965545008482209
  168. 8.5 0.00010173418450532208718446671524353319364865579083973
  169. 9 0.61704902043339774748818345365016913036076303396971e-4
  170. 9.5 0.37425914943850295735594659677277583056493289386783e-4
  171. 10 0.22699964881242425767795757780275305118958884798806e-4
  172. */
  173. template <class RealType>
  174. void test_pdf_cdf_ocatave()
  175. {
  176. RealType tolerance(1e-10f);
  177. BOOST_CHECK_CLOSE(
  178. pdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.L)),
  179. // static_cast<RealType>(0.06766764161831L),
  180. static_cast<RealType>(0.067667641618306345946999747486242201703815773119812L),
  181. tolerance);
  182. BOOST_CHECK_CLOSE(
  183. cdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.L)),
  184. //static_cast<RealType>(0.06766764161831L),
  185. static_cast<RealType>(0.067667641618306345946999747486242201703815773119812L),
  186. tolerance);
  187. BOOST_CHECK_CLOSE(
  188. pdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.L)),
  189. //static_cast<RealType>(0.18393972058572L),
  190. static_cast<RealType>(0.18393972058572116079776188508073043372290556554506L),
  191. tolerance);
  192. BOOST_CHECK_CLOSE(
  193. cdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.L)),
  194. static_cast<RealType>(0.18393972058572L),
  195. tolerance);
  196. BOOST_CHECK_CLOSE(
  197. pdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.5L)),
  198. // static_cast<RealType>(0.30326532985632L),
  199. static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
  200. tolerance);
  201. BOOST_CHECK_CLOSE(
  202. cdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.5L)),
  203. //static_cast<RealType>(0.30326532985632L),
  204. static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
  205. tolerance);
  206. BOOST_CHECK_CLOSE(
  207. pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.0L)),
  208. static_cast<RealType>(0.5L),
  209. tolerance);
  210. BOOST_CHECK_CLOSE(
  211. cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.0L)),
  212. static_cast<RealType>(0.5L),
  213. tolerance);
  214. BOOST_CHECK_CLOSE(
  215. pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.5L)),
  216. //static_cast<RealType>(0.30326532985632L),
  217. static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
  218. tolerance);
  219. BOOST_CHECK_CLOSE(
  220. cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.5L)),
  221. // static_cast<RealType>(0.69673467014368L),
  222. static_cast<RealType>(0.69673467014368328819810023250440977327904093221632L),
  223. tolerance);
  224. BOOST_CHECK_CLOSE(
  225. pdf(laplace_distribution<RealType>(), static_cast<RealType>(1.0L)),
  226. // static_cast<RealType>(0.18393972058572L),
  227. static_cast<RealType>(0.18393972058572116079776188508073043372290556554506L),
  228. tolerance);
  229. BOOST_CHECK_CLOSE(
  230. cdf(laplace_distribution<RealType>(), static_cast<RealType>(1.00000000000000L)),
  231. // static_cast<RealType>(0.81606027941428L),
  232. static_cast<RealType>(0.81606027941427883920223811491926956627709443427977L),
  233. tolerance);
  234. BOOST_CHECK_CLOSE(
  235. pdf(laplace_distribution<RealType>(), static_cast<RealType>(2.0L)),
  236. // static_cast<RealType>(0.06766764161831L),
  237. static_cast<RealType>(0.067667641618306345946999747486242201703815772944649L),
  238. tolerance);
  239. BOOST_CHECK_CLOSE(
  240. cdf(laplace_distribution<RealType>(), static_cast<RealType>(2.0L)),
  241. // static_cast<RealType>(0.93233235838169L),
  242. static_cast<RealType>(0.93233235838169365405300025251375779829618422688019L),
  243. tolerance);
  244. check_out_of_range<laplace_distribution<RealType> >(0, 1);
  245. BOOST_MATH_CHECK_THROW(laplace_distribution<RealType>(0, 0), std::domain_error);
  246. BOOST_MATH_CHECK_THROW(laplace_distribution<RealType>(0, -1), std::domain_error);
  247. }
  248. template <class RealType>
  249. void test_cdf_quantile_symmetry()
  250. {
  251. RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage.
  252. const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  253. for (int i=0; i<7; ++i)
  254. {
  255. RealType x( static_cast<RealType>(xtest[i]) );
  256. RealType x2( quantile(laplace_distribution<RealType>(), cdf(laplace_distribution<RealType>(), x)) );
  257. BOOST_CHECK_CLOSE( x, x2, tolerance);
  258. }
  259. }
  260. template <class RealType>
  261. void test_hazard_pdf_cdf_symmetry()
  262. {
  263. RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage
  264. const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  265. for (int xi=0; xi<7; ++xi)
  266. {
  267. RealType x( static_cast<RealType>(xtest[xi]) );
  268. RealType p( pdf(laplace_distribution<RealType>(), x) );
  269. RealType c( cdf(laplace_distribution<RealType>(), x) );
  270. RealType h1( p/(static_cast<RealType>(1.0) - c) );
  271. RealType h2( hazard(laplace_distribution<RealType>(), x) );
  272. BOOST_CHECK_CLOSE( h1, h2, tolerance);
  273. }
  274. }
  275. template <class RealType>
  276. void test_location_scale_symmetry()
  277. {
  278. RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage
  279. const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  280. const float ltest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  281. const float stest[3] = { 0.5, 1.0, 2.0 };
  282. for (int xi=0; xi<7; ++xi)
  283. for (int li=0; li<7; ++li)
  284. for (int si=0; si<3; ++si)
  285. {
  286. RealType x( static_cast<RealType>(xtest[xi]) );
  287. RealType l( static_cast<RealType>(ltest[li]) );
  288. RealType s( static_cast<RealType>(stest[si]) );
  289. RealType x0( (x-l)/s );
  290. BOOST_CHECK_CLOSE(
  291. pdf(laplace_distribution<RealType>(l,s), x) * s,
  292. pdf(laplace_distribution<RealType>(), x0),
  293. tolerance);
  294. BOOST_CHECK_CLOSE(
  295. cdf(laplace_distribution<RealType>(l,s), x),
  296. cdf(laplace_distribution<RealType>(), x0),
  297. tolerance);
  298. }
  299. }
  300. template <class RealType>
  301. void test_mmm_moments()
  302. {
  303. RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage
  304. // const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  305. const float ltest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
  306. const float stest[3] = { 0.5, 1.0, 2.0 };
  307. for (int xi=0; xi<7; ++xi)
  308. for (int li=0; li<7; ++li)
  309. for (int si=0; si<3; ++si)
  310. {
  311. //RealType x( static_cast<RealType>(xtest[xi]) );
  312. RealType l( static_cast<RealType>(ltest[li]) );
  313. RealType s( static_cast<RealType>(stest[si]) );
  314. BOOST_CHECK_CLOSE(
  315. mean( laplace_distribution<RealType>(l,s) ),
  316. l,
  317. tolerance);
  318. BOOST_CHECK_CLOSE(
  319. median( laplace_distribution<RealType>(l,s) ),
  320. l,
  321. tolerance);
  322. BOOST_CHECK_CLOSE(
  323. mode( laplace_distribution<RealType>(l,s) ),
  324. l,
  325. tolerance);
  326. BOOST_CHECK_CLOSE(
  327. standard_deviation( laplace_distribution<RealType>(l,s) ),
  328. static_cast<RealType>( s * boost::math::constants::root_two<RealType>() ),
  329. tolerance);
  330. BOOST_CHECK_CLOSE(
  331. skewness( laplace_distribution<RealType>(l,s) ),
  332. static_cast<RealType>(0),
  333. tolerance);
  334. BOOST_CHECK_CLOSE(
  335. kurtosis( laplace_distribution<RealType>(l,s) ),
  336. static_cast<RealType>(6),
  337. tolerance);
  338. BOOST_CHECK_CLOSE(
  339. kurtosis_excess( laplace_distribution<RealType>(l,s) ),
  340. static_cast<RealType>(3),
  341. tolerance);
  342. }
  343. } // template <class RealType> void test_mmm_moments()
  344. template <class RealType>
  345. void test_complemented()
  346. {
  347. RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage.
  348. const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 }; // x values.
  349. const float ptest[7] = { 0.125, 0.25, 0.5, 0.75, 0.875 }; // probability values.
  350. const float ltest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 }; // locations.
  351. const float stest[3] = { 0.5, 1.0, 2.0 }; // scales.
  352. for (int li=0; li<7; ++li)
  353. for (int si=0; si<3; ++si)
  354. {
  355. RealType l( static_cast<RealType>(ltest[li]) );
  356. RealType s( static_cast<RealType>(stest[si]) );
  357. for (int xi=0; xi<7; ++xi)
  358. {
  359. RealType x( static_cast<RealType>(xtest[xi]) );
  360. // Check sum of cdf and complement = unity.
  361. BOOST_CHECK_CLOSE(
  362. cdf(complement(laplace_distribution<RealType>(l,s), x))
  363. + cdf(laplace_distribution<RealType>(l,s), x),
  364. static_cast<RealType>(1),
  365. tolerance);
  366. }
  367. for (int pi=0; pi<5; ++pi)
  368. {
  369. RealType p( static_cast<RealType>(ptest[pi]) );
  370. BOOST_CHECK_CLOSE(
  371. quantile(complement(laplace_distribution<RealType>(l,s), 1-p )),
  372. quantile(laplace_distribution<RealType>(l,s), p),
  373. tolerance);
  374. }
  375. }
  376. } // void test_complemented()
  377. template <class RealType>
  378. void test_bad_dist_parameters()
  379. {
  380. // Check that can generate laplace distribution using both convenience methods:
  381. laplace_distribution<double> lp1(0.5); // Using default RealType double.
  382. boost::math::laplace lp2(0.5); // Using typedef.
  383. #ifndef BOOST_NO_EXCEPTIONS
  384. BOOST_MATH_CHECK_THROW(boost::math::laplace_distribution<RealType> lbad1(0, 0), std::domain_error);
  385. BOOST_MATH_CHECK_THROW(boost::math::laplace_distribution<RealType> lbad2(0, -1), std::domain_error);
  386. #else
  387. BOOST_MATH_CHECK_THROW(boost::math::laplace_distribution<RealType>(0, 0), std::domain_error);
  388. BOOST_MATH_CHECK_THROW(boost::math::laplace_distribution<RealType>(0, -1), std::domain_error);
  389. #endif
  390. }
  391. template <class RealType>
  392. void test_extreme_function_arguments()
  393. {
  394. using boost::math::laplace_distribution;
  395. using boost::math::policies::policy;
  396. using boost::math::policies::overflow_error;
  397. using boost::math::policies::ignore_error;
  398. typedef policy<
  399. overflow_error<ignore_error> // Ignore if argument value causes overflow.
  400. > ignore_overflow_policy;
  401. laplace_distribution<RealType> L01(0, 1);
  402. // Compare random variate x = infinity with RealType max value, usually std::numeric_limits<RealType>::max().
  403. using boost::math::tools::max_value; // In case std::numeric_limits<RealType>::max() is not defined.
  404. BOOST_CHECK_EQUAL(pdf(L01, +max_value<RealType>()), pdf(L01, +std::numeric_limits<RealType>::infinity()) );
  405. BOOST_CHECK_EQUAL(pdf(L01, -max_value<RealType>()), pdf(L01, -std::numeric_limits<RealType>::infinity()) );
  406. if(std::numeric_limits<RealType>::has_infinity)
  407. {
  408. laplace_distribution<RealType, ignore_overflow_policy> L1(0, 1);
  409. laplace_distribution<RealType, ignore_overflow_policy> L2(1, 2);
  410. laplace_distribution<RealType> l01;
  411. // Check pdf == 0 at x = +/- infinity.
  412. BOOST_CHECK_EQUAL(pdf(L01, +std::numeric_limits<RealType>::infinity()), 0 );
  413. BOOST_CHECK_EQUAL(pdf(L01, -std::numeric_limits<RealType>::infinity()), 0 );
  414. BOOST_CHECK_EQUAL(cdf(L01, +std::numeric_limits<RealType>::infinity()), 1 );
  415. BOOST_CHECK_EQUAL(cdf(L01, -std::numeric_limits<RealType>::infinity()), 0 );
  416. BOOST_CHECK_EQUAL(cdf(complement(L01, +std::numeric_limits<RealType>::infinity())), 0 );
  417. BOOST_CHECK_EQUAL(cdf(complement(L01, -std::numeric_limits<RealType>::infinity())), 1 );
  418. // Trac #9672 Feb 2014 x = infinity is now allowed.
  419. //BOOST_MATH_CHECK_THROW(pdf(L1, +std::numeric_limits<RealType>::infinity()), std::domain_error);
  420. //BOOST_MATH_CHECK_THROW(pdf(L1, -std::numeric_limits<RealType>::infinity()), std::domain_error);
  421. //BOOST_MATH_CHECK_THROW(pdf(L2, +std::numeric_limits<RealType>::infinity()), std::domain_error);
  422. //BOOST_MATH_CHECK_THROW(pdf(L2, -std::numeric_limits<RealType>::infinity()), std::domain_error);
  423. // Check cdf at x = +/- infinity.
  424. //BOOST_MATH_CHECK_THROW(cdf(L1, +std::numeric_limits<RealType>::infinity()), std::domain_error);
  425. //BOOST_MATH_CHECK_THROW(cdf(L1, -std::numeric_limits<RealType>::infinity()), std::domain_error);
  426. //BOOST_MATH_CHECK_THROW(cdf(L2, +std::numeric_limits<RealType>::infinity()), std::domain_error);
  427. //BOOST_MATH_CHECK_THROW(cdf(L2, -std::numeric_limits<RealType>::infinity()), std::domain_error);
  428. // Check quantile at p = 0, 1 which return infinity.
  429. BOOST_CHECK_EQUAL(quantile(L1, 0), -std::numeric_limits<RealType>::infinity() );
  430. BOOST_CHECK_EQUAL(quantile(L1, 1), +std::numeric_limits<RealType>::infinity() );
  431. BOOST_CHECK_EQUAL(quantile(L2, 0), -std::numeric_limits<RealType>::infinity() );
  432. BOOST_CHECK_EQUAL(quantile(L2, 1), +std::numeric_limits<RealType>::infinity() );
  433. }
  434. }
  435. BOOST_AUTO_TEST_CASE( vs_GNU_Octave )
  436. {
  437. test_pdf_cdf_ocatave<float>();
  438. test_pdf_cdf_ocatave<double>();
  439. }
  440. BOOST_AUTO_TEST_CASE( cdf_quantile_symmetry )
  441. {
  442. test_cdf_quantile_symmetry<float>();
  443. test_cdf_quantile_symmetry<double>();
  444. }
  445. BOOST_AUTO_TEST_CASE( hazard_pdf_cdf_symmetry )
  446. {
  447. test_hazard_pdf_cdf_symmetry<float>();
  448. test_hazard_pdf_cdf_symmetry<double>();
  449. }
  450. BOOST_AUTO_TEST_CASE( location_scale_symmetry )
  451. {
  452. test_location_scale_symmetry<float>();
  453. test_location_scale_symmetry<double>();
  454. }
  455. BOOST_AUTO_TEST_CASE( mmm_moments )
  456. {
  457. test_mmm_moments<float>();
  458. test_mmm_moments<double>();
  459. }
  460. BOOST_AUTO_TEST_CASE( t_complemented )
  461. {
  462. test_complemented<float>();
  463. test_complemented<double>();
  464. }
  465. BOOST_AUTO_TEST_CASE( bad_dist_parameters )
  466. {
  467. test_bad_dist_parameters<float>();
  468. test_bad_dist_parameters<double>();
  469. }
  470. BOOST_AUTO_TEST_CASE( extreme_function_arguments )
  471. {
  472. BOOST_TEST_MESSAGE("extreme arguments");
  473. test_extreme_function_arguments<float>();
  474. test_extreme_function_arguments<double>();
  475. }
  476. /*
  477. Output:
  478. ------ Rebuild All started: Project: test_laplace, Configuration: Debug Win32 ------
  479. test_laplace.cpp
  480. test_laplace.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Debug\test_laplace.exe
  481. Running 8 test cases...
  482. *** No errors detected
  483. ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
  484. */