diff options
Diffstat (limited to 'libcxx/test')
24 files changed, 1505 insertions, 0 deletions
diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp new file mode 100644 index 00000000000..77b69234f71 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// piecewise_linear_distribution& operator=(const piecewise_linear_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_linear_distribution<> D; + double p[] = {2, 4, 1, 8, 3}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp new file mode 100644 index 00000000000..3bc165f64b9 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// piecewise_linear_distribution(const piecewise_linear_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_linear_distribution<> D; + double p[] = {2, 4, 1, 8, 2}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp new file mode 100644 index 00000000000..ca0b775ebfc --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// piecewise_linear_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + D d; + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp new file mode 100644 index 00000000000..fed6f565dbb --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class UnaryOperation> +// piecewise_linear_distribution(size_t nw, result_type xmin, +// result_type xmax, UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + D d(0, 0, 1, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0); + assert(dn[1] == 2); + } + { + typedef std::piecewise_linear_distribution<> D; + D d(1, 10, 12, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + D d(2, 6, 14, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp new file mode 100644 index 00000000000..77aab01e23d --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// piecewise_linear_distribution(initializer_list<result_type> bl, +// UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::piecewise_linear_distribution<> D; + D d({}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({12}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({10, 12}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({6, 10, 14}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +#endif +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp new file mode 100644 index 00000000000..89ba21a9cd4 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class InputIterator> +// piecewise_linear_distribution(InputIteratorB firstB, +// InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b+1, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 15}; + double p[] = {20, 20}; + D d(b, b+2, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1/5.); + assert(dn[1] == 1/5.); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 15, 16}; + double p[] = {.25, .75, .25}; + D d(b, b+3, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == .25/3); + assert(dn[1] == .75/3); + assert(dn[2] == .25/3); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + D d(b, b+4, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 4); + assert(dn[0] == 0); + assert(dn[1] == 1/4.5); + assert(dn[2] == 1/4.5); + assert(dn[3] == 0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp new file mode 100644 index 00000000000..1eb492625c2 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// explicit piecewise_linear_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P pa(b, b+4, p); + D d(pa); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 4); + assert(dn[0] == 25/256.25); + assert(dn[1] == 62.5/256.25); + assert(dn[2] == 12.5/256.25); + assert(dn[3] == 0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp new file mode 100644 index 00000000000..b394cd8ab58 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// bool operator=(const piecewise_linear_distribution& x, +// const piecewise_linear_distribution& y); +// bool operator!(const piecewise_linear_distribution& x, +// const piecewise_linear_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 1}; + D d1(b, b+4, p); + D d2(b, b+4, p); + assert(d1 == d2); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + D d1(b, b+4, p); + D d2; + assert(d1 != d2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp new file mode 100644 index 00000000000..ce884a88b8c --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp @@ -0,0 +1,341 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <iostream> + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +double +f(double x, double a, double m, double b, double c) +{ + return a + m*(sqr(x) - sqr(b))/2 + c*(x-b); +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 0, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {1, 0, 0, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {0, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14}; + double p[] = {1, 1}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp new file mode 100644 index 00000000000..b024b8781f8 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +double +f(double x, double a, double m, double b, double c) +{ + return a + m*(sqr(x) - sqr(b))/2 + c*(x-b); +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d; + P pa(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, pa); + assert(10 <= v && v < 17); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp new file mode 100644 index 00000000000..b04b8512f6a --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 10}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P pa(b, b+Np+1, p); + D d(pa); + assert(d.param() == pa); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp new file mode 100644 index 00000000000..d1640626740 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const piecewise_linear_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// piecewise_linear_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d1(b, b+Np+1, p); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp new file mode 100644 index 00000000000..351b94d598c --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np, p); + assert(d.max() == 17); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp new file mode 100644 index 00000000000..df0835f8518 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np, p); + assert(d.min() == 10); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp new file mode 100644 index 00000000000..baa9d216d90 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 2}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np, p); + P p1; + p1 = p0; + assert(p1 == p0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp new file mode 100644 index 00000000000..56e2fcd3f53 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np, p); + P p1 = p0; + assert(p1 == p0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp new file mode 100644 index 00000000000..74177134a2e --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// param_type(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa; + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp new file mode 100644 index 00000000000..73c861605f2 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class UnaryOperation> +// param_type(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(0, 0, 1, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0); + assert(dn[1] == 2); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(1, 10, 12, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(2, 6, 14, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp new file mode 100644 index 00000000000..1b01b05e4e5 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// param_type(initializer_list<result_type> bl, UnaryOperation fw); + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({12}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({10, 12}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({6, 10, 14}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +#endif +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp new file mode 100644 index 00000000000..5be45b87072 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// template<class InputIterator> +// param_type(InputIteratorB firstB, InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b+1, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15}; + double p[] = {12, 12}; + P pa(b, b+2, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1/5.); + assert(dn[1] == 1/5.); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15, 16}; + double p[] = {.25, .75, .25}; + P pa(b, b+3, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == .25/3); + assert(dn[1] == .75/3); + assert(dn[2] == .25/3); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + P pa(b, b+4, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 4); + assert(dn[0] == 0); + assert(dn[1] == 1/4.5); + assert(dn[2] == 1/4.5); + assert(dn[3] == 0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp new file mode 100644 index 00000000000..28fb0f8c187 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P p1(b, b+4, p); + P p2(b, b+4, p); + assert(p1 == p2); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P p1(b, b+3, p); + P p2(b, b+4, p); + assert(p1 != p2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp new file mode 100644 index 00000000000..4fd475ee135 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp new file mode 100644 index 00000000000..4e8ac964075 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P pa(b, b+4, p); + D d; + d.param(pa); + assert(d.param() == pa); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp new file mode 100644 index 00000000000..2662abfd1fb --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::piecewise_linear_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} |

