diff options
22 files changed, 886 insertions, 1 deletions
diff --git a/libcxx/include/random b/libcxx/include/random index 63a44aae443..07c78d37388 100644 --- a/libcxx/include/random +++ b/libcxx/include/random @@ -909,7 +909,61 @@ template<class RealType = double> class lognormal_distribution; template<class RealType = double> - class chi_squared_distribution; +class chi_squared_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef chi_squared_distribution distribution_type; + + explicit param_type(result_type n = 1); + + result_type n() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit chi_squared_distribution(result_type n = 1); + explicit chi_squared_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type n() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + + friend bool operator==(const chi_squared_distribution& x, + const chi_squared_distribution& y); + friend bool operator!=(const chi_squared_distribution& x, + const chi_squared_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const chi_squared_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + chi_squared_distribution& x); +}; template<class RealType = double> class cauchy_distribution; @@ -3894,6 +3948,94 @@ operator>>(basic_istream<_CharT, _Traits>& __is, return __is; } +// chi_squared_distribution + +template<class _RealType = double> +class chi_squared_distribution +{ +public: + // types + typedef _RealType result_type; + + class param_type + { + result_type __n_; + public: + typedef chi_squared_distribution distribution_type; + + explicit param_type(result_type __n = 1) : __n_(__n) {} + + result_type n() const {return __n_;} + + friend bool operator==(const param_type& __x, const param_type& __y) + {return __x.__n_ == __y.__n_;} + friend bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + explicit chi_squared_distribution(result_type __n = 1) + : __p_(param_type(__n)) {} + explicit chi_squared_distribution(const param_type& __p) + : __p_(__p) {} + void reset() {} + + // generating functions + template<class _URNG> result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p) + {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} + + // property functions + result_type n() const {return __p_.n();} + + param_type param() const {return __p_;} + void param(const param_type& __p) {__p_ = __p;} + + result_type min() const {return 0;} + result_type max() const {return numeric_limits<result_type>::infinity();} + + + friend bool operator==(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend bool operator!=(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const chi_squared_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> _(__os); + __os.flags(ios_base::dec | ios_base::left); + __os << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + chi_squared_distribution<_RT>& __x) +{ + typedef chi_squared_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> _(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __n; + __is >> __n; + if (!__is.fail()) + __x.param(param_type(__n)); + return __is; +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_RANDOM diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b89f168e9c4 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/assign.pass.cpp new file mode 100644 index 00000000000..ce8d100f843 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// chi_squared_distribution& operator=(const chi_squared_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::chi_squared_distribution<> D; + D d1(20.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.chisq/copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/copy.pass.cpp new file mode 100644 index 00000000000..789b44d950a --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// chi_squared_distribution(const chi_squared_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::chi_squared_distribution<> D; + D d1(21.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.chisq/ctor_double.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_double.pass.cpp new file mode 100644 index 00000000000..d725805f6f7 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// explicit chi_squared_distribution(result_type alpha = 0, result_type beta = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + D d; + assert(d.n() == 1); + } + { + typedef std::chi_squared_distribution<> D; + D d(14.5); + assert(d.n() == 14.5); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_param.pass.cpp new file mode 100644 index 00000000000..ffbe44415cf --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// explicit chi_squared_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.n() == 0.25); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eq.pass.cpp new file mode 100644 index 00000000000..d52004b7121 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// bool operator=(const chi_squared_distribution& x, +// const chi_squared_distribution& y); +// bool operator!(const chi_squared_distribution& x, +// const chi_squared_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + D d1(2.5); + D d2(2.5); + assert(d1 == d2); + } + { + typedef std::chi_squared_distribution<> D; + D d1(4); + D d2(4.5); + assert(d1 != d2); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp new file mode 100644 index 00000000000..5c24f91ebaf --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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 chi_squared_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::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(0.5); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*d.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(1); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*d.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(2); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*d.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp new file mode 100644 index 00000000000..b771225b4d1 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// 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 chi_squared_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::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(0.5); + P p(1); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*p.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(1); + P p(2); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*p.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(2); + P p(.5); + const int N = 100000; + 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.n(); + D::result_type x_var = 2*p.n(); + assert(std::abs(mean - x_mean) / x_mean < 0.02); + assert(std::abs(var - x_var) / x_var < 0.02); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/get_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/get_param.pass.cpp new file mode 100644 index 00000000000..eb03084e3dd --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_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.norm/rand.dist.norm.chisq/io.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/io.pass.cpp new file mode 100644 index 00000000000..77b46d83659 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const chi_squared_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// chi_squared_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_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.norm/rand.dist.norm.chisq/max.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/max.pass.cpp new file mode 100644 index 00000000000..8252306f1bb --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + D d(5); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/min.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/min.pass.cpp new file mode 100644 index 00000000000..ee8240b6755 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + D d(.5); + assert(d.min() == 0); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_assign.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_assign.pass.cpp new file mode 100644 index 00000000000..cadc12f0e31 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75); + param_type p; + p = p0; + assert(p.n() == .75); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_copy.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_copy.pass.cpp new file mode 100644 index 00000000000..1e90c55d7eb --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type param_type; + param_type p0(10); + param_type p = p0; + assert(p.n() == 10); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_ctor.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_ctor.pass.cpp new file mode 100644 index 00000000000..2d6e9afc155 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.n() == 1); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.n() == 10); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_eq.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_eq.pass.cpp new file mode 100644 index 00000000000..5b3c081518b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::chi_squared_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.norm/rand.dist.norm.chisq/param_types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_types.pass.cpp new file mode 100644 index 00000000000..cbbea9ff7a1 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::chi_squared_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.chisq/set_param.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/set_param.pass.cpp new file mode 100644 index 00000000000..c3a0232e8cb --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::chi_squared_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.norm/rand.dist.norm.chisq/types.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/types.pass.cpp new file mode 100644 index 00000000000..964403e896b --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/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 chi_squared_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::chi_squared_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::chi_squared_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b89f168e9c4 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b89f168e9c4 --- /dev/null +++ b/libcxx/test/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} |