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)
5
6 //
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).
10 //
11
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;
17
18 //template <class T>
19 //inline void check_result_imp(T, T){}
20
check_result_imp(float,float)21 inline void check_result_imp(float, float){}
check_result_imp(double,double)22 inline void check_result_imp(double, double){}
check_result_imp(long double,long double)23 inline void check_result_imp(long double, long double){}
check_result_imp(int,int)24 inline void check_result_imp(int, int){}
check_result_imp(long,long)25 inline void check_result_imp(long, long){}
26 #ifdef BOOST_HAS_LONG_LONG
check_result_imp(boost::long_long_type,boost::long_long_type)27 inline void check_result_imp(boost::long_long_type, boost::long_long_type){}
28 #endif
check_result_imp(bool,bool)29 inline void check_result_imp(bool, bool){}
30
31 //
32 // If the compiler warns about unused typedefs then enable this:
33 //
34 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
35 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
36 #else
37 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE
38 #endif
39
40 template <class T, class U>
41 struct local_is_same
42 {
43 enum{ value = false };
44 };
45 template <class T>
46 struct local_is_same<T, T>
47 {
48 enum{ value = true };
49 };
50
51 template <class T1, class T2>
check_result_imp(T1,T2)52 inline void check_result_imp(T1, T2)
53 {
54 // This is a static assertion that should always fail to compile...
55 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
58 #endif
59 typedef BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE int static_assertion[local_is_same<T1, T2>::value ? 1 : 0];
60 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))
61 #pragma GCC diagnostic pop
62 #endif
63 }
64
65 template <class T1, class T2>
check_result(T2)66 inline void check_result(T2)
67 {
68 T1 a = T1();
69 T2 b = T2();
70 return check_result_imp(a, b);
71 }
72
73 union max_align_type
74 {
75 char c;
76 short s;
77 int i;
78 long l;
79 double d;
80 long double ld;
81 #ifdef BOOST_HAS_LONG_LONG
82 long long ll;
83 #endif
84 };
85
86 template <class Distribution>
87 struct DistributionConcept
88 {
constraintsDistributionConcept89 static void constraints()
90 {
91 typedef typename Distribution::value_type value_type;
92
93 const Distribution& dist = DistributionConcept<Distribution>::get_object();
94
95 value_type x = 0;
96 // The result values are ignored in all these checks.
97 check_result<value_type>(cdf(dist, x));
98 check_result<value_type>(cdf(complement(dist, x)));
99 check_result<value_type>(pdf(dist, x));
100 check_result<value_type>(quantile(dist, x));
101 check_result<value_type>(quantile(complement(dist, x)));
102 check_result<value_type>(mean(dist));
103 check_result<value_type>(mode(dist));
104 check_result<value_type>(standard_deviation(dist));
105 check_result<value_type>(variance(dist));
106 check_result<value_type>(hazard(dist, x));
107 check_result<value_type>(chf(dist, x));
108 check_result<value_type>(coefficient_of_variation(dist));
109 check_result<value_type>(skewness(dist));
110 check_result<value_type>(kurtosis(dist));
111 check_result<value_type>(kurtosis_excess(dist));
112 check_result<value_type>(median(dist));
113 //
114 // we can't actually test that at std::pair is returned from these
115 // because that would mean including some std lib headers....
116 //
117 range(dist);
118 support(dist);
119
120 check_result<value_type>(cdf(dist, f));
121 check_result<value_type>(cdf(complement(dist, f)));
122 check_result<value_type>(pdf(dist, f));
123 check_result<value_type>(quantile(dist, f));
124 check_result<value_type>(quantile(complement(dist, f)));
125 check_result<value_type>(hazard(dist, f));
126 check_result<value_type>(chf(dist, f));
127 check_result<value_type>(cdf(dist, d));
128 check_result<value_type>(cdf(complement(dist, d)));
129 check_result<value_type>(pdf(dist, d));
130 check_result<value_type>(quantile(dist, d));
131 check_result<value_type>(quantile(complement(dist, d)));
132 check_result<value_type>(hazard(dist, d));
133 check_result<value_type>(chf(dist, d));
134 check_result<value_type>(cdf(dist, l));
135 check_result<value_type>(cdf(complement(dist, l)));
136 check_result<value_type>(pdf(dist, l));
137 check_result<value_type>(quantile(dist, l));
138 check_result<value_type>(quantile(complement(dist, l)));
139 check_result<value_type>(hazard(dist, l));
140 check_result<value_type>(chf(dist, l));
141 check_result<value_type>(cdf(dist, i));
142 check_result<value_type>(cdf(complement(dist, i)));
143 check_result<value_type>(pdf(dist, i));
144 check_result<value_type>(quantile(dist, i));
145 check_result<value_type>(quantile(complement(dist, i)));
146 check_result<value_type>(hazard(dist, i));
147 check_result<value_type>(chf(dist, i));
148 unsigned long li = 1;
149 check_result<value_type>(cdf(dist, li));
150 check_result<value_type>(cdf(complement(dist, li)));
151 check_result<value_type>(pdf(dist, li));
152 check_result<value_type>(quantile(dist, li));
153 check_result<value_type>(quantile(complement(dist, li)));
154 check_result<value_type>(hazard(dist, li));
155 check_result<value_type>(chf(dist, li));
156 }
157 private:
storageDistributionConcept158 static void* storage()
159 {
160 static max_align_type storage[sizeof(Distribution)];
161 return storage;
162 }
get_object_pDistributionConcept163 static Distribution* get_object_p()
164 {
165 return static_cast<Distribution*>(storage());
166 }
get_objectDistributionConcept167 static Distribution& get_object()
168 {
169 // will never get called:
170 return *get_object_p();
171 }
172 }; // struct DistributionConcept
173
174 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
175 #define TEST_DIST_FUNC(dist)\
176 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
177 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();\
178 DistributionConcept< boost::math::dist##_distribution<long double> >::constraints();
179 #else
180 #define TEST_DIST_FUNC(dist)\
181 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
182 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();
183 #endif
184