summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
committerEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
commit5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch)
treeafde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp
parentf11e8eab527fba316c64112f6e05de1a79693a3e (diff)
downloadbcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz
bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp')
-rw-r--r--libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp279
1 files changed, 279 insertions, 0 deletions
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);
+ }
+}
OpenPOWER on IntegriCloud