diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-12 21:02:31 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-12 21:02:31 +0000 |
commit | 6f97c4e7bc155f7200db4e53f33feb3c5d1bff95 (patch) | |
tree | 2646b97c4ba29b252380cc0daee4299caf678558 /libcxx/test | |
parent | 5aa20d6c26b0bb9bed6a859394107dab9c97117a (diff) | |
download | bcm5719-llvm-6f97c4e7bc155f7200db4e53f33feb3c5d1bff95.tar.gz bcm5719-llvm-6f97c4e7bc155f7200db4e53f33feb3c5d1bff95.zip |
[rand.dist.norm.normal]
llvm-svn: 103646
Diffstat (limited to 'libcxx/test')
18 files changed, 641 insertions, 0 deletions
diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp new file mode 100644 index 00000000000..c5f1df2be04 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// normal_distribution& operator=(const normal_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::normal_distribution<> D; + D d1(20, 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.norm/rand.dist.norm.normal/copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp new file mode 100644 index 00000000000..a3fc95cd2b6 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// normal_distribution(const normal_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::normal_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp new file mode 100644 index 00000000000..d4694dc7155 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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 normal_distribution + +// explicit normal_distribution(result_type mean = 0, result_type stddev = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + D d; + assert(d.mean() == 0); + assert(d.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + D d(14.5); + assert(d.mean() == 14.5); + assert(d.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + D d(14.5, 5.25); + assert(d.mean() == 14.5); + assert(d.stddev() == 5.25); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp new file mode 100644 index 00000000000..cf965652e8e --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_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 normal_distribution + +// explicit normal_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.mean() == 0.25); + assert(d.stddev() == 10); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp new file mode 100644 index 00000000000..52082b326d7 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// bool operator=(const normal_distribution& x, +// const normal_distribution& y); +// bool operator!(const normal_distribution& x, +// const normal_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::normal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp new file mode 100644 index 00000000000..b6d9550a05e --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_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::normal_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(5, 4); + 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 = d.mean(); + D::result_type x_var = sqr(d.stddev()); + 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.norm/rand.dist.norm.normal/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp new file mode 100644 index 00000000000..652c4c1dc2b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_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::normal_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(5, 4); + P p(50, .5); + 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 = p.mean(); + D::result_type x_var = sqr(p.stddev()); + 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.norm/rand.dist.norm.normal/get_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp new file mode 100644 index 00000000000..6a1afd757e0 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp new file mode 100644 index 00000000000..51a2185e329 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const normal_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// normal_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + D d1(7, 5); + 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.norm/rand.dist.norm.normal/max.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp new file mode 100644 index 00000000000..6e91d1605b7 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp new file mode 100644 index 00000000000..e251e16b580 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + D d(.5, .5); + assert(d.min() == -INFINITY); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp new file mode 100644 index 00000000000..f5cb6ad2c5b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 RealType = double> +// class normal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.mean() == .75); + assert(p.stddev() == 6); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp new file mode 100644 index 00000000000..8ddff2fa1a7 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 RealType = double> +// class normal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.mean() == 10); + assert(p.stddev() == .125); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp new file mode 100644 index 00000000000..1f184e911de --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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 normal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.mean() == 0); + assert(p.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.mean() == 10); + assert(p.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.mean() == 10); + assert(p.stddev() == 5); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp new file mode 100644 index 00000000000..c04f8bc08c1 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75, .5); + param_type p2(0.75, .5); + assert(p1 == p2); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75, .5); + param_type p2(0.5, .5); + assert(p1 != p2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp new file mode 100644 index 00000000000..edd2b8b0599 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::normal_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.norm/rand.dist.norm.normal/set_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp new file mode 100644 index 00000000000..a85dc466a1b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(0.25, 5.5); + D d(0.75, 4); + d.param(p); + assert(d.param() == p); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp new file mode 100644 index 00000000000..9fbaed3f834 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/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 normal_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::normal_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} |