]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/random/test/test_uniform_on_sphere_distribution.cpp
1 /* test_uniform_on_sphere_distribution.cpp
3 * Copyright Steven Watanabe 2011
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/random/uniform_on_sphere.hpp>
13 #include <boost/assign/list_of.hpp>
17 #define BOOST_RANDOM_DISTRIBUTION boost::random::uniform_on_sphere<>
18 #define BOOST_RANDOM_ARG1 dim
19 #define BOOST_RANDOM_ARG1_DEFAULT 2
20 #define BOOST_RANDOM_ARG1_VALUE 3
22 std::vector
<double> min0
= boost::assign::list_of(-1.0)(0.0);
23 std::vector
<double> max0
= boost::assign::list_of(1.0)(0.0);
24 std::vector
<double> min1
= boost::assign::list_of(-1.0)(0.0)(0.0);
25 std::vector
<double> max1
= boost::assign::list_of(1.0)(0.0)(0.0);
27 #define BOOST_RANDOM_DIST0_MIN min0
28 #define BOOST_RANDOM_DIST0_MAX max0
29 #define BOOST_RANDOM_DIST1_MIN min1
30 #define BOOST_RANDOM_DIST1_MAX max1
32 #define BOOST_RANDOM_TEST1_PARAMS (0)
33 #define BOOST_RANDOM_TEST1_MIN std::vector<double>()
34 #define BOOST_RANDOM_TEST1_MAX std::vector<double>()
35 #define BOOST_RANDOM_TEST2_PARAMS
36 #define BOOST_RANDOM_TEST2_MIN min0
37 #define BOOST_RANDOM_TEST2_MAX max0
39 #include <boost/test/test_tools.hpp>
41 BOOST_TEST_DONT_PRINT_LOG_VALUE( std::vector
<double> )
43 #include "test_distribution.ipp"
45 #include <boost/math/special_functions/fpclassify.hpp>
47 struct generate_zeros
{
49 generate_zeros() : i(0) {}
50 typedef unsigned result_type
;
51 static unsigned (min
)() { return 0u; }
52 static unsigned (max
)() { return boost::random::minstd_rand0::max(); }
53 unsigned operator()() {
54 static unsigned data
[] = { 0, 0, 0, 0, 0, 0 };
63 boost::random::minstd_rand0 gen
;
66 BOOST_AUTO_TEST_CASE(test_zeros
) {
68 boost::random::uniform_on_sphere
<> dist(2);
69 std::vector
<double> val
= dist(gen
);
70 BOOST_CHECK(!(boost::math::isnan
)(val
[0]));
73 BOOST_AUTO_TEST_CASE(test_valid_output
) {
74 boost::random::minstd_rand0 gen
;
75 for(int n
= 0; n
< 10; ++n
) {
76 boost::random::uniform_on_sphere
<> dist(n
);
77 std::vector
<double> result
= dist(gen
);
78 BOOST_TEST(result
.size() == static_cast<std::size_t>(n
));
81 for(std::size_t j
= 0; j
< result
.size(); ++j
) {
82 sum_sq
+= result
[j
] * result
[j
];
84 BOOST_CHECK_CLOSE_FRACTION(sum_sq
, 1.0, 1e-5);