diff options
Diffstat (limited to 'libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real')
18 files changed, 1075 insertions, 0 deletions
diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp new file mode 100644 index 00000000000..9651a2f0596 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// uniform_real_distribution& operator=(const uniform_real_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_real_distribution<float> D; + D d1(2, 5); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp new file mode 100644 index 00000000000..073c3a85157 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// uniform_real_distribution(const uniform_real_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_real_distribution<float> D; + D d1(2, 5); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp new file mode 100644 index 00000000000..03abc536210 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// explicit uniform_real_distribution(RealType a = 0, +// RealType b = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d; + assert(d.a() == 0); + assert(d.b() == 1); + } + { + typedef std::uniform_real_distribution<> D; + D d(-6); + assert(d.a() == -6); + assert(d.b() == 1); + } + { + typedef std::uniform_real_distribution<> D; + D d(-6, 106); + assert(d.a() == -6); + assert(d.b() == 106); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp new file mode 100644 index 00000000000..a6f4aff93d8 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// explicit uniform_real_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3.5, 8); + D d(p); + assert(d.a() == 3.5); + assert(d.b() == 8); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp new file mode 100644 index 00000000000..5fcba4346dc --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// bool operator=(const uniform_real_distribution& x, +// const uniform_real_distribution& y); +// bool operator!(const uniform_real_distribution& x, +// const uniform_real_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + D d2(3, 8); + assert(d1 == d2); + } + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + D d2(3, 8.1); + assert(d1 != d2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp new file mode 100644 index 00000000000..2663b2683bb --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp @@ -0,0 +1,474 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// <random> + +// template<class RealType = double> +// class uniform_real_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::uniform_real_distribution<> D; + typedef std::minstd_rand0 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::mt19937 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::mt19937_64 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux24_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.02); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux48_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux24 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux48 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::knuth_b G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(-1, 1); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(5.5, 25); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp new file mode 100644 index 00000000000..b5803f40146 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <cassert> +#include <vector> +#include <numeric> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + typedef D::param_type P; + G g; + D d(5.5, 25); + P p(-10, 20); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(p.a() <= v && v < p.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (p.a() + p.b()) / 2; + D::result_type x_var = sqr(p.b() - p.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp new file mode 100644 index 00000000000..0496d853e32 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp new file mode 100644 index 00000000000..17ff9388930 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const uniform_real_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// uniform_real_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp new file mode 100644 index 00000000000..6baa6d81a83 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d(3, 8); + assert(d.max() == 8); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp new file mode 100644 index 00000000000..3974258c54d --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d(3, 8); + assert(d.min() == 3); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp new file mode 100644 index 00000000000..07497fef531 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p; + p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp new file mode 100644 index 00000000000..d64df7dacb6 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp new file mode 100644 index 00000000000..8f21ebfbdbb --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 0); + assert(p.b() == 1); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p(5); + assert(p.a() == 5); + assert(p.b() == 1); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p(5, 10); + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp new file mode 100644 index 00000000000..62df68ca628 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(5, 10); + assert(p1 == p2); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(6, 10); + assert(p1 != p2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp new file mode 100644 index 00000000000..27c0998be25 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + typedef param_type::distribution_type distribution_type; + static_assert((std::is_same<D, distribution_type>::value), ""); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp new file mode 100644 index 00000000000..1ff121def10 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(6, 7); + d.param(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp new file mode 100644 index 00000000000..b0e792fdd62 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// typedef IntType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} |