diff options
Diffstat (limited to 'libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp')
73 files changed, 4694 insertions, 0 deletions
diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp new file mode 100644 index 00000000000..aee3f74f26c --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// discrete_distribution& operator=(const discrete_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::discrete_distribution<> D; + double p[] = {2, 4, 1, 8}; + D d1(p, p+4); + 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.samp/rand.dist.samp.discrete/copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp new file mode 100644 index 00000000000..b133ac708da --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// discrete_distribution(const discrete_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::discrete_distribution<> D; + double p[] = {2, 4, 1, 8}; + D d1(p, p+4); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp new file mode 100644 index 00000000000..3c1ed6a186e --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.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 IntType = int> +// class discrete_distribution + +// discrete_distribution(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp new file mode 100644 index 00000000000..34af69382c1 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class UnaryOperation> +// discrete_distribution(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return x+1; +} + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d(0, 0, 1, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d(1, 0, 1, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d(2, 0.5, 1.5, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == .4375); + assert(p[1] == .5625); + } + { + typedef std::discrete_distribution<> D; + D d(4, 0, 2, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 4); + assert(p[0] == .15625); + assert(p[1] == .21875); + assert(p[2] == .28125); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp new file mode 100644 index 00000000000..bc4494b9848 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// discrete_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + D d = {}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d = {10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d = {10, 30}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + D d = {30, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {30, 0, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {0, 30, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {0, 0, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp new file mode 100644 index 00000000000..65e14eeed2a --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class InputIterator> +// discrete_distribution(InputIterator firstW, InputIterator lastW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {1}; + D d(p0, p0); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10}; + D d(p0, p0+1); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10, 30}; + D d(p0, p0+2); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {30, 10}; + D d(p0, p0+2); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {30, 0, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {0, 30, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {0, 0, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp new file mode 100644 index 00000000000..c12fe45db92 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// explicit discrete_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10, 30}; + P pa(p0, p0+2); + D d(pa); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp new file mode 100644 index 00000000000..bad06987b0c --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// bool operator=(const discrete_distribution& x, +// const discrete_distribution& y); +// bool operator!(const discrete_distribution& x, +// const discrete_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {1}; + D d1(p0, p0+1); + D d2; + assert(d1 == d2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10, 30}; + D d1(p0, p0+2); + D d2; + assert(d1 != d2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp new file mode 100644 index 00000000000..55080b25202 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp @@ -0,0 +1,279 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <vector> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + D d; + const int N = 100; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + assert((double)u[i]/N == prob[i]); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {.3}; + D d(p0, p0+1); + const int N = 100; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + assert((double)u[i]/N == prob[i]); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {.75, .25}; + D d(p0, p0+2); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {0, 1}; + D d(p0, p0+2); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + assert((double)u[0]/N == prob[0]); + assert((double)u[1]/N == prob[1]); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {1, 0}; + D d(p0, p0+2); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + assert((double)u[0]/N == prob[0]); + assert((double)u[1]/N == prob[1]); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {.3, .1, .6}; + D d(p0, p0+3); + const int N = 10000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {0, 25, 75}; + D d(p0, p0+3); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {25, 0, 75}; + D d(p0, p0+3); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {25, 75, 0}; + D d(p0, p0+3); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {0, 0, 1}; + D d(p0, p0+3); + const int N = 100; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {0, 1, 0}; + D d(p0, p0+3); + const int N = 100; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {1, 0, 0}; + D d(p0, p0+3); + const int N = 100; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } + { + typedef std::discrete_distribution<> D; + typedef std::minstd_rand G; + G g; + double p0[] = {33, 0, 0, 67}; + D d(p0, p0+3); + const int N = 1000000; + std::vector<D::result_type> u(d.max()+1); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u[v]++; + } + std::vector<double> prob = d.probabilities(); + for (int i = 0; i <= d.max(); ++i) + if (prob[i] != 0) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + else + assert(u[i] == 0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp new file mode 100644 index 00000000000..8d8a2242409 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <vector> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d; + double p0[] = {.3, .1, .6}; + P p(p0, p0+3); + const int N = 10000000; + std::vector<D::result_type> u(3); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(0 <= v && v <= 2); + u[v]++; + } + std::vector<double> prob = p.probabilities(); + for (int i = 0; i <= 2; ++i) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp new file mode 100644 index 00000000000..4970c5aae40 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_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 IntType = int> +// class discrete_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {.3, .1, .6}; + P p(p0, p0+3); + D d(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp new file mode 100644 index 00000000000..92499501659 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const discrete_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// discrete_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d1(p0, p0+3); + 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.samp/rand.dist.samp.discrete/max.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp new file mode 100644 index 00000000000..b1d1acdab50 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.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 IntType = int> +// class discrete_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d(p0, p0+3); + assert(d.max() == 2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6, .2}; + D d(p0, p0+4); + assert(d.max() == 3); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp new file mode 100644 index 00000000000..ab938323814 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.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 IntType = int> +// class discrete_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d(p0, p0+3); + assert(d.min() == 0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp new file mode 100644 index 00000000000..ea57852b62c --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/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 IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double d0[] = {.3, .1, .6}; + param_type p0(d0, d0+3); + param_type p; + p = p0; + assert(p == p0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp new file mode 100644 index 00000000000..b65ebb0d8c7 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/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 IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double d0[] = {.3, .1, .6}; + param_type p0(d0, d0+3); + param_type p = p0; + assert(p == p0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp new file mode 100644 index 00000000000..1071305f4db --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.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 IntType = int> +// class discrete_distribution + +// param_type(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {1}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp new file mode 100644 index 00000000000..6d43b2234fc --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class UnaryOperation> +// param_type(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return x+1; +} + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(0, 0, 1, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(1, 0, 1, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(2, 0.5, 1.5, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == .4375); + assert(p[1] == .5625); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(4, 0, 2, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 4); + assert(p[0] == .15625); + assert(p[1] == .21875); + assert(p[2] == .28125); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp new file mode 100644 index 00000000000..79d8a0b71a9 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// param_type(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {10, 30}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {30, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {30, 0, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {0, 30, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {0, 0, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp new file mode 100644 index 00000000000..7ef646707c1 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution + +// template<class InputIterator> +// param_type(InputIterator firstW, InputIterator lastW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {1}; + P pa(p0, p0); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10}; + P pa(p0, p0+1); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10, 30}; + P pa(p0, p0+2); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {30, 10}; + P pa(p0, p0+2); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {30, 0, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {0, 30, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {0, 0, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp new file mode 100644 index 00000000000..6ec2c2aad4b --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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 IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double p0[] = {30, 10}; + param_type p1(p0, p0+2); + param_type p2(p0, p0+2); + assert(p1 == p2); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double p0[] = {30, 10}; + param_type p1(p0, p0+2); + param_type p2; + assert(p1 != p2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp new file mode 100644 index 00000000000..086b7600feb --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/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 IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::discrete_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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp new file mode 100644 index 00000000000..bc433ec7564 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.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 IntType = int> +// class discrete_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double d0[] = {.3, .1, .6}; + P p(d0, d0+3); + D d; + d.param(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp new file mode 100644 index 00000000000..af73008ff41 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.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 IntType = int> +// class discrete_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::discrete_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp new file mode 100644 index 00000000000..e5c994445d4 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// piecewise_constant_distribution& operator=(const piecewise_constant_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_constant_distribution<> D; + double p[] = {2, 4, 1, 8}; + 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.pass.cpp new file mode 100644 index 00000000000..a3eb1f4a503 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.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 piecewise_constant_distribution + +// piecewise_constant_distribution(const piecewise_constant_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_constant_distribution<> D; + double p[] = {2, 4, 1, 8}; + 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp new file mode 100644 index 00000000000..d4f339fe7f3 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// piecewise_constant_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp new file mode 100644 index 00000000000..74fa2344268 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// template<class UnaryOperation> +// piecewise_constant_distribution(size_t nw, result_type xmin, +// result_type xmax, UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_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() == 2); + assert(dn[0] == 0.1); + assert(dn[1] == 0.15); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp new file mode 100644 index 00000000000..5708e45093c --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// piecewise_constant_distribution(initializer_list<result_type> bl, +// UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + D d({12, 14}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 12); + assert(iv[1] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + D d({5.5, 7.5, 11.5}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 5.5); + assert(iv[1] == 7.5); + assert(iv[2] == 11.5); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.203125); + assert(dn[1] == 0.1484375); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp new file mode 100644 index 00000000000..d994b0a802b --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// template<class InputIterator> +// piecewise_constant_distribution(InputIteratorB firstB, +// InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 15}; + double p[] = {12}; + 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() == 1); + assert(dn[0] == 1/5.); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 15, 16}; + double p[] = {.25, .75}; + 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() == 2); + assert(dn[0] == .25/5.); + assert(dn[1] == .75); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + 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() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.pass.cpp new file mode 100644 index 00000000000..0ccdba6b964 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.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 piecewise_constant_distribution + +// explicit piecewise_constant_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + 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() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp new file mode 100644 index 00000000000..2ef9d7b6e0f --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// bool operator=(const piecewise_constant_distribution& x, +// const piecewise_constant_distribution& y); +// bool operator!(const piecewise_constant_distribution& x, +// const piecewise_constant_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + D d1(b, b+4, p); + D d2(b, b+4, p); + assert(d1 == d2); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + D d1(b, b+4, p); + D d2; + assert(d1 != d2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp new file mode 100644 index 00000000000..5d14b3612b2 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp @@ -0,0 +1,695 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + 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::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + 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::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 0, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + 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::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + 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::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 0, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 25, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 0, 1}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {75, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {0, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14}; + double p[] = {1}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + 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.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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.samp/rand.dist.samp.pconst/eval_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp new file mode 100644 index 00000000000..6850115875b --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_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; +} + +int main() +{ + { + typedef std::piecewise_constant_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}; + const size_t Np = sizeof(p) / sizeof(p[0]); + 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::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double 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.samp/rand.dist.samp.pconst/get_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/get_param.pass.cpp new file mode 100644 index 00000000000..fdda4e8f0d6 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/get_param.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 piecewise_constant_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.pass.cpp new file mode 100644 index 00000000000..9af776d549a --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.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 piecewise_constant_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const piecewise_constant_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// piecewise_constant_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.pass.cpp new file mode 100644 index 00000000000..772c36ed73e --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.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 piecewise_constant_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + assert(d.max() == 17); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.pass.cpp new file mode 100644 index 00000000000..66618ba95d7 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.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 piecewise_constant_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + assert(d.min() == 10); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_assign.pass.cpp new file mode 100644 index 00000000000..4d3a503584e --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_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 piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np+1, p); + P p1; + p1 = p0; + assert(p1 == p0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp new file mode 100644 index 00000000000..de63a54edfb --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np+1, p); + P p1 = p0; + assert(p1 == p0); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.pass.cpp new file mode 100644 index 00000000000..fd84d46713c --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.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 piecewise_constant_distribution + +// param_type(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp new file mode 100644 index 00000000000..98e3006f3e3 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_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_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_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() == 2); + assert(dn[0] == 0.1); + assert(dn[1] == 0.15); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp new file mode 100644 index 00000000000..fa6530979ed --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// param_type(initializer_list<result_type> bl, UnaryOperation fw); + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({12, 14}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 12); + assert(iv[1] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({5.5, 7.5, 11.5}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 5.5); + assert(iv[1] == 7.5); + assert(iv[2] == 11.5); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.203125); + assert(dn[1] == 0.1484375); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp new file mode 100644 index 00000000000..98d467c07e2 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_constant_distribution + +// template<class InputIterator> +// param_type(InputIteratorB firstB, InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_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() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15}; + double p[] = {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() == 1); + assert(dn[0] == 1/5.); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15, 16}; + double p[] = {.25, .75}; + 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() == 2); + assert(dn[0] == .25/5.); + assert(dn[1] == .75); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + 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() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.pass.cpp new file mode 100644 index 00000000000..9cc554e604a --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.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 piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P p1(b, b+4, p); + P p2(b, b+4, p); + assert(p1 == p2); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P p1(b, b+3, p); + P p2(b, b+4, p); + assert(p1 != p2); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_types.pass.cpp new file mode 100644 index 00000000000..e039df36c98 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/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 piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_constant_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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.pass.cpp new file mode 100644 index 00000000000..1a3fedb0940 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.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 piecewise_constant_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P pa(b, b+4, p); + D d; + d.param(pa); + assert(d.param() == pa); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.pass.cpp new file mode 100644 index 00000000000..76032597973 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.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 piecewise_constant_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::piecewise_constant_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp new file mode 100644 index 00000000000..0ba7dcb5919 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp new file mode 100644 index 00000000000..536b139dda6 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp new file mode 100644 index 00000000000..745bd6b97ec --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 piecewise_linear_distribution + +// piecewise_linear_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp new file mode 100644 index 00000000000..3ebaf77f756 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp new file mode 100644 index 00000000000..44c76f0cf6c --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp new file mode 100644 index 00000000000..5fce58bbd97 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp new file mode 100644 index 00000000000..7dc47b4a3a2 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp new file mode 100644 index 00000000000..766989c5889 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp new file mode 100644 index 00000000000..af75fce512e --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp @@ -0,0 +1,343 @@ +//===----------------------------------------------------------------------===// +// +// 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 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp new file mode 100644 index 00000000000..fe704228e78 --- /dev/null +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp new file mode 100644 index 00000000000..57a8ca5589c --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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, p); + D d(pa); + assert(d.param() == pa); + } +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp new file mode 100644 index 00000000000..1be2791fa47 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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, p); + 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.samp/rand.dist.samp.plinear/max.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp new file mode 100644 index 00000000000..3dc12b69253 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp new file mode 100644 index 00000000000..4d4a7603a01 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp new file mode 100644 index 00000000000..055b2f58e79 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp new file mode 100644 index 00000000000..87d94940a87 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp new file mode 100644 index 00000000000..0bdf2c337d2 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp new file mode 100644 index 00000000000..27e93ab6171 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp new file mode 100644 index 00000000000..cfa416434a2 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp new file mode 100644 index 00000000000..117a5ef93bb --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp new file mode 100644 index 00000000000..1adffc8ca86 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp new file mode 100644 index 00000000000..cea1e3dffd3 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp new file mode 100644 index 00000000000..e85a2f0ce4c --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp new file mode 100644 index 00000000000..a3421298787 --- /dev/null +++ b/libcxx/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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), ""); + } +} |