aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/26_numerics
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2011-03-24 16:49:19 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2011-03-24 16:49:19 +0000
commit113b21bdaf45d2b80d1585b4b2c9cb20395667be (patch)
tree910868d6c7c42cdefee69efc97a8e2516cb71df2 /libstdc++-v3/testsuite/26_numerics
parent67295642aaa617fe2419ab877e66aa280fb32802 (diff)
downloadgcc-113b21bdaf45d2b80d1585b4b2c9cb20395667be.zip
gcc-113b21bdaf45d2b80d1585b4b2c9cb20395667be.tar.gz
gcc-113b21bdaf45d2b80d1585b4b2c9cb20395667be.tar.bz2
random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), [...]): Fix construction of _M_gd.
2011-03-24 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), negative_binomial_distribution<>:: negative_binomial_distribution(const param_type&)): Fix construction of _M_gd. * include/bits/random.tcc (negative_binomial_distribution<>:: operator()): Fix computation, per Leger's algorithm. * testsuite/util/testsuite_random.h (discrete_pdf, negative_binomial_pdf, poisson_pdf, uniform_int_pdf): New. (binomial_pdf): Swap last two parameters. * testsuite/26_numerics/random/discrete_distribution/ operators/values.cc: New. * testsuite/26_numerics/random/negative_binomial_distribution/ operators/values.cc: Likewise. * testsuite/26_numerics/random/poisson_distribution/ operators/values.cc: Likewise. * testsuite/26_numerics/random/uniform_int_distribution/ operators/values.cc: Likewise. * testsuite/26_numerics/random/binomial_distribution/ operators/values.cc: Adjust. From-SVN: r171411
Diffstat (limited to 'libstdc++-v3/testsuite/26_numerics')
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/values.cc6
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/values.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/values.cc55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/values.cc51
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc50
5 files changed, 211 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/values.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/values.cc
index c0248ab..9fa8f03 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/values.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/values.cc
@@ -33,16 +33,16 @@ void test01()
std::binomial_distribution<> bd1(5, 0.3);
auto bbd1 = std::bind(bd1, eng);
- testDiscreteDist(bbd1, [](int n) { return binomial_pdf(n, 0.3, 5); } );
+ testDiscreteDist(bbd1, [](int n) { return binomial_pdf(n, 5, 0.3); } );
std::binomial_distribution<> bd2(55, 0.3);
auto bbd2 = std::bind(bd2, eng);
- testDiscreteDist(bbd2, [](int n) { return binomial_pdf(n, 0.3, 55); } );
+ testDiscreteDist(bbd2, [](int n) { return binomial_pdf(n, 55, 0.3); } );
// libstdc++/48114
std::binomial_distribution<> bd3(10, 0.75);
auto bbd3 = std::bind(bd3, eng);
- testDiscreteDist(bbd3, [](int n) { return binomial_pdf(n, 0.75, 10); } );
+ testDiscreteDist(bbd3, [](int n) { return binomial_pdf(n, 10, 0.75); } );
}
int main()
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/values.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/values.cc
new file mode 100644
index 0000000..1710875
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/values.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 26.5.8.6.1 Class template discrete_distribution [rand.dist.samp.discrete]
+
+#include <random>
+#include <functional>
+#include <testsuite_random.h>
+
+void test01()
+{
+ using namespace __gnu_test;
+
+ std::mt19937 eng;
+
+ std::discrete_distribution<> dd1({ });
+ auto bdd1 = std::bind(dd1, eng);
+ testDiscreteDist(bdd1, [](int n) { return discrete_pdf(n, { }); } );
+
+ std::discrete_distribution<> dd2({ 1.0, 3.0, 2.0});
+ auto bdd2 = std::bind(dd2, eng);
+ testDiscreteDist(bdd2, [](int n)
+ { return discrete_pdf(n, { 1.0, 3.0, 2.0}); } );
+
+ std::discrete_distribution<> dd3({ 2.0, 2.0, 1.0, 0.0, 4.0});
+ auto bdd3 = std::bind(dd3, eng);
+ testDiscreteDist(bdd3, [](int n)
+ { return discrete_pdf(n, { 2.0, 2.0, 1.0, 0.0, 4.0}); } );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/values.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/values.cc
new file mode 100644
index 0000000..fb5194a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/values.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-cmath "" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 26.5.8.3.4 Class template negative_binomial_distribution
+// [rand.dist.bern.negbin]
+
+#include <random>
+#include <functional>
+#include <testsuite_random.h>
+
+void test01()
+{
+ using namespace __gnu_test;
+
+ std::mt19937 eng;
+
+ std::negative_binomial_distribution<> nbd1(5, 0.3);
+ auto bnbd1 = std::bind(nbd1, eng);
+ testDiscreteDist(bnbd1, [](int n)
+ { return negative_binomial_pdf(n, 5, 0.3); } );
+
+ std::negative_binomial_distribution<> nbd2(55, 0.3);
+ auto bnbd2 = std::bind(nbd2, eng);
+ testDiscreteDist(bnbd2, [](int n)
+ { return negative_binomial_pdf(n, 55, 0.3); } );
+
+ std::negative_binomial_distribution<> nbd3(10, 0.75);
+ auto bnbd3 = std::bind(nbd3, eng);
+ testDiscreteDist(bnbd3, [](int n)
+ { return negative_binomial_pdf(n, 10, 0.75); } );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/values.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/values.cc
new file mode 100644
index 0000000..adfe9b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/values.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-cmath "" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 26.5.8.4.1 Class template poisson_distribution [rand.dist.pois.poisson]
+
+#include <random>
+#include <functional>
+#include <testsuite_random.h>
+
+void test01()
+{
+ using namespace __gnu_test;
+
+ std::mt19937 eng;
+
+ std::poisson_distribution<> pd1(3.0);
+ auto bpd1 = std::bind(pd1, eng);
+ testDiscreteDist(bpd1, [](int n) { return poisson_pdf(n, 3.0); } );
+
+ std::poisson_distribution<> pd2(15.0);
+ auto bpd2 = std::bind(pd2, eng);
+ testDiscreteDist(bpd2, [](int n) { return poisson_pdf(n, 15.0); } );
+
+ std::poisson_distribution<> pd3(30.0);
+ auto bpd3 = std::bind(pd3, eng);
+ testDiscreteDist(bpd3, [](int n) { return poisson_pdf(n, 30.0); } );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc
new file mode 100644
index 0000000..8cb99a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc
@@ -0,0 +1,50 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 26.5.8.2.1 Class template uniform_int_distribution [rand.dist.uni.int]
+
+#include <random>
+#include <functional>
+#include <testsuite_random.h>
+
+void test01()
+{
+ using namespace __gnu_test;
+
+ std::mt19937 eng;
+
+ std::uniform_int_distribution<> uid1(0, 2);
+ auto buid1 = std::bind(uid1, eng);
+ testDiscreteDist(buid1, [](int n) { return uniform_int_pdf(n, 0, 2); } );
+
+ std::uniform_int_distribution<> uid2(3, 7);
+ auto buid2 = std::bind(uid2, eng);
+ testDiscreteDist(buid2, [](int n) { return uniform_int_pdf(n, 3, 7); } );
+
+ std::uniform_int_distribution<> uid3(1, 20);
+ auto buid3 = std::bind(uid3, eng);
+ testDiscreteDist(buid3, [](int n) { return uniform_int_pdf(n, 1, 20); } );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}