1 // Copyright John Maddock 2007.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Note this header must NOT include any other headers, for its
8 // use to be meaningful (because we use it in tests designed to
9 // detect missing includes).
12 static const float f = 0;
13 static const double d = 0;
14 static const long double l = 0;
15 static const unsigned u = 0;
16 static const int i = 0;
19 //inline void check_result_imp(T, T){}
21 inline void check_result_imp(float, float){}
22 inline void check_result_imp(double, double){}
23 inline void check_result_imp(long double, long double){}
24 inline void check_result_imp(int, int){}
25 inline void check_result_imp(long, long){}
26 #ifdef BOOST_HAS_LONG_LONG
27 inline void check_result_imp(boost::long_long_type, boost::long_long_type){}
29 inline void check_result_imp(bool, bool){}
32 // If the compiler warns about unused typedefs then enable this:
34 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
35 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
37 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE
40 template <class T, class U>
43 enum{ value = false };
46 struct local_is_same<T, T>
51 template <class T1, class T2>
52 inline void check_result_imp(T1, T2)
54 // This is a static assertion that should always fail to compile...
55 typedef BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE int static_assertion[local_is_same<T1, T2>::value ? 1 : 0];
58 template <class T1, class T2>
59 inline void check_result(T2)
63 return check_result_imp(a, b);
74 #ifdef BOOST_HAS_LONG_LONG
79 template <class Distribution>
80 struct DistributionConcept
82 static void constraints()
84 typedef typename Distribution::value_type value_type;
86 const Distribution& dist = DistributionConcept<Distribution>::get_object();
89 // The result values are ignored in all these checks.
90 check_result<value_type>(cdf(dist, x));
91 check_result<value_type>(cdf(complement(dist, x)));
92 check_result<value_type>(pdf(dist, x));
93 check_result<value_type>(quantile(dist, x));
94 check_result<value_type>(quantile(complement(dist, x)));
95 check_result<value_type>(mean(dist));
96 check_result<value_type>(mode(dist));
97 check_result<value_type>(standard_deviation(dist));
98 check_result<value_type>(variance(dist));
99 check_result<value_type>(hazard(dist, x));
100 check_result<value_type>(chf(dist, x));
101 check_result<value_type>(coefficient_of_variation(dist));
102 check_result<value_type>(skewness(dist));
103 check_result<value_type>(kurtosis(dist));
104 check_result<value_type>(kurtosis_excess(dist));
105 check_result<value_type>(median(dist));
107 // we can't actually test that at std::pair is returned from these
108 // because that would mean including some std lib headers....
113 check_result<value_type>(cdf(dist, f));
114 check_result<value_type>(cdf(complement(dist, f)));
115 check_result<value_type>(pdf(dist, f));
116 check_result<value_type>(quantile(dist, f));
117 check_result<value_type>(quantile(complement(dist, f)));
118 check_result<value_type>(hazard(dist, f));
119 check_result<value_type>(chf(dist, f));
120 check_result<value_type>(cdf(dist, d));
121 check_result<value_type>(cdf(complement(dist, d)));
122 check_result<value_type>(pdf(dist, d));
123 check_result<value_type>(quantile(dist, d));
124 check_result<value_type>(quantile(complement(dist, d)));
125 check_result<value_type>(hazard(dist, d));
126 check_result<value_type>(chf(dist, d));
127 check_result<value_type>(cdf(dist, l));
128 check_result<value_type>(cdf(complement(dist, l)));
129 check_result<value_type>(pdf(dist, l));
130 check_result<value_type>(quantile(dist, l));
131 check_result<value_type>(quantile(complement(dist, l)));
132 check_result<value_type>(hazard(dist, l));
133 check_result<value_type>(chf(dist, l));
134 check_result<value_type>(cdf(dist, i));
135 check_result<value_type>(cdf(complement(dist, i)));
136 check_result<value_type>(pdf(dist, i));
137 check_result<value_type>(quantile(dist, i));
138 check_result<value_type>(quantile(complement(dist, i)));
139 check_result<value_type>(hazard(dist, i));
140 check_result<value_type>(chf(dist, i));
141 unsigned long li = 1;
142 check_result<value_type>(cdf(dist, li));
143 check_result<value_type>(cdf(complement(dist, li)));
144 check_result<value_type>(pdf(dist, li));
145 check_result<value_type>(quantile(dist, li));
146 check_result<value_type>(quantile(complement(dist, li)));
147 check_result<value_type>(hazard(dist, li));
148 check_result<value_type>(chf(dist, li));
151 static void* storage()
153 static max_align_type storage[sizeof(Distribution)];
156 static Distribution* get_object_p()
158 return static_cast<Distribution*>(storage());
160 static Distribution& get_object()
162 // will never get called:
163 return *get_object_p();
165 }; // struct DistributionConcept
167 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
168 #define TEST_DIST_FUNC(dist)\
169 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
170 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();\
171 DistributionConcept< boost::math::dist##_distribution<long double> >::constraints();
173 #define TEST_DIST_FUNC(dist)\
174 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
175 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();