diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-19 01:53:57 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-19 01:53:57 +0000 |
commit | fb0e5ec825c26d4ef8a99bcb38b95a4ca1c0316e (patch) | |
tree | b264b0a151d2e24fccc290539f330f15ad767a2a /libcxx/test | |
parent | 2c452fcd1419110641ed2094836aca394c6b6d4e (diff) | |
download | bcm5719-llvm-fb0e5ec825c26d4ef8a99bcb38b95a4ca1c0316e.tar.gz bcm5719-llvm-fb0e5ec825c26d4ef8a99bcb38b95a4ca1c0316e.zip |
[rand.dist.samp.discrete]
llvm-svn: 104103
Diffstat (limited to 'libcxx/test')
24 files changed, 1326 insertions, 0 deletions
diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp new file mode 100644 index 00000000000..617fa75d641 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp new file mode 100644 index 00000000000..1a453be6c33 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp new file mode 100644 index 00000000000..dd401930815 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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() +{ + { + 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp new file mode 100644 index 00000000000..bad03ab5224 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp new file mode 100644 index 00000000000..fffb0dbaf43 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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() +{ +#ifdef _LIBCPP_MOVE + { + 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 +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp new file mode 100644 index 00000000000..9bc2161c7b3 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp new file mode 100644 index 00000000000..10651ddc116 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp new file mode 100644 index 00000000000..5691bbf33a9 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp new file mode 100644 index 00000000000..037aa39e365 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp @@ -0,0 +1,277 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp new file mode 100644 index 00000000000..d2c5a6788de --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp new file mode 100644 index 00000000000..1e36a262379 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp new file mode 100644 index 00000000000..c8e8a5e1c20 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp new file mode 100644 index 00000000000..c7787f1f372 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp new file mode 100644 index 00000000000..64738e474c6 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp new file mode 100644 index 00000000000..acbf6fab4c0 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp new file mode 100644 index 00000000000..e8877b8595a --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp new file mode 100644 index 00000000000..756dd3ee09c --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// param_type(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ + { + 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); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp new file mode 100644 index 00000000000..648305d8540 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp new file mode 100644 index 00000000000..bf01b0ae17f --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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() +{ +#ifdef _LIBCPP_MOVE + { + 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 +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp new file mode 100644 index 00000000000..110dd615413 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp new file mode 100644 index 00000000000..dd10bff7df8 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp new file mode 100644 index 00000000000..82d2bdcb507 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp new file mode 100644 index 00000000000..f3043f70321 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp new file mode 100644 index 00000000000..8871e1d6ab0 --- /dev/null +++ b/libcxx/test/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 distributed under the University of Illinois Open Source +// License. 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), ""); + } +} |