diff options
Diffstat (limited to 'libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp')
-rw-r--r-- | libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp new file mode 100644 index 00000000000..48cfc7ed628 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <cassert> +#include <vector> +#include <numeric> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + typedef std::knuth_b G; + G g; + D d(.75); + const int N = 1000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + for (int i = 0; i < u.size(); ++i) + var += sqr(u[i] - mean); + var /= u.size(); + D::result_type x_mean = 1/d.lambda(); + D::result_type x_var = 1/sqr(d.lambda()); + assert(std::abs(mean - x_mean) / x_mean < 0.01); + assert(std::abs(var - x_var) / x_var < 0.01); + } +} |