diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-12 17:08:57 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-12 17:08:57 +0000 |
commit | bcc4ff0db04b082e86696294e370475d6936f797 (patch) | |
tree | a06c95794b3b16cf460adb487b26aa18c2d0824b /libcxx/test | |
parent | 54818f0c37dc2800220ba2d7a1314452b04cd39c (diff) | |
download | bcm5719-llvm-bcc4ff0db04b082e86696294e370475d6936f797.tar.gz bcm5719-llvm-bcc4ff0db04b082e86696294e370475d6936f797.zip |
[rand.dist.pois.exp]
llvm-svn: 103621
Diffstat (limited to 'libcxx/test')
19 files changed, 621 insertions, 2 deletions
diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp index 9727949a48a..74139d4d6be 100644 --- a/libcxx/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp @@ -17,8 +17,6 @@ #include <random> #include <cassert> -#include <iostream> - int main() { { diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp new file mode 100644 index 00000000000..5a54926e8ce --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// exponential_distribution& operator=(const exponential_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::exponential_distribution<> D; + D d1(0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp new file mode 100644 index 00000000000..1b9a563e1aa --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// exponential_distribution(const exponential_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::exponential_distribution<> D; + D d1(1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp new file mode 100644 index 00000000000..cafd42c923a --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// explicit exponential_distribution(RealType lambda = 1.0); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + D d; + assert(d.lambda() == 1); + } + { + typedef std::exponential_distribution<> D; + D d(3.5); + assert(d.lambda() == 3.5); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp new file mode 100644 index 00000000000..4585f19fd40 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.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 RealType = double> +// class exponential_distribution + +// explicit exponential_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.lambda() == 0.25); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp new file mode 100644 index 00000000000..704232f5919 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// bool operator=(const exponential_distribution& x, +// const exponential_distribution& y); +// bool operator!(const exponential_distribution& x, +// const exponential_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + D d1(.25); + D d2(.25); + assert(d1 == d2); + } + { + typedef std::exponential_distribution<> D; + D d1(.28); + D d2(.25); + assert(d1 != d2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp new file mode 100644 index 00000000000..48cfc7ed628 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <cassert> +#include <vector> +#include <numeric> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + typedef std::knuth_b G; + G g; + D d(.75); + const int N = 1000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + for (int i = 0; i < u.size(); ++i) + var += sqr(u[i] - mean); + var /= u.size(); + D::result_type x_mean = 1/d.lambda(); + D::result_type x_var = 1/sqr(d.lambda()); + assert(std::abs(mean - x_mean) / x_mean < 0.01); + assert(std::abs(var - x_var) / x_var < 0.01); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp new file mode 100644 index 00000000000..e51b45e3608 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <cassert> +#include <vector> +#include <numeric> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + typedef std::knuth_b G; + G g; + D d(.75); + P p(2); + const int N = 1000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + for (int i = 0; i < u.size(); ++i) + var += sqr(u[i] - mean); + var /= u.size(); + D::result_type x_mean = 1/p.lambda(); + D::result_type x_var = 1/sqr(p.lambda()); + assert(std::abs(mean - x_mean) / x_mean < 0.01); + assert(std::abs(var - x_var) / x_var < 0.01); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp new file mode 100644 index 00000000000..fcd08b27144 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.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 RealType = double> +// class exponential_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + P p(.125); + D d(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp new file mode 100644 index 00000000000..953a588249c --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const exponential_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// exponential_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + D d1(7); + 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.pois/rand.dist.pois.exp/max.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp new file mode 100644 index 00000000000..004b8787a44 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + D d(.25); + D::result_type m = d.max(); + assert(146 < m && m < 147); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp new file mode 100644 index 00000000000..d21419559b5 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + D d(.5); + assert(d.min() == 0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp new file mode 100644 index 00000000000..eecd79ab83d --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.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 RealType = double> +// class exponential_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p0(.7); + param_type p; + p = p0; + assert(p.lambda() == .7); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp new file mode 100644 index 00000000000..c7c5c1c9c9b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p0(.125); + param_type p = p0; + assert(p.lambda() == .125); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp new file mode 100644 index 00000000000..d042225c973 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.lambda() == 1); + } + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.lambda() == 10); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp new file mode 100644 index 00000000000..64185041f4f --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::exponential_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.5); + assert(p1 != p2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp new file mode 100644 index 00000000000..9795a4539a8 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::exponential_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.pois/rand.dist.pois.exp/set_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp new file mode 100644 index 00000000000..125b1d3ff00 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_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 RealType = double> +// class exponential_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(0.75); + d.param(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp new file mode 100644 index 00000000000..e8023860d42 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class exponential_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::exponential_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::exponential_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} |