diff options
Diffstat (limited to 'test/std/numerics')
820 files changed, 43887 insertions, 0 deletions
diff --git a/test/std/numerics/c.math/cmath.pass.cpp b/test/std/numerics/c.math/cmath.pass.cpp new file mode 100644 index 000000000000..0b0d86288737 --- /dev/null +++ b/test/std/numerics/c.math/cmath.pass.cpp @@ -0,0 +1,1485 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <cmath> + +// NOTE: isinf and isnan are tested separately because they are expected to fail +// on linux. We don't want their expected failure to hide other failures in this file. + +#include <cmath> +#include <type_traits> +#include <cassert> + +#include "hexfloat.h" + +// convertible to int/float/double/etc +template <class T, int N=0> +struct Value { + operator T () { return T(N); } +}; + +// See PR21083 +// Ambiguous is a user-defined type that defines its own overloads of cmath +// functions. When the std overloads are candidates too (by using or adl), +// they should not interfere. +struct Ambiguous : std::true_type { // ADL + operator float () { return 0.f; } + operator double () { return 0.; } +}; +Ambiguous abs(Ambiguous){ return Ambiguous(); } +Ambiguous acos(Ambiguous){ return Ambiguous(); } +Ambiguous asin(Ambiguous){ return Ambiguous(); } +Ambiguous atan(Ambiguous){ return Ambiguous(); } +Ambiguous atan2(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous ceil(Ambiguous){ return Ambiguous(); } +Ambiguous cos(Ambiguous){ return Ambiguous(); } +Ambiguous cosh(Ambiguous){ return Ambiguous(); } +Ambiguous exp(Ambiguous){ return Ambiguous(); } +Ambiguous fabs(Ambiguous){ return Ambiguous(); } +Ambiguous floor(Ambiguous){ return Ambiguous(); } +Ambiguous fmod(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous frexp(Ambiguous, int*){ return Ambiguous(); } +Ambiguous ldexp(Ambiguous, int){ return Ambiguous(); } +Ambiguous log(Ambiguous){ return Ambiguous(); } +Ambiguous log10(Ambiguous){ return Ambiguous(); } +Ambiguous modf(Ambiguous, Ambiguous*){ return Ambiguous(); } +Ambiguous pow(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous sin(Ambiguous){ return Ambiguous(); } +Ambiguous sinh(Ambiguous){ return Ambiguous(); } +Ambiguous sqrt(Ambiguous){ return Ambiguous(); } +Ambiguous tan(Ambiguous){ return Ambiguous(); } +Ambiguous tanh(Ambiguous){ return Ambiguous(); } +Ambiguous signbit(Ambiguous){ return Ambiguous(); } +Ambiguous fpclassify(Ambiguous){ return Ambiguous(); } +Ambiguous isfinite(Ambiguous){ return Ambiguous(); } +Ambiguous isnormal(Ambiguous){ return Ambiguous(); } +Ambiguous isgreater(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous isgreaterequal(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous isless(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous islessequal(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous islessgreater(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous isunordered(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous acosh(Ambiguous){ return Ambiguous(); } +Ambiguous asinh(Ambiguous){ return Ambiguous(); } +Ambiguous atanh(Ambiguous){ return Ambiguous(); } +Ambiguous cbrt(Ambiguous){ return Ambiguous(); } +Ambiguous copysign(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous erf(Ambiguous){ return Ambiguous(); } +Ambiguous erfc(Ambiguous){ return Ambiguous(); } +Ambiguous exp2(Ambiguous){ return Ambiguous(); } +Ambiguous expm1(Ambiguous){ return Ambiguous(); } +Ambiguous fdim(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous fma(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous fmax(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous fmin(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous hypot(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous ilogb(Ambiguous){ return Ambiguous(); } +Ambiguous lgamma(Ambiguous){ return Ambiguous(); } +Ambiguous llrint(Ambiguous){ return Ambiguous(); } +Ambiguous llround(Ambiguous){ return Ambiguous(); } +Ambiguous log1p(Ambiguous){ return Ambiguous(); } +Ambiguous log2(Ambiguous){ return Ambiguous(); } +Ambiguous logb(Ambiguous){ return Ambiguous(); } +Ambiguous lrint(Ambiguous){ return Ambiguous(); } +Ambiguous lround(Ambiguous){ return Ambiguous(); } +Ambiguous nearbyint(Ambiguous){ return Ambiguous(); } +Ambiguous nextafter(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous nexttoward(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous remainder(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous remquo(Ambiguous, Ambiguous, int*){ return Ambiguous(); } +Ambiguous rint(Ambiguous){ return Ambiguous(); } +Ambiguous round(Ambiguous){ return Ambiguous(); } +Ambiguous scalbln(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous scalbn(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous tgamma(Ambiguous){ return Ambiguous(); } +Ambiguous trunc(Ambiguous){ return Ambiguous(); } + +void test_abs() +{ + static_assert((std::is_same<decltype(std::abs((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::abs((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::abs((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(abs(Ambiguous())), Ambiguous>::value), ""); + assert(std::abs(-1.) == 1); +} + +void test_acos() +{ + static_assert((std::is_same<decltype(std::acos((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::acos((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acos((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::acosf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::acosl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(acos(Ambiguous())), Ambiguous>::value), ""); + assert(std::acos(1) == 0); +} + +void test_asin() +{ + static_assert((std::is_same<decltype(std::asin((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::asin((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asin((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::asinf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::asinl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(asin(Ambiguous())), Ambiguous>::value), ""); + assert(std::asin(0) == 0); +} + +void test_atan() +{ + static_assert((std::is_same<decltype(std::atan((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atan((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atanf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atanl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(atan(Ambiguous())), Ambiguous>::value), ""); + assert(std::atan(0) == 0); +} + +void test_atan2() +{ + static_assert((std::is_same<decltype(std::atan2((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atan2((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2f(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atan2l(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atan2((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(atan2(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::atan2(0,1) == 0); +} + +void test_ceil() +{ + static_assert((std::is_same<decltype(std::ceil((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::ceil((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::ceil((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::ceilf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::ceill(0)), long double>::value), ""); + static_assert((std::is_same<decltype(ceil(Ambiguous())), Ambiguous>::value), ""); + assert(std::ceil(0) == 0); +} + +void test_cos() +{ + static_assert((std::is_same<decltype(std::cos((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::cos((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cos((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::cosf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::cosl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(cos(Ambiguous())), Ambiguous>::value), ""); + assert(std::cos(0) == 1); +} + +void test_cosh() +{ + static_assert((std::is_same<decltype(std::cosh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::cosh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cosh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::coshf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::coshl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(cosh(Ambiguous())), Ambiguous>::value), ""); + assert(std::cosh(0) == 1); +} + +void test_exp() +{ + static_assert((std::is_same<decltype(std::exp((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::exp((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::expf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::expl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(exp(Ambiguous())), Ambiguous>::value), ""); + assert(std::exp(0) == 1); +} + +void test_fabs() +{ + static_assert((std::is_same<decltype(std::fabs((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fabs((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fabs((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fabsf(0.0f)), float>::value), ""); + static_assert((std::is_same<decltype(std::fabsl(0.0L)), long double>::value), ""); + static_assert((std::is_same<decltype(fabs(Ambiguous())), Ambiguous>::value), ""); + assert(std::fabs(-1) == 1); +} + +void test_floor() +{ + static_assert((std::is_same<decltype(std::floor((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::floor((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::floor((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::floorf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::floorl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(floor(Ambiguous())), Ambiguous>::value), ""); + assert(std::floor(1) == 1); +} + +void test_fmod() +{ + static_assert((std::is_same<decltype(std::fmod((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmod((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmodf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmodl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmod((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(fmod(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::fmod(1.5,1) == .5); +} + +void test_frexp() +{ + int ip; + static_assert((std::is_same<decltype(std::frexp((float)0, &ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::frexp((bool)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((unsigned short)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((int)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((unsigned int)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((unsigned long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((long long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((unsigned long long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((double)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::frexp((long double)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::frexpf(0, &ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::frexpl(0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(frexp(Ambiguous(), &ip)), Ambiguous>::value), ""); + assert(std::frexp(0, &ip) == 0); +} + +void test_ldexp() +{ + int ip = 1; + static_assert((std::is_same<decltype(std::ldexp((float)0, ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((bool)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((unsigned short)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((int)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((unsigned int)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((long)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((unsigned long)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((long long)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((unsigned long long)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((double)0, ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::ldexp((long double)0, ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::ldexpf(0, ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::ldexpl(0, ip)), long double>::value), ""); + static_assert((std::is_same<decltype(ldexp(Ambiguous(), ip)), Ambiguous>::value), ""); + assert(std::ldexp(1, ip) == 2); +} + +void test_log() +{ + static_assert((std::is_same<decltype(std::log((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::logf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::logl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(log(Ambiguous())), Ambiguous>::value), ""); + assert(std::log(1) == 0); +} + +void test_log10() +{ + static_assert((std::is_same<decltype(std::log10((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log10((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log10((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::log10f(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log10l(0)), long double>::value), ""); + static_assert((std::is_same<decltype(log10(Ambiguous())), Ambiguous>::value), ""); + assert(std::log10(1) == 0); +} + +void test_modf() +{ + static_assert((std::is_same<decltype(std::modf((float)0, (float*)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::modf((double)0, (double*)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::modf((long double)0, (long double*)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::modff(0, (float*)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::modfl(0, (long double*)0)), long double>::value), ""); + static_assert((std::is_same<decltype(modf(Ambiguous(), (Ambiguous*)0)), Ambiguous>::value), ""); + double i; + assert(std::modf(1., &i) == 0); +} + +void test_pow() +{ + static_assert((std::is_same<decltype(std::pow((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::pow((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::pow((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::pow((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::pow((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::pow((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::pow((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::powf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::powl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::pow((int)0, (int)0)), double>::value), ""); +// static_assert((std::is_same<decltype(std::pow(Value<int>(), (int)0)), double>::value), ""); +// static_assert((std::is_same<decltype(std::pow(Value<long double>(), (float)0)), long double>::value), ""); +// static_assert((std::is_same<decltype(std::pow((float) 0, Value<float>())), float>::value), ""); + static_assert((std::is_same<decltype(pow(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::pow(1,1) == 1); +// assert(std::pow(Value<int,1>(), Value<float,1>()) == 1); +// assert(std::pow(1.0f, Value<double,1>()) == 1); +// assert(std::pow(1.0, Value<int,1>()) == 1); +// assert(std::pow(Value<long double,1>(), 1LL) == 1); +} + +void test_sin() +{ + static_assert((std::is_same<decltype(std::sin((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sin((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sin((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::sinf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sinl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(sin(Ambiguous())), Ambiguous>::value), ""); + assert(std::sin(0) == 0); +} + +void test_sinh() +{ + static_assert((std::is_same<decltype(std::sinh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sinh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sinh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::sinhf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sinhl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(sinh(Ambiguous())), Ambiguous>::value), ""); + assert(std::sinh(0) == 0); +} + +void test_sqrt() +{ + static_assert((std::is_same<decltype(std::sqrt((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::sqrt((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::sqrtf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::sqrtl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(sqrt(Ambiguous())), Ambiguous>::value), ""); + assert(std::sqrt(4) == 2); +} + +void test_tan() +{ + static_assert((std::is_same<decltype(std::tan((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tan((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tan((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::tanf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tanl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(tan(Ambiguous())), Ambiguous>::value), ""); + assert(std::tan(0) == 0); +} + +void test_tanh() +{ + static_assert((std::is_same<decltype(std::tanh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tanh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tanh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::tanhf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tanhl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(tanh(Ambiguous())), Ambiguous>::value), ""); + assert(std::tanh(0) == 0); +} + +void test_signbit() +{ +#ifdef signbit +#error signbit defined +#endif + static_assert((std::is_same<decltype(std::signbit((float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::signbit((double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::signbit(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::signbit((long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(signbit(Ambiguous())), Ambiguous>::value), ""); + assert(std::signbit(-1.0) == true); +} + +void test_fpclassify() +{ +#ifdef fpclassify +#error fpclassify defined +#endif + static_assert((std::is_same<decltype(std::fpclassify((float)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fpclassify((double)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fpclassify(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), ""); + static_assert((std::is_same<decltype(fpclassify(Ambiguous())), Ambiguous>::value), ""); + assert(std::fpclassify(-1.0) == FP_NORMAL); +} + +void test_isfinite() +{ +#ifdef isfinite +#error isfinite defined +#endif + static_assert((std::is_same<decltype(std::isfinite((float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isfinite((double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isfinite(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isfinite((long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isfinite(Ambiguous())), Ambiguous>::value), ""); + assert(std::isfinite(-1.0) == true); +} + +void test_isnormal() +{ +#ifdef isnormal +#error isnormal defined +#endif + static_assert((std::is_same<decltype(std::isnormal((float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnormal((double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnormal(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnormal((long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isnormal(Ambiguous())), Ambiguous>::value), ""); + assert(std::isnormal(-1.0) == true); +} + +void test_isgreater() +{ +#ifdef isgreater +#error isgreater defined +#endif + static_assert((std::is_same<decltype(std::isgreater((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreater((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isgreater(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::isgreater(-1.0, 0.F) == false); +} + +void test_isgreaterequal() +{ +#ifdef isgreaterequal +#error isgreaterequal defined +#endif + static_assert((std::is_same<decltype(std::isgreaterequal((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isgreaterequal((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isgreaterequal(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::isgreaterequal(-1.0, 0.F) == false); +} + +void test_isless() +{ +#ifdef isless +#error isless defined +#endif + static_assert((std::is_same<decltype(std::isless((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isless((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isless(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::isless(-1.0, 0.F) == true); +} + +void test_islessequal() +{ +#ifdef islessequal +#error islessequal defined +#endif + static_assert((std::is_same<decltype(std::islessequal((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessequal((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(islessequal(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::islessequal(-1.0, 0.F) == true); +} + +void test_islessgreater() +{ +#ifdef islessgreater +#error islessgreater defined +#endif + static_assert((std::is_same<decltype(std::islessgreater((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::islessgreater((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(islessgreater(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::islessgreater(-1.0, 0.F) == true); +} + +void test_isunordered() +{ +#ifdef isunordered +#error isunordered defined +#endif + static_assert((std::is_same<decltype(std::isunordered((float)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((float)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((float)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered(0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((long double)0, (float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((long double)0, (double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isunordered((long double)0, (long double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(isunordered(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::isunordered(-1.0, 0.F) == false); +} + +void test_acosh() +{ + static_assert((std::is_same<decltype(std::acosh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::acosh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::acosh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::acoshf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::acoshl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(acosh(Ambiguous())), Ambiguous>::value), ""); + assert(std::acosh(1) == 0); +} + +void test_asinh() +{ + static_assert((std::is_same<decltype(std::asinh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::asinh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::asinh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::asinhf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::asinhl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(asinh(Ambiguous())), Ambiguous>::value), ""); + assert(std::asinh(0) == 0); +} + +void test_atanh() +{ + static_assert((std::is_same<decltype(std::atanh((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atanh((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::atanh((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::atanhf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::atanhl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(atanh(Ambiguous())), Ambiguous>::value), ""); + assert(std::atanh(0) == 0); +} + +void test_cbrt() +{ + static_assert((std::is_same<decltype(std::cbrt((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::cbrt((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::cbrtf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::cbrtl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(cbrt(Ambiguous())), Ambiguous>::value), ""); + assert(std::cbrt(1) == 1); +} + +void test_copysign() +{ + static_assert((std::is_same<decltype(std::copysign((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::copysign((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysignf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::copysignl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::copysign((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(copysign(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::copysign(1,1) == 1); +} + +void test_erf() +{ + static_assert((std::is_same<decltype(std::erf((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::erf((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erf((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::erff(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::erfl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(erf(Ambiguous())), Ambiguous>::value), ""); + assert(std::erf(0) == 0); +} + +void test_erfc() +{ + static_assert((std::is_same<decltype(std::erfc((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::erfc((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::erfc((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::erfcf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::erfcl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(erfc(Ambiguous())), Ambiguous>::value), ""); + assert(std::erfc(0) == 1); +} + +void test_exp2() +{ + static_assert((std::is_same<decltype(std::exp2((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::exp2((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::exp2((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::exp2f(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::exp2l(0)), long double>::value), ""); + static_assert((std::is_same<decltype(exp2(Ambiguous())), Ambiguous>::value), ""); + assert(std::exp2(1) == 2); +} + +void test_expm1() +{ + static_assert((std::is_same<decltype(std::expm1((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::expm1((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::expm1((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::expm1f(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::expm1l(0)), long double>::value), ""); + static_assert((std::is_same<decltype(expm1(Ambiguous())), Ambiguous>::value), ""); + assert(std::expm1(0) == 0); +} + +void test_fdim() +{ + static_assert((std::is_same<decltype(std::fdim((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fdim((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdimf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fdiml(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fdim((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(fdim(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::fdim(1,0) == 1); +} + +void test_fma() +{ + static_assert((std::is_same<decltype(std::fma((bool)0, (float)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((char)0, (float)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((unsigned)0, (float)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (int)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (long)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (float)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((float)0, (float)0, (float)0)), float>::value), ""); + + static_assert((std::is_same<decltype(std::fma((bool)0, (double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((char)0, (double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((unsigned)0, (double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (int)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (long)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (double)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (double)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (double)0, (double)0)), double>::value), ""); + + static_assert((std::is_same<decltype(std::fma((bool)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((char)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((unsigned)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((long double)0, (int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((long double)0, (long)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((long double)0, (long double)0, (unsigned long long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((long double)0, (long double)0, (float)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((double)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fma((long double)0, (long double)0, (long double)0)), long double>::value), ""); + + static_assert((std::is_same<decltype(std::fmaf(0,0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmal(0,0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(fma(Ambiguous(), Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::fma(1,1,1) == 2); +} + +void test_fmax() +{ + static_assert((std::is_same<decltype(std::fmax((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmax((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmaxf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmaxl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmax((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(fmax(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::fmax(1,0) == 1); +} + +void test_fmin() +{ + static_assert((std::is_same<decltype(std::fmin((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fmin((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fminf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::fminl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::fmin((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(fmin(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::fmin(1,0) == 0); +} + +void test_hypot() +{ + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::hypot((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypotf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::hypotl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::hypot(3,4) == 5); +} + +void test_ilogb() +{ + static_assert((std::is_same<decltype(std::ilogb((float)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((bool)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((unsigned short)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((int)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((unsigned int)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((long)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((unsigned long)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((long long)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((unsigned long long)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((double)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogb((long double)0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogbf(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::ilogbl(0)), int>::value), ""); + static_assert((std::is_same<decltype(ilogb(Ambiguous())), Ambiguous>::value), ""); + assert(std::ilogb(1) == 0); +} + +void test_lgamma() +{ + static_assert((std::is_same<decltype(std::lgamma((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::lgamma((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::lgammaf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::lgammal(0)), long double>::value), ""); + static_assert((std::is_same<decltype(lgamma(Ambiguous())), Ambiguous>::value), ""); + assert(std::lgamma(1) == 0); +} + +void test_llrint() +{ + static_assert((std::is_same<decltype(std::llrint((float)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((bool)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((unsigned short)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((int)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((unsigned int)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((unsigned long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((long long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((unsigned long long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((double)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrint((long double)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrintf(0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llrintl(0)), long long>::value), ""); + static_assert((std::is_same<decltype(llrint(Ambiguous())), Ambiguous>::value), ""); + assert(std::llrint(1) == 1LL); +} + +void test_llround() +{ + static_assert((std::is_same<decltype(std::llround((float)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((bool)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((unsigned short)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((int)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((unsigned int)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((unsigned long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((long long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((unsigned long long)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((double)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llround((long double)0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llroundf(0)), long long>::value), ""); + static_assert((std::is_same<decltype(std::llroundl(0)), long long>::value), ""); + static_assert((std::is_same<decltype(llround(Ambiguous())), Ambiguous>::value), ""); + assert(std::llround(1) == 1LL); +} + +void test_log1p() +{ + static_assert((std::is_same<decltype(std::log1p((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log1p((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log1p((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::log1pf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log1pl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(log1p(Ambiguous())), Ambiguous>::value), ""); + assert(std::log1p(0) == 0); +} + +void test_log2() +{ + static_assert((std::is_same<decltype(std::log2((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log2((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::log2((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::log2f(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::log2l(0)), long double>::value), ""); + static_assert((std::is_same<decltype(log2(Ambiguous())), Ambiguous>::value), ""); + assert(std::log2(1) == 0); +} + +void test_logb() +{ + static_assert((std::is_same<decltype(std::logb((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::logb((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::logb((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::logbf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::logbl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(logb(Ambiguous())), Ambiguous>::value), ""); + assert(std::logb(1) == 0); +} + +void test_lrint() +{ + static_assert((std::is_same<decltype(std::lrint((float)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((bool)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((unsigned short)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((int)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((unsigned int)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((unsigned long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((long long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((unsigned long long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((double)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrint((long double)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrintf(0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lrintl(0)), long>::value), ""); + static_assert((std::is_same<decltype(lrint(Ambiguous())), Ambiguous>::value), ""); + assert(std::lrint(1) == 1L); +} + +void test_lround() +{ + static_assert((std::is_same<decltype(std::lround((float)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((bool)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((unsigned short)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((int)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((unsigned int)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((unsigned long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((long long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((unsigned long long)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((double)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lround((long double)0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lroundf(0)), long>::value), ""); + static_assert((std::is_same<decltype(std::lroundl(0)), long>::value), ""); + static_assert((std::is_same<decltype(lround(Ambiguous())), Ambiguous>::value), ""); + assert(std::lround(1) == 1L); +} + +void test_nan() +{ + static_assert((std::is_same<decltype(std::nan("")), double>::value), ""); + static_assert((std::is_same<decltype(std::nanf("")), float>::value), ""); + static_assert((std::is_same<decltype(std::nanl("")), long double>::value), ""); +} + +void test_nearbyint() +{ + static_assert((std::is_same<decltype(std::nearbyint((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyint((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nearbyintf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nearbyintl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(nearbyint(Ambiguous())), Ambiguous>::value), ""); + assert(std::nearbyint(1) == 1); +} + +void test_nextafter() +{ + static_assert((std::is_same<decltype(std::nextafter((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafterf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nextafterl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nextafter((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(nextafter(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::nextafter(0,1) == hexfloat<double>(0x1, 0, -1074)); +} + +void test_nexttoward() +{ + static_assert((std::is_same<decltype(std::nexttoward((float)0, (long double)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((bool)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((unsigned short)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((int)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((unsigned int)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((long)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((unsigned long)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((long long)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((unsigned long long)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((double)0, (long double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::nexttoward((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::nexttowardf(0, (long double)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::nexttowardl(0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(nexttoward(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::nexttoward(0, 1) == hexfloat<double>(0x1, 0, -1074)); +} + +void test_remainder() +{ + static_assert((std::is_same<decltype(std::remainder((float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::remainder((bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainderf(0,0)), float>::value), ""); + static_assert((std::is_same<decltype(std::remainderl(0,0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remainder((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(remainder(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::remainder(0.5,1) == 0.5); +} + +void test_remquo() +{ + int ip; + static_assert((std::is_same<decltype(std::remquo((float)0, (float)0, &ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::remquo((bool)0, (float)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((unsigned short)0, (double)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((int)0, (long double)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((float)0, (unsigned int)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((double)0, (long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((long double)0, (unsigned long)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((int)0, (long long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((int)0, (unsigned long long)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((double)0, (double)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((long double)0, (long double)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((float)0, (double)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((float)0, (long double)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((double)0, (long double)0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquof(0,0, &ip)), float>::value), ""); + static_assert((std::is_same<decltype(std::remquol(0,0, &ip)), long double>::value), ""); + static_assert((std::is_same<decltype(std::remquo((int)0, (int)0, &ip)), double>::value), ""); + static_assert((std::is_same<decltype(remquo(Ambiguous(), Ambiguous(), &ip)), Ambiguous>::value), ""); + assert(std::remquo(0.5,1, &ip) == 0.5); +} + +void test_rint() +{ + static_assert((std::is_same<decltype(std::rint((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::rint((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::rint((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::rintf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::rintl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(rint(Ambiguous())), Ambiguous>::value), ""); + assert(std::rint(1) == 1); +} + +void test_round() +{ + static_assert((std::is_same<decltype(std::round((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::round((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::round((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::roundf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::roundl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(round(Ambiguous())), Ambiguous>::value), ""); + assert(std::round(1) == 1); +} + +void test_scalbln() +{ + static_assert((std::is_same<decltype(std::scalbln((float)0, (long)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((bool)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((unsigned short)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((int)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((unsigned int)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((long)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((unsigned long)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((long long)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((unsigned long long)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbln((long double)0, (long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::scalblnf(0, (long)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::scalblnl(0, (long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(scalbln(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::scalbln(1, 1) == 2); +} + +void test_scalbn() +{ + static_assert((std::is_same<decltype(std::scalbn((float)0, (int)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((bool)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((unsigned short)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((unsigned int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((long)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((unsigned long)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((long long)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((unsigned long long)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((double)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::scalbn((long double)0, (int)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::scalbnf(0, (int)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::scalbnl(0, (int)0)), long double>::value), ""); + static_assert((std::is_same<decltype(scalbn(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + assert(std::scalbn(1, 1) == 2); +} + +void test_tgamma() +{ + static_assert((std::is_same<decltype(std::tgamma((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::tgamma((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::tgammaf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::tgammal(0)), long double>::value), ""); + static_assert((std::is_same<decltype(tgamma(Ambiguous())), Ambiguous>::value), ""); + assert(std::tgamma(1) == 1); +} + +void test_trunc() +{ + static_assert((std::is_same<decltype(std::trunc((float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::trunc((bool)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((unsigned short)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((unsigned long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::trunc((long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::truncf(0)), float>::value), ""); + static_assert((std::is_same<decltype(std::truncl(0)), long double>::value), ""); + static_assert((std::is_same<decltype(trunc(Ambiguous())), Ambiguous>::value), ""); + assert(std::trunc(1) == 1); +} + +int main() +{ + test_abs(); + test_acos(); + test_asin(); + test_atan(); + test_atan2(); + test_ceil(); + test_cos(); + test_cosh(); + test_exp(); + test_fabs(); + test_floor(); + test_fmod(); + test_frexp(); + test_ldexp(); + test_log(); + test_log10(); + test_modf(); + test_pow(); + test_sin(); + test_sinh(); + test_sqrt(); + test_tan(); + test_tanh(); + test_signbit(); + test_fpclassify(); + test_isfinite(); + test_isnormal(); + test_isgreater(); + test_isgreaterequal(); + test_isless(); + test_islessequal(); + test_islessgreater(); + test_isunordered(); + test_acosh(); + test_asinh(); + test_atanh(); + test_cbrt(); + test_copysign(); + test_erf(); + test_erfc(); + test_exp2(); + test_expm1(); + test_fdim(); + test_fma(); + test_fmax(); + test_fmin(); + test_hypot(); + test_ilogb(); + test_lgamma(); + test_llrint(); + test_llround(); + test_log1p(); + test_log2(); + test_logb(); + test_lrint(); + test_lround(); + test_nan(); + test_nearbyint(); + test_nextafter(); + test_nexttoward(); + test_remainder(); + test_remquo(); + test_rint(); + test_round(); + test_scalbln(); + test_scalbn(); + test_tgamma(); + test_trunc(); +} diff --git a/test/std/numerics/c.math/cmath_isinf.pass.cpp b/test/std/numerics/c.math/cmath_isinf.pass.cpp new file mode 100644 index 000000000000..6cde04d9bc86 --- /dev/null +++ b/test/std/numerics/c.math/cmath_isinf.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <cmath> + +// isinf + +// XFAIL: linux + +#include <cmath> +#include <type_traits> +#include <cassert> + +int main() +{ +#ifdef isinf +#error isinf defined +#endif + static_assert((std::is_same<decltype(std::isinf((float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isinf((double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isinf(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isinf((long double)0)), bool>::value), ""); + assert(std::isinf(-1.0) == false); +}
\ No newline at end of file diff --git a/test/std/numerics/c.math/cmath_isnan.pass.cpp b/test/std/numerics/c.math/cmath_isnan.pass.cpp new file mode 100644 index 000000000000..7b33b9647052 --- /dev/null +++ b/test/std/numerics/c.math/cmath_isnan.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <cmath> + +// isnan + +// XFAIL: linux + +#include <cmath> +#include <type_traits> +#include <cassert> + +int main() +{ +#ifdef isnan +#error isnan defined +#endif + static_assert((std::is_same<decltype(std::isnan((float)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnan((double)0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnan(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnan((long double)0)), bool>::value), ""); + assert(std::isnan(-1.0) == false); +} diff --git a/test/std/numerics/c.math/ctgmath.pass.cpp b/test/std/numerics/c.math/ctgmath.pass.cpp new file mode 100644 index 000000000000..278217e04840 --- /dev/null +++ b/test/std/numerics/c.math/ctgmath.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ctgmath> + +#include <ctgmath> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ + std::complex<double> cd; + double x = std::sin(0); +} diff --git a/test/std/numerics/c.math/tgmath_h.pass.cpp b/test/std/numerics/c.math/tgmath_h.pass.cpp new file mode 100644 index 000000000000..23143c7140a6 --- /dev/null +++ b/test/std/numerics/c.math/tgmath_h.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tgmath.h> + +#include <tgmath.h> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/c.math/version_cmath.pass.cpp b/test/std/numerics/c.math/version_cmath.pass.cpp new file mode 100644 index 000000000000..1249a902e7af --- /dev/null +++ b/test/std/numerics/c.math/version_cmath.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <cmath> + +#include <cmath> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/cfenv/cfenv.syn/cfenv.pass.cpp b/test/std/numerics/cfenv/cfenv.syn/cfenv.pass.cpp new file mode 100644 index 000000000000..fcf075a36e1a --- /dev/null +++ b/test/std/numerics/cfenv/cfenv.syn/cfenv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: newlib + +// <cfenv> + +#include <cfenv> +#include <type_traits> + +#ifndef FE_DIVBYZERO +#error FE_DIVBYZERO not defined +#endif + +#ifndef FE_INEXACT +#error FE_INEXACT not defined +#endif + +#ifndef FE_INVALID +#error FE_INVALID not defined +#endif + +#ifndef FE_OVERFLOW +#error FE_OVERFLOW not defined +#endif + +#ifndef FE_UNDERFLOW +#error FE_UNDERFLOW not defined +#endif + +#ifndef FE_ALL_EXCEPT +#error FE_ALL_EXCEPT not defined +#endif + +#ifndef FE_DOWNWARD +#error FE_DOWNWARD not defined +#endif + +#ifndef FE_TONEAREST +#error FE_TONEAREST not defined +#endif + +#ifndef FE_TOWARDZERO +#error FE_TOWARDZERO not defined +#endif + +#ifndef FE_UPWARD +#error FE_UPWARD not defined +#endif + +#ifndef FE_DFL_ENV +#error FE_DFL_ENV not defined +#endif + +int main() +{ + std::fenv_t fenv; + std::fexcept_t fex; + static_assert((std::is_same<decltype(std::feclearexcept(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fegetexceptflag(&fex, 0)), int>::value), ""); + static_assert((std::is_same<decltype(std::feraiseexcept(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fesetexceptflag(&fex, 0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fetestexcept(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fegetround()), int>::value), ""); + static_assert((std::is_same<decltype(std::fesetround(0)), int>::value), ""); + static_assert((std::is_same<decltype(std::fegetenv(&fenv)), int>::value), ""); + static_assert((std::is_same<decltype(std::feholdexcept(&fenv)), int>::value), ""); + static_assert((std::is_same<decltype(std::fesetenv(&fenv)), int>::value), ""); + static_assert((std::is_same<decltype(std::feupdateenv(&fenv)), int>::value), ""); +} diff --git a/test/std/numerics/cfenv/version.pass.cpp b/test/std/numerics/cfenv/version.pass.cpp new file mode 100644 index 000000000000..727d5bdf3994 --- /dev/null +++ b/test/std/numerics/cfenv/version.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: newlib + +// <cfenv> + +#include <cfenv> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/complex.number/cases.h b/test/std/numerics/complex.number/cases.h new file mode 100644 index 000000000000..cd6bd165a9d1 --- /dev/null +++ b/test/std/numerics/complex.number/cases.h @@ -0,0 +1,230 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// test cases + +#ifndef CASES_H +#define CASES_H + +#include <complex> +#include <cassert> + +std::complex<double> x[] = +{ + std::complex<double>( 1.e-6, 1.e-6), + std::complex<double>(-1.e-6, 1.e-6), + std::complex<double>(-1.e-6, -1.e-6), + std::complex<double>( 1.e-6, -1.e-6), + + std::complex<double>( 1.e+6, 1.e-6), + std::complex<double>(-1.e+6, 1.e-6), + std::complex<double>(-1.e+6, -1.e-6), + std::complex<double>( 1.e+6, -1.e-6), + + std::complex<double>( 1.e-6, 1.e+6), + std::complex<double>(-1.e-6, 1.e+6), + std::complex<double>(-1.e-6, -1.e+6), + std::complex<double>( 1.e-6, -1.e+6), + + std::complex<double>( 1.e+6, 1.e+6), + std::complex<double>(-1.e+6, 1.e+6), + std::complex<double>(-1.e+6, -1.e+6), + std::complex<double>( 1.e+6, -1.e+6), + + std::complex<double>(NAN, NAN), + std::complex<double>(-INFINITY, NAN), + std::complex<double>(-2, NAN), + std::complex<double>(-1, NAN), + std::complex<double>(-0.5, NAN), + std::complex<double>(-0., NAN), + std::complex<double>(+0., NAN), + std::complex<double>(0.5, NAN), + std::complex<double>(1, NAN), + std::complex<double>(2, NAN), + std::complex<double>(INFINITY, NAN), + + std::complex<double>(NAN, -INFINITY), + std::complex<double>(-INFINITY, -INFINITY), + std::complex<double>(-2, -INFINITY), + std::complex<double>(-1, -INFINITY), + std::complex<double>(-0.5, -INFINITY), + std::complex<double>(-0., -INFINITY), + std::complex<double>(+0., -INFINITY), + std::complex<double>(0.5, -INFINITY), + std::complex<double>(1, -INFINITY), + std::complex<double>(2, -INFINITY), + std::complex<double>(INFINITY, -INFINITY), + + std::complex<double>(NAN, -2), + std::complex<double>(-INFINITY, -2), + std::complex<double>(-2, -2), + std::complex<double>(-1, -2), + std::complex<double>(-0.5, -2), + std::complex<double>(-0., -2), + std::complex<double>(+0., -2), + std::complex<double>(0.5, -2), + std::complex<double>(1, -2), + std::complex<double>(2, -2), + std::complex<double>(INFINITY, -2), + + std::complex<double>(NAN, -1), + std::complex<double>(-INFINITY, -1), + std::complex<double>(-2, -1), + std::complex<double>(-1, -1), + std::complex<double>(-0.5, -1), + std::complex<double>(-0., -1), + std::complex<double>(+0., -1), + std::complex<double>(0.5, -1), + std::complex<double>(1, -1), + std::complex<double>(2, -1), + std::complex<double>(INFINITY, -1), + + std::complex<double>(NAN, -0.5), + std::complex<double>(-INFINITY, -0.5), + std::complex<double>(-2, -0.5), + std::complex<double>(-1, -0.5), + std::complex<double>(-0.5, -0.5), + std::complex<double>(-0., -0.5), + std::complex<double>(+0., -0.5), + std::complex<double>(0.5, -0.5), + std::complex<double>(1, -0.5), + std::complex<double>(2, -0.5), + std::complex<double>(INFINITY, -0.5), + + std::complex<double>(NAN, -0.), + std::complex<double>(-INFINITY, -0.), + std::complex<double>(-2, -0.), + std::complex<double>(-1, -0.), + std::complex<double>(-0.5, -0.), + std::complex<double>(-0., -0.), + std::complex<double>(+0., -0.), + std::complex<double>(0.5, -0.), + std::complex<double>(1, -0.), + std::complex<double>(2, -0.), + std::complex<double>(INFINITY, -0.), + + std::complex<double>(NAN, +0.), + std::complex<double>(-INFINITY, +0.), + std::complex<double>(-2, +0.), + std::complex<double>(-1, +0.), + std::complex<double>(-0.5, +0.), + std::complex<double>(-0., +0.), + std::complex<double>(+0., +0.), + std::complex<double>(0.5, +0.), + std::complex<double>(1, +0.), + std::complex<double>(2, +0.), + std::complex<double>(INFINITY, +0.), + + std::complex<double>(NAN, 0.5), + std::complex<double>(-INFINITY, 0.5), + std::complex<double>(-2, 0.5), + std::complex<double>(-1, 0.5), + std::complex<double>(-0.5, 0.5), + std::complex<double>(-0., 0.5), + std::complex<double>(+0., 0.5), + std::complex<double>(0.5, 0.5), + std::complex<double>(1, 0.5), + std::complex<double>(2, 0.5), + std::complex<double>(INFINITY, 0.5), + + std::complex<double>(NAN, 1), + std::complex<double>(-INFINITY, 1), + std::complex<double>(-2, 1), + std::complex<double>(-1, 1), + std::complex<double>(-0.5, 1), + std::complex<double>(-0., 1), + std::complex<double>(+0., 1), + std::complex<double>(0.5, 1), + std::complex<double>(1, 1), + std::complex<double>(2, 1), + std::complex<double>(INFINITY, 1), + + std::complex<double>(NAN, 2), + std::complex<double>(-INFINITY, 2), + std::complex<double>(-2, 2), + std::complex<double>(-1, 2), + std::complex<double>(-0.5, 2), + std::complex<double>(-0., 2), + std::complex<double>(+0., 2), + std::complex<double>(0.5, 2), + std::complex<double>(1, 2), + std::complex<double>(2, 2), + std::complex<double>(INFINITY, 2), + + std::complex<double>(NAN, INFINITY), + std::complex<double>(-INFINITY, INFINITY), + std::complex<double>(-2, INFINITY), + std::complex<double>(-1, INFINITY), + std::complex<double>(-0.5, INFINITY), + std::complex<double>(-0., INFINITY), + std::complex<double>(+0., INFINITY), + std::complex<double>(0.5, INFINITY), + std::complex<double>(1, INFINITY), + std::complex<double>(2, INFINITY), + std::complex<double>(INFINITY, INFINITY) +}; + +enum {zero, non_zero, inf, NaN, non_zero_nan}; + +template <class T> +int +classify(const std::complex<T>& x) +{ + if (x == std::complex<T>()) + return zero; + if (std::isinf(x.real()) || std::isinf(x.imag())) + return inf; + if (std::isnan(x.real()) && std::isnan(x.imag())) + return NaN; + if (std::isnan(x.real())) + { + if (x.imag() == T(0)) + return NaN; + return non_zero_nan; + } + if (std::isnan(x.imag())) + { + if (x.real() == T(0)) + return NaN; + return non_zero_nan; + } + return non_zero; +} + +inline +int +classify(double x) +{ + if (x == 0) + return zero; + if (std::isinf(x)) + return inf; + if (std::isnan(x)) + return NaN; + return non_zero; +} + +void is_about(float x, float y) +{ + assert(std::abs((x-y)/(x+y)) < 1.e-6); +} + +void is_about(double x, double y) +{ + assert(std::abs((x-y)/(x+y)) < 1.e-14); +} + +void is_about(long double x, long double y) +{ + assert(std::abs((x-y)/(x+y)) < 1.e-14); +} + +#endif // CASES_H diff --git a/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp b/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp new file mode 100644 index 000000000000..21aaa669fd43 --- /dev/null +++ b/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ccomplex> + +#include <ccomplex> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ + std::complex<double> d; +} diff --git a/test/std/numerics/complex.number/cmplx.over/arg.pass.cpp b/test/std/numerics/complex.number/cmplx.over/arg.pass.cpp new file mode 100644 index 000000000000..978c6255ac38 --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/arg.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<Arithmetic T> +// T +// arg(T x); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::arg(x)), double>::value), ""); + assert(std::arg(x) == arg(std::complex<double>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::arg(x)), T>::value), ""); + assert(std::arg(x) == arg(std::complex<T>(x, 0))); +} + +template <class T> +void +test() +{ + test<T>(0); + test<T>(1); + test<T>(10); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/conj.pass.cpp b/test/std/numerics/complex.number/cmplx.over/conj.pass.cpp new file mode 100644 index 000000000000..6adbf21ec26f --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/conj.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> complex<T> conj(const complex<T>&); +// complex<long double> conj(long double); +// complex<double> conj(double); +// template<Integral T> complex<double> conj(T); +// complex<float> conj(float); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::conj(x)), std::complex<double> >::value), ""); + assert(std::conj(x) == conj(std::complex<double>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), ""); + assert(std::conj(x) == conj(std::complex<T>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<!std::is_integral<T>::value && + !std::is_floating_point<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), ""); + assert(std::conj(x) == conj(std::complex<T>(x, 0))); +} + +template <class T> +void +test() +{ + test<T>(0); + test<T>(1); + test<T>(10); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/imag.pass.cpp b/test/std/numerics/complex.number/cmplx.over/imag.pass.cpp new file mode 100644 index 000000000000..30c95c3c88d9 --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/imag.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<Arithmetic T> +// T +// imag(const T& x); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T, int x> +void +test(typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::imag(T(x))), double>::value), ""); + assert(std::imag(x) == 0); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::imag(val) == 0, ""); + constexpr std::complex<T> t{val, val}; + static_assert(t.imag() == x, "" ); +#endif +} + +template <class T, int x> +void +test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::imag(T(x))), T>::value), ""); + assert(std::imag(x) == 0); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::imag(val) == 0, ""); + constexpr std::complex<T> t{val, val}; + static_assert(t.imag() == x, "" ); +#endif +} + +template <class T> +void +test() +{ + test<T, 0>(); + test<T, 1>(); + test<T, 10>(); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/norm.pass.cpp b/test/std/numerics/complex.number/cmplx.over/norm.pass.cpp new file mode 100644 index 000000000000..badd5c0cc85f --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/norm.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<Arithmetic T> +// T +// norm(T x); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::norm(x)), double>::value), ""); + assert(std::norm(x) == norm(std::complex<double>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::norm(x)), T>::value), ""); + assert(std::norm(x) == norm(std::complex<T>(x, 0))); +} + +template <class T> +void +test() +{ + test<T>(0); + test<T>(1); + test<T>(10); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/pow.pass.cpp b/test/std/numerics/complex.number/cmplx.over/pow.pass.cpp new file mode 100644 index 000000000000..3b1e9b34b35c --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/pow.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<Arithmetic T, Arithmetic U> +// complex<promote<T, U>::type> +// pow(const T& x, const complex<U>& y); + +// template<Arithmetic T, Arithmetic U> +// complex<promote<T, U>::type> +// pow(const complex<T>& x, const U& y); + +// template<Arithmetic T, Arithmetic U> +// complex<promote<T, U>::type> +// pow(const complex<T>& x, const complex<U>& y); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T> +double +promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0); + +float promote(float); +double promote(double); +long double promote(long double); + +template <class T, class U> +void +test(T x, const std::complex<U>& y) +{ + typedef decltype(promote(x)+promote(real(y))) V; + static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), ""); + assert(std::pow(x, y) == pow(std::complex<V>(x, 0), std::complex<V>(y))); +} + +template <class T, class U> +void +test(const std::complex<T>& x, U y) +{ + typedef decltype(promote(real(x))+promote(y)) V; + static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), ""); + assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y, 0))); +} + +template <class T, class U> +void +test(const std::complex<T>& x, const std::complex<U>& y) +{ + typedef decltype(promote(real(x))+promote(real(y))) V; + static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), ""); + assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y))); +} + +template <class T, class U> +void +test(typename std::enable_if<std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0) +{ + test(T(3), std::complex<U>(4, 5)); + test(std::complex<U>(3, 4), T(5)); +} + +template <class T, class U> +void +test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0) +{ + test(T(3), std::complex<U>(4, 5)); + test(std::complex<T>(3, 4), U(5)); + test(std::complex<T>(3, 4), std::complex<U>(5, 6)); +} + +int main() +{ + test<int, float>(); + test<int, double>(); + test<int, long double>(); + + test<unsigned, float>(); + test<unsigned, double>(); + test<unsigned, long double>(); + + test<long long, float>(); + test<long long, double>(); + test<long long, long double>(); + + test<float, double>(); + test<float, long double>(); + + test<double, float>(); + test<double, long double>(); + + test<long double, float>(); + test<long double, double>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/proj.pass.cpp b/test/std/numerics/complex.number/cmplx.over/proj.pass.cpp new file mode 100644 index 000000000000..60d6e7223e51 --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/proj.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> complex<T> proj(const complex<T>&); +// complex<long double> proj(long double); +// complex<double> proj(double); +// template<Integral T> complex<double> proj(T); +// complex<float> proj(float); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::proj(x)), std::complex<double> >::value), ""); + assert(std::proj(x) == proj(std::complex<double>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), ""); + assert(std::proj(x) == proj(std::complex<T>(x, 0))); +} + +template <class T> +void +test(T x, typename std::enable_if<!std::is_integral<T>::value && + !std::is_floating_point<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), ""); + assert(std::proj(x) == proj(std::complex<T>(x, 0))); +} + +template <class T> +void +test() +{ + test<T>(0); + test<T>(1); + test<T>(10); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/cmplx.over/real.pass.cpp b/test/std/numerics/complex.number/cmplx.over/real.pass.cpp new file mode 100644 index 000000000000..a5a4a35b13ca --- /dev/null +++ b/test/std/numerics/complex.number/cmplx.over/real.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<Arithmetic T> +// T +// real(const T& x); + +#include <complex> +#include <type_traits> +#include <cassert> + +#include "../cases.h" + +template <class T, int x> +void +test(typename std::enable_if<std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::real(T(x))), double>::value), ""); + assert(std::real(x) == x); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::real(val) == val, ""); + constexpr std::complex<T> t{val, val}; + static_assert(t.real() == x, "" ); +#endif +} + +template <class T, int x> +void +test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0) +{ + static_assert((std::is_same<decltype(std::real(T(x))), T>::value), ""); + assert(std::real(x) == x); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::real(val) == val, ""); + constexpr std::complex<T> t{val, val}; + static_assert(t.real() == x, "" ); +#endif +} + +template <class T> +void +test() +{ + test<T, 0>(); + test<T, 1>(); + test<T, 10>(); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test<int>(); + test<unsigned>(); + test<long long>(); +} diff --git a/test/std/numerics/complex.number/complex.literals/literals.pass.cpp b/test/std/numerics/complex.number/complex.literals/literals.pass.cpp new file mode 100644 index 000000000000..45b59914e7f8 --- /dev/null +++ b/test/std/numerics/complex.number/complex.literals/literals.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <complex> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals::complex_literals; + +// Make sure the types are right + static_assert ( std::is_same<decltype( 3.0il ), std::complex<long double>>::value, "" ); + static_assert ( std::is_same<decltype( 3il ), std::complex<long double>>::value, "" ); + static_assert ( std::is_same<decltype( 3.0i ), std::complex<double>>::value, "" ); + static_assert ( std::is_same<decltype( 3i ), std::complex<double>>::value, "" ); + static_assert ( std::is_same<decltype( 3.0if ), std::complex<float>>::value, "" ); + static_assert ( std::is_same<decltype( 3if ), std::complex<float>>::value, "" ); + + { + std::complex<long double> c1 = 3.0il; + assert ( c1 == std::complex<long double>(0, 3.0)); + auto c2 = 3il; + assert ( c1 == c2 ); + } + + { + std::complex<double> c1 = 3.0i; + assert ( c1 == std::complex<double>(0, 3.0)); + auto c2 = 3i; + assert ( c1 == c2 ); + } + + { + std::complex<float> c1 = 3.0if; + assert ( c1 == std::complex<float>(0, 3.0)); + auto c2 = 3if; + assert ( c1 == c2 ); + } + +#endif +} diff --git a/test/std/numerics/complex.number/complex.literals/literals1.fail.cpp b/test/std/numerics/complex.number/complex.literals/literals1.fail.cpp new file mode 100644 index 000000000000..0f31d595566c --- /dev/null +++ b/test/std/numerics/complex.number/complex.literals/literals1.fail.cpp @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +#include <complex> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::complex<float> foo = 1.0if; // should fail w/conversion operator not found +#else +#error +#endif +} diff --git a/test/std/numerics/complex.number/complex.literals/literals1.pass.cpp b/test/std/numerics/complex.number/complex.literals/literals1.pass.cpp new file mode 100644 index 000000000000..46903bbd565d --- /dev/null +++ b/test/std/numerics/complex.number/complex.literals/literals1.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <complex> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals; + + { + std::complex<long double> c1 = 3.0il; + assert ( c1 == std::complex<long double>(0, 3.0)); + auto c2 = 3il; + assert ( c1 == c2 ); + } + + { + std::complex<double> c1 = 3.0i; + assert ( c1 == std::complex<double>(0, 3.0)); + auto c2 = 3i; + assert ( c1 == c2 ); + } + + { + std::complex<float> c1 = 3.0if; + assert ( c1 == std::complex<float>(0, 3.0)); + auto c2 = 3if; + assert ( c1 == c2 ); + } + +#endif +} diff --git a/test/std/numerics/complex.number/complex.literals/literals2.pass.cpp b/test/std/numerics/complex.number/complex.literals/literals2.pass.cpp new file mode 100644 index 000000000000..8bd8acd981bc --- /dev/null +++ b/test/std/numerics/complex.number/complex.literals/literals2.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <complex> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std; + + { + std::complex<long double> c1 = 3.0il; + assert ( c1 == std::complex<long double>(0, 3.0)); + auto c2 = 3il; + assert ( c1 == c2 ); + } + + { + std::complex<double> c1 = 3.0i; + assert ( c1 == std::complex<double>(0, 3.0)); + auto c2 = 3i; + assert ( c1 == c2 ); + } + + { + std::complex<float> c1 = 3.0if; + assert ( c1 == std::complex<float>(0, 3.0)); + auto c2 = 3if; + assert ( c1 == c2 ); + } + +#endif +} diff --git a/test/std/numerics/complex.number/complex.member.ops/assignment_complex.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/assignment_complex.pass.cpp new file mode 100644 index 000000000000..d39429427964 --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/assignment_complex.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator=(const complex&); +// template<class X> complex& operator= (const complex<X>&); + +#include <complex> +#include <cassert> + +template <class T, class X> +void +test() +{ + std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + std::complex<T> c2(1.5, 2.5); + c = c2; + assert(c.real() == 1.5); + assert(c.imag() == 2.5); + std::complex<X> c3(3.5, -4.5); + c = c3; + assert(c.real() == 3.5); + assert(c.imag() == -4.5); +} + +int main() +{ + test<float, float>(); + test<float, double>(); + test<float, long double>(); + + test<double, float>(); + test<double, double>(); + test<double, long double>(); + + test<long double, float>(); + test<long double, double>(); + test<long double, long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/assignment_scalar.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/assignment_scalar.pass.cpp new file mode 100644 index 000000000000..87b78061e536 --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/assignment_scalar.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator= (const T&); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + c = 1.5; + assert(c.real() == 1.5); + assert(c.imag() == 0); + c = -1.5; + assert(c.real() == -1.5); + assert(c.imag() == 0); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp new file mode 100644 index 000000000000..cb285117b15d --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator/=(const complex& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c(-4, 7.5); + const std::complex<T> c2(1.5, 2.5); + assert(c.real() == -4); + assert(c.imag() == 7.5); + c /= c2; + assert(c.real() == 1.5); + assert(c.imag() == 2.5); + c /= c2; + assert(c.real() == 1); + assert(c.imag() == 0); + + std::complex<T> c3; + + c3 = c; + std::complex<int> ic (1,1); + c3 /= ic; + assert(c3.real() == 0.5); + assert(c3.imag() == -0.5); + + c3 = c; + std::complex<float> fc (1,1); + c3 /= fc; + assert(c3.real() == 0.5); + assert(c3.imag() == -0.5); + +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/divide_equal_scalar.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/divide_equal_scalar.pass.cpp new file mode 100644 index 000000000000..89907d13a45c --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/divide_equal_scalar.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator/=(const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c(1); + assert(c.real() == 1); + assert(c.imag() == 0); + c /= 0.5; + assert(c.real() == 2); + assert(c.imag() == 0); + c /= 0.5; + assert(c.real() == 4); + assert(c.imag() == 0); + c /= -0.5; + assert(c.real() == -8); + assert(c.imag() == 0); + c.imag(2); + c /= 0.5; + assert(c.real() == -16); + assert(c.imag() == 4); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp new file mode 100644 index 000000000000..67a1c7189a29 --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator-=(const complex& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c; + const std::complex<T> c2(1.5, 2.5); + assert(c.real() == 0); + assert(c.imag() == 0); + c -= c2; + assert(c.real() == -1.5); + assert(c.imag() == -2.5); + c -= c2; + assert(c.real() == -3); + assert(c.imag() == -5); + + std::complex<T> c3; + + c3 = c; + std::complex<int> ic (1,1); + c3 -= ic; + assert(c3.real() == -4); + assert(c3.imag() == -6); + + c3 = c; + std::complex<float> fc (1,1); + c3 -= fc; + assert(c3.real() == -4); + assert(c3.imag() == -6); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/minus_equal_scalar.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/minus_equal_scalar.pass.cpp new file mode 100644 index 000000000000..ddec891b25aa --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/minus_equal_scalar.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator-=(const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + c -= 1.5; + assert(c.real() == -1.5); + assert(c.imag() == 0); + c -= 1.5; + assert(c.real() == -3); + assert(c.imag() == 0); + c -= -1.5; + assert(c.real() == -1.5); + assert(c.imag() == 0); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp new file mode 100644 index 000000000000..8c16f4ced2cd --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator+=(const complex& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c; + const std::complex<T> c2(1.5, 2.5); + assert(c.real() == 0); + assert(c.imag() == 0); + c += c2; + assert(c.real() == 1.5); + assert(c.imag() == 2.5); + c += c2; + assert(c.real() == 3); + assert(c.imag() == 5); + + std::complex<T> c3; + + c3 = c; + std::complex<int> ic (1,1); + c3 += ic; + assert(c3.real() == 4); + assert(c3.imag() == 6); + + c3 = c; + std::complex<float> fc (1,1); + c3 += fc; + assert(c3.real() == 4); + assert(c3.imag() == 6); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/plus_equal_scalar.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/plus_equal_scalar.pass.cpp new file mode 100644 index 000000000000..4dd8066d1267 --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/plus_equal_scalar.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator+=(const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + c += 1.5; + assert(c.real() == 1.5); + assert(c.imag() == 0); + c += 1.5; + assert(c.real() == 3); + assert(c.imag() == 0); + c += -1.5; + assert(c.real() == 1.5); + assert(c.imag() == 0); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp new file mode 100644 index 000000000000..84d6e591306e --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator*=(const complex& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c(1); + const std::complex<T> c2(1.5, 2.5); + assert(c.real() == 1); + assert(c.imag() == 0); + c *= c2; + assert(c.real() == 1.5); + assert(c.imag() == 2.5); + c *= c2; + assert(c.real() == -4); + assert(c.imag() == 7.5); + + std::complex<T> c3; + + c3 = c; + std::complex<int> ic (1,1); + c3 *= ic; + assert(c3.real() == -11.5); + assert(c3.imag() == 3.5); + + c3 = c; + std::complex<float> fc (1,1); + c3 *= fc; + assert(c3.real() == -11.5); + assert(c3.imag() == 3.5); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.member.ops/times_equal_scalar.pass.cpp b/test/std/numerics/complex.number/complex.member.ops/times_equal_scalar.pass.cpp new file mode 100644 index 000000000000..c94baa9b6235 --- /dev/null +++ b/test/std/numerics/complex.number/complex.member.ops/times_equal_scalar.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// complex& operator*=(const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> c(1); + assert(c.real() == 1); + assert(c.imag() == 0); + c *= 1.5; + assert(c.real() == 1.5); + assert(c.imag() == 0); + c *= 1.5; + assert(c.real() == 2.25); + assert(c.imag() == 0); + c *= -1.5; + assert(c.real() == -3.375); + assert(c.imag() == 0); + c.imag(2); + c *= 1.5; + assert(c.real() == -5.0625); + assert(c.imag() == 3); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.members/construct.pass.cpp b/test/std/numerics/complex.number/complex.members/construct.pass.cpp new file mode 100644 index 000000000000..b4d870fad11e --- /dev/null +++ b/test/std/numerics/complex.number/complex.members/construct.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// constexpr complex(const T& re = T(), const T& im = T()); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + { + const std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + } + { + const std::complex<T> c = 7.5; + assert(c.real() == 7.5); + assert(c.imag() == 0); + } + { + const std::complex<T> c(8.5); + assert(c.real() == 8.5); + assert(c.imag() == 0); + } + { + const std::complex<T> c(10.5, -9.5); + assert(c.real() == 10.5); + assert(c.imag() == -9.5); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<T> c; + static_assert(c.real() == 0, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex<T> c = 7.5; + static_assert(c.real() == 7.5, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex<T> c(8.5); + static_assert(c.real() == 8.5, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex<T> c(10.5, -9.5); + static_assert(c.real() == 10.5, ""); + static_assert(c.imag() == -9.5, ""); + } +#endif +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.members/real_imag.pass.cpp b/test/std/numerics/complex.number/complex.members/real_imag.pass.cpp new file mode 100644 index 000000000000..7ead855f5c76 --- /dev/null +++ b/test/std/numerics/complex.number/complex.members/real_imag.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// void real(T val); +// void imag(T val); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + constexpr std::complex<T> c1; + static_assert(c1.real() == 0, ""); + static_assert(c1.imag() == 0, ""); + constexpr std::complex<T> c2(3); + static_assert(c2.real() == 3, ""); + static_assert(c2.imag() == 0, ""); + constexpr std::complex<T> c3(3, 4); + static_assert(c3.real() == 3, ""); + static_assert(c3.imag() == 4, ""); +#endif +} + +template <class T> +void +test() +{ + std::complex<T> c; + assert(c.real() == 0); + assert(c.imag() == 0); + c.real(3.5); + assert(c.real() == 3.5); + assert(c.imag() == 0); + c.imag(4.5); + assert(c.real() == 3.5); + assert(c.imag() == 4.5); + c.real(-4.5); + assert(c.real() == -4.5); + assert(c.imag() == 4.5); + c.imag(-5.5); + assert(c.real() == -4.5); + assert(c.imag() == -5.5); + + test_constexpr<T> (); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_constexpr<int> (); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp new file mode 100644 index 000000000000..86119678aa70 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator/(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs / rhs == x); +} + +template <class T> +void +test() +{ + std::complex<T> lhs(-4.0, 7.5); + std::complex<T> rhs(1.5, 2.5); + std::complex<T> x(1.5, 2.5); + test(lhs, rhs, x); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + for (unsigned j = 0; j < N; ++j) + { + std::complex<double> r = x[i] / x[j]; + switch (classify(x[i])) + { + case zero: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == NaN); + break; + case non_zero: + assert(classify(r) == zero); + break; + case inf: + assert(classify(r) == zero); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case non_zero: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == inf); + break; + case non_zero: + assert(classify(r) == non_zero); + break; + case inf: + assert(classify(r) == zero); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case inf: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == inf); + break; + case non_zero: + assert(classify(r) == inf); + break; + case inf: + assert(classify(r) == NaN); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case NaN: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == NaN); + break; + case non_zero: + assert(classify(r) == NaN); + break; + case inf: + assert(classify(r) == NaN); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case non_zero_nan: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == inf); + break; + case non_zero: + assert(classify(r) == NaN); + break; + case inf: + assert(classify(r) == NaN); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_divide_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_divide_scalar.pass.cpp new file mode 100644 index 000000000000..b23b381cb59d --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_divide_scalar.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator/(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x) +{ + assert(lhs / rhs == x); +} + +template <class T> +void +test() +{ + std::complex<T> lhs(-4.0, 7.5); + T rhs(2); + std::complex<T> x(-2, 3.75); + test(lhs, rhs, x); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp new file mode 100644 index 000000000000..970f021f8e63 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator==(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr std::complex<T> rhs(1.5, -2.5); + static_assert( !(lhs == rhs), ""); + } + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert(lhs == rhs, ""); + } +#endif +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(1.5, -2.5); + assert( !(lhs == rhs)); + } + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(1.5, 2.5); + assert(lhs == rhs); + } + test_constexpr<T> (); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int> (); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp new file mode 100644 index 000000000000..3c8b772bcaa5 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator==(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr T rhs(-2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex<T> lhs(1.5, 0); + constexpr T rhs(-2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr T rhs(1.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex<T> lhs(1.5, 0); + constexpr T rhs(1.5); + static_assert( (lhs == rhs), ""); + } +#endif +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + T rhs(-2.5); + assert(!(lhs == rhs)); + } + { + std::complex<T> lhs(1.5, 0); + T rhs(-2.5); + assert(!(lhs == rhs)); + } + { + std::complex<T> lhs(1.5, 2.5); + T rhs(1.5); + assert(!(lhs == rhs)); + } + { + std::complex<T> lhs(1.5, 0); + T rhs(1.5); + assert( (lhs == rhs)); + } + + test_constexpr<T> (); + } + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int> (); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_minus_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_minus_complex.pass.cpp new file mode 100644 index 000000000000..b2cddd26d8b5 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_minus_complex.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator-(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs - rhs == x); +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(3.5, 4.5); + std::complex<T> x(-2.0, -2.0); + test(lhs, rhs, x); + } + { + std::complex<T> lhs(1.5, -2.5); + std::complex<T> rhs(-3.5, 4.5); + std::complex<T> x(5.0, -7.0); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_minus_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_minus_scalar.pass.cpp new file mode 100644 index 000000000000..b630679fc985 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_minus_scalar.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator-(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x) +{ + assert(lhs - rhs == x); +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + T rhs(3.5); + std::complex<T> x(-2.0, 2.5); + test(lhs, rhs, x); + } + { + std::complex<T> lhs(1.5, -2.5); + T rhs(-3.5); + std::complex<T> x(5.0, -2.5); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp new file mode 100644 index 000000000000..ee138c1ecbcd --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator!=(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr std::complex<T> rhs(1.5, -2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert(!(lhs != rhs), "" ); + } +#endif +} + + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(1.5, -2.5); + assert(lhs != rhs); + } + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(1.5, 2.5); + assert(!(lhs != rhs)); + } + + test_constexpr<T> (); + } + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int> (); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp new file mode 100644 index 000000000000..efb1c0e872db --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator!=(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr T rhs(-2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex<T> lhs(1.5, 0); + constexpr T rhs(-2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex<T> lhs(1.5, 2.5); + constexpr T rhs(1.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex<T> lhs(1.5, 0); + constexpr T rhs(1.5); + static_assert( !(lhs != rhs), ""); + } +#endif +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + T rhs(-2.5); + assert(lhs != rhs); + } + { + std::complex<T> lhs(1.5, 0); + T rhs(-2.5); + assert(lhs != rhs); + } + { + std::complex<T> lhs(1.5, 2.5); + T rhs(1.5); + assert(lhs != rhs); + } + { + std::complex<T> lhs(1.5, 0); + T rhs(1.5); + assert( !(lhs != rhs)); + } + + test_constexpr<T> (); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int> (); + } diff --git a/test/std/numerics/complex.number/complex.ops/complex_plus_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_plus_complex.pass.cpp new file mode 100644 index 000000000000..02ed8684ea92 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_plus_complex.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator+(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs + rhs == x); +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(3.5, 4.5); + std::complex<T> x(5.0, 7.0); + test(lhs, rhs, x); + } + { + std::complex<T> lhs(1.5, -2.5); + std::complex<T> rhs(-3.5, 4.5); + std::complex<T> x(-2.0, 2.0); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_plus_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_plus_scalar.pass.cpp new file mode 100644 index 000000000000..eeec83fb09ad --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_plus_scalar.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator+(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x) +{ + assert(lhs + rhs == x); +} + +template <class T> +void +test() +{ + { + std::complex<T> lhs(1.5, 2.5); + T rhs(3.5); + std::complex<T> x(5.0, 2.5); + test(lhs, rhs, x); + } + { + std::complex<T> lhs(1.5, -2.5); + T rhs(-3.5); + std::complex<T> x(-2.0, -2.5); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp new file mode 100644 index 000000000000..565eaa5657cd --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator*(const complex<T>& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs * rhs == x); +} + +template <class T> +void +test() +{ + std::complex<T> lhs(1.5, 2.5); + std::complex<T> rhs(1.5, 2.5); + std::complex<T> x(-4.0, 7.5); + test(lhs, rhs, x); +} + +// test edges + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + for (unsigned j = 0; j < N; ++j) + { + std::complex<double> r = x[i] * x[j]; + switch (classify(x[i])) + { + case zero: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == zero); + break; + case non_zero: + assert(classify(r) == zero); + break; + case inf: + assert(classify(r) == NaN); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case non_zero: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == zero); + break; + case non_zero: + assert(classify(r) == non_zero); + break; + case inf: + assert(classify(r) == inf); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case inf: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == NaN); + break; + case non_zero: + assert(classify(r) == inf); + break; + case inf: + assert(classify(r) == inf); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == inf); + break; + } + break; + case NaN: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == NaN); + break; + case non_zero: + assert(classify(r) == NaN); + break; + case inf: + assert(classify(r) == NaN); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + case non_zero_nan: + switch (classify(x[j])) + { + case zero: + assert(classify(r) == NaN); + break; + case non_zero: + assert(classify(r) == NaN); + break; + case inf: + assert(classify(r) == inf); + break; + case NaN: + assert(classify(r) == NaN); + break; + case non_zero_nan: + assert(classify(r) == NaN); + break; + } + break; + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.ops/complex_times_scalar.pass.cpp b/test/std/numerics/complex.number/complex.ops/complex_times_scalar.pass.cpp new file mode 100644 index 000000000000..0e829a4caa68 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/complex_times_scalar.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator*(const complex<T>& lhs, const T& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x) +{ + assert(lhs * rhs == x); +} + +template <class T> +void +test() +{ + std::complex<T> lhs(1.5, 2.5); + T rhs(1.5); + std::complex<T> x(2.25, 3.75); + test(lhs, rhs, x); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_divide_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_divide_complex.pass.cpp new file mode 100644 index 000000000000..e16f02ea6db9 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_divide_complex.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator/(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs / rhs == x); +} + +template <class T> +void +test() +{ + T lhs(-8.5); + std::complex<T> rhs(1.5, 2.5); + std::complex<T> x(-1.5, 2.5); + test(lhs, rhs, x); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp new file mode 100644 index 000000000000..0cd903541fe3 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator==(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr T lhs(-2.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(-2.5); + constexpr std::complex<T> rhs(1.5, 0); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex<T> rhs(1.5, 0); + static_assert(lhs == rhs, ""); + } +#endif +} + +template <class T> +void +test() +{ + { + T lhs(-2.5); + std::complex<T> rhs(1.5, 2.5); + assert(!(lhs == rhs)); + } + { + T lhs(-2.5); + std::complex<T> rhs(1.5, 0); + assert(!(lhs == rhs)); + } + { + T lhs(1.5); + std::complex<T> rhs(1.5, 2.5); + assert(!(lhs == rhs)); + } + { + T lhs(1.5); + std::complex<T> rhs(1.5, 0); + assert(lhs == rhs); + } + + test_constexpr<T> (); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_minus_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_minus_complex.pass.cpp new file mode 100644 index 000000000000..35a3749118e9 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_minus_complex.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator-(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs - rhs == x); +} + +template <class T> +void +test() +{ + { + T lhs(1.5); + std::complex<T> rhs(3.5, 4.5); + std::complex<T> x(-2.0, -4.5); + test(lhs, rhs, x); + } + { + T lhs(1.5); + std::complex<T> rhs(-3.5, 4.5); + std::complex<T> x(5.0, -4.5); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp new file mode 100644 index 000000000000..7d6003cb891b --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// bool +// operator!=(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr T lhs(-2.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(-2.5); + constexpr std::complex<T> rhs(1.5, 0); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex<T> rhs(1.5, 2.5); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex<T> rhs(1.5, 0); + static_assert (!(lhs != rhs), ""); + } +#endif +} + +template <class T> +void +test() +{ + { + T lhs(-2.5); + std::complex<T> rhs(1.5, 2.5); + assert (lhs != rhs); + } + { + T lhs(-2.5); + std::complex<T> rhs(1.5, 0); + assert (lhs != rhs); + } + { + T lhs(1.5); + std::complex<T> rhs(1.5, 2.5); + assert (lhs != rhs); + } + { + T lhs(1.5); + std::complex<T> rhs(1.5, 0); + assert (!(lhs != rhs)); + } + + test_constexpr<T> (); + } + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +// test_constexpr<int>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_plus_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_plus_complex.pass.cpp new file mode 100644 index 000000000000..ec0de5a7f960 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_plus_complex.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator+(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs + rhs == x); +} + +template <class T> +void +test() +{ + { + T lhs(1.5); + std::complex<T> rhs(3.5, 4.5); + std::complex<T> x(5.0, 4.5); + test(lhs, rhs, x); + } + { + T lhs(1.5); + std::complex<T> rhs(-3.5, 4.5); + std::complex<T> x(-2.0, 4.5); + test(lhs, rhs, x); + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/scalar_times_complex.pass.cpp b/test/std/numerics/complex.number/complex.ops/scalar_times_complex.pass.cpp new file mode 100644 index 000000000000..ebff8b23ba6c --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/scalar_times_complex.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator*(const T& lhs, const complex<T>& rhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x) +{ + assert(lhs * rhs == x); +} + +template <class T> +void +test() +{ + T lhs(1.5); + std::complex<T> rhs(1.5, 2.5); + std::complex<T> x(2.25, 3.75); + test(lhs, rhs, x); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/stream_input.pass.cpp b/test/std/numerics/complex.number/complex.ops/stream_input.pass.cpp new file mode 100644 index 000000000000..24644e307799 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/stream_input.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T, class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, complex<T>& x); + +#include <complex> +#include <sstream> +#include <cassert> + +int main() +{ + { + std::istringstream is("5"); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5, 0)); + assert(is.eof()); + } + { + std::istringstream is(" 5 "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5, 0)); + assert(is.good()); + } + { + std::istringstream is(" 5, "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5, 0)); + assert(is.good()); + } + { + std::istringstream is(" , 5, "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(0, 0)); + assert(is.fail()); + } + { + std::istringstream is("5.5 "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5.5, 0)); + assert(is.good()); + } + { + std::istringstream is(" ( 5.5 ) "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5.5, 0)); + assert(is.good()); + } + { + std::istringstream is(" 5.5)"); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(5.5, 0)); + assert(is.good()); + } + { + std::istringstream is("(5.5 "); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(0, 0)); + assert(is.fail()); + } + { + std::istringstream is("(5.5,"); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(0, 0)); + assert(is.fail()); + } + { + std::istringstream is("( -5.5 , -6.5 )"); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(-5.5, -6.5)); + assert(!is.eof()); + } + { + std::istringstream is("(-5.5,-6.5)"); + std::complex<double> c; + is >> c; + assert(c == std::complex<double>(-5.5, -6.5)); + assert(!is.eof()); + } +} diff --git a/test/std/numerics/complex.number/complex.ops/stream_output.pass.cpp b/test/std/numerics/complex.number/complex.ops/stream_output.pass.cpp new file mode 100644 index 000000000000..edb381cf60ab --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/stream_output.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T, class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& o, const complex<T>& x); + +#include <complex> +#include <sstream> +#include <cassert> + +int main() +{ + std::complex<double> c(1, 2); + std::ostringstream os; + os << c; + assert(os.str() == "(1,2)"); +} diff --git a/test/std/numerics/complex.number/complex.ops/unary_minus.pass.cpp b/test/std/numerics/complex.number/complex.ops/unary_minus.pass.cpp new file mode 100644 index 000000000000..6a3a201ceaa8 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/unary_minus.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator-(const complex<T>& lhs); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> z(1.5, 2.5); + assert(z.real() == 1.5); + assert(z.imag() == 2.5); + std::complex<T> c = -z; + assert(c.real() == -1.5); + assert(c.imag() == -2.5); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.ops/unary_plus.pass.cpp b/test/std/numerics/complex.number/complex.ops/unary_plus.pass.cpp new file mode 100644 index 000000000000..5edaad29e682 --- /dev/null +++ b/test/std/numerics/complex.number/complex.ops/unary_plus.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// operator+(const complex<T>&); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> z(1.5, 2.5); + assert(z.real() == 1.5); + assert(z.imag() == 2.5); + std::complex<T> c = +z; + assert(c.real() == 1.5); + assert(c.imag() == 2.5); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.special/double_float_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/double_float_explicit.pass.cpp new file mode 100644 index 000000000000..e8d07ce287d0 --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/double_float_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<double> +// { +// public: +// constexpr complex(const complex<float>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<float> cd(2.5, 3.5); + std::complex<double> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<float> cd(2.5, 3.5); + constexpr std::complex<double> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/double_float_implicit.pass.cpp b/test/std/numerics/complex.number/complex.special/double_float_implicit.pass.cpp new file mode 100644 index 000000000000..298aaa3a7a8a --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/double_float_implicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<double> +// { +// public: +// constexpr complex(const complex<float>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<float> cd(2.5, 3.5); + std::complex<double> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<float> cd(2.5, 3.5); + constexpr std::complex<double> cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp new file mode 100644 index 000000000000..6ff74a2cdef3 --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<double> +// { +// public: +// explicit constexpr complex(const complex<long double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<long double> cd(2.5, 3.5); + std::complex<double> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<long double> cd(2.5, 3.5); + constexpr std::complex<double> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/double_long_double_implicit.fail.cpp b/test/std/numerics/complex.number/complex.special/double_long_double_implicit.fail.cpp new file mode 100644 index 000000000000..3866f6e33e71 --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/double_long_double_implicit.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<double> +// { +// public: +// explicit constexpr complex(const complex<long double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + const std::complex<long double> cd(2.5, 3.5); + std::complex<double> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); +} diff --git a/test/std/numerics/complex.number/complex.special/float_double_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/float_double_explicit.pass.cpp new file mode 100644 index 000000000000..77ca9d7f2aac --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/float_double_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<float> +// { +// public: +// explicit constexpr complex(const complex<double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<double> cd(2.5, 3.5); + std::complex<float> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<double> cd(2.5, 3.5); + constexpr std::complex<float> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/float_double_implicit.fail.cpp b/test/std/numerics/complex.number/complex.special/float_double_implicit.fail.cpp new file mode 100644 index 000000000000..d1519753285d --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/float_double_implicit.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<float> +// { +// public: +// explicit constexpr complex(const complex<double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + const std::complex<double> cd(2.5, 3.5); + std::complex<float> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); +} diff --git a/test/std/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp new file mode 100644 index 000000000000..4fb11b4ca27c --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<float> +// { +// public: +// explicit constexpr complex(const complex<long double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<long double> cd(2.5, 3.5); + std::complex<float> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<long double> cd(2.5, 3.5); + constexpr std::complex<float> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/float_long_double_implicit.fail.cpp b/test/std/numerics/complex.number/complex.special/float_long_double_implicit.fail.cpp new file mode 100644 index 000000000000..9401febee5d6 --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/float_long_double_implicit.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<float> +// { +// public: +// explicit constexpr complex(const complex<long double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + const std::complex<long double> cd(2.5, 3.5); + std::complex<float> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); +} diff --git a/test/std/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp new file mode 100644 index 000000000000..dd10c808b90a --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<long double> +// { +// public: +// constexpr complex(const complex<double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<double> cd(2.5, 3.5); + std::complex<long double> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<double> cd(2.5, 3.5); + constexpr std::complex<long double> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp b/test/std/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp new file mode 100644 index 000000000000..aab539407d0f --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<long double> +// { +// public: +// constexpr complex(const complex<double>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<double> cd(2.5, 3.5); + std::complex<long double> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<double> cd(2.5, 3.5); + constexpr std::complex<long double> cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp b/test/std/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp new file mode 100644 index 000000000000..a5f5101c4dc8 --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<long double> +// { +// public: +// constexpr complex(const complex<float>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<float> cd(2.5, 3.5); + std::complex<long double> cf(cd); + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<float> cd(2.5, 3.5); + constexpr std::complex<long double> cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp b/test/std/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp new file mode 100644 index 000000000000..25b93823f6ed --- /dev/null +++ b/test/std/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<> class complex<long double> +// { +// public: +// constexpr complex(const complex<float>&); +// }; + +#include <complex> +#include <cassert> + +int main() +{ + { + const std::complex<float> cd(2.5, 3.5); + std::complex<long double> cf = cd; + assert(cf.real() == cd.real()); + assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex<float> cd(2.5, 3.5); + constexpr std::complex<long double> cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif +} diff --git a/test/std/numerics/complex.number/complex.synopsis/nothing_to_do.pass.cpp b/test/std/numerics/complex.number/complex.synopsis/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/complex.number/complex.synopsis/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp new file mode 100644 index 000000000000..f8ee306d7544 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp @@ -0,0 +1,140 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// acos(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(acos(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(INFINITY, 1), std::complex<T>(0, -INFINITY)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = acos(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + is_about(r.real(), pi/2); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (x[i].real() == 0 && std::isnan(x[i].imag())) + { + is_about(r.real(), pi/2); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + is_about(r.real(), pi/2); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isfinite(x[i].real()) && x[i].real() != 0 && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag())) + { + is_about(r.real(), pi); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag())) + { + assert(r.real() == 0); + assert(!std::signbit(r.real())); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag())) + { + is_about(r.real(), 0.75 * pi); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag())) + { + is_about(r.real(), 0.25 * pi); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isinf(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) != std::signbit(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (!std::signbit(x[i].real()) && !std::signbit(x[i].imag())) + { + assert(!std::signbit(r.real())); + assert( std::signbit(r.imag())); + } + else if (std::signbit(x[i].real()) && !std::signbit(x[i].imag())) + { + assert(!std::signbit(r.real())); + assert( std::signbit(r.imag())); + } + else if (std::signbit(x[i].real()) && std::signbit(x[i].imag())) + { + assert(!std::signbit(r.real())); + assert(!std::signbit(r.imag())); + } + else if (!std::signbit(x[i].real()) && std::signbit(x[i].imag())) + { + assert(!std::signbit(r.real())); + assert(!std::signbit(r.imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp new file mode 100644 index 000000000000..88a5c798424d --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp @@ -0,0 +1,142 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// acosh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(acosh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(INFINITY, 1), std::complex<T>(INFINITY, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = acosh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(!std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (x[i].real() == 1 && x[i].imag() == 0) + { + assert(r.real() == 0); + assert(!std::signbit(r.real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi); + else + is_about(r.imag(), pi); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -0.75 * pi); + else + is_about(r.imag(), 0.75 * pi); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -0.25 * pi); + else + is_about(r.imag(), 0.25 * pi); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else + { + assert(!std::signbit(r.real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp new file mode 100644 index 000000000000..c743be6488c6 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// asin(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(asin(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = asin(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if ( x[i].real() == 0 && std::isnan(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + if (x[i].real() > 0) + is_about(r.real(), pi/2); + else + is_about(r.real(), - pi/2); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + if (std::signbit(x[i].real())) + is_about(r.real(), -pi/4); + else + is_about(r.real(), pi/4); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].real()) != std::signbit(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isinf(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp new file mode 100644 index 000000000000..027bc6a98a99 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// asinh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(asinh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = asinh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/4); + else + is_about(r.imag(), pi/4); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && x[i].imag() == 0) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp new file mode 100644 index 000000000000..69bc95240141 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// atan(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(atan(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = atan(x[i]); + std::complex<double> t1(-imag(x[i]), real(x[i])); + std::complex<double> t2 = atanh(t1); + std::complex<double> z(imag(t2), -real(t2)); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp new file mode 100644 index 000000000000..b821109b751b --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// atanh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(atanh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = atanh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if ( x[i].real() == 0 && std::isnan(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::abs(x[i].real()) == 1 && x[i].imag() == 0) + { + assert(std::isinf(r.real())); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (x[i].imag() > 0) + is_about(r.imag(), pi/2); + else + is_about(r.imag(), -pi/2); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(std::signbit(x[i].real()) == std::signbit(r.real())); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi/2); + else + is_about(r.imag(), pi/2); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else + { + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp new file mode 100644 index 000000000000..f25c967cb1a7 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// cos(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(cos(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(1, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = cos(x[i]); + std::complex<double> t1(-imag(x[i]), real(x[i])); + std::complex<double> z = cosh(t1); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp new file mode 100644 index 000000000000..acf4746389c8 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// cosh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(cosh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(1, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = cosh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(r.real() == 1); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (x[i].real() == 0 && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + } + else if (x[i].real() == 0 && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].imag() == 0) + { + assert(std::isinf(r.real())); + assert(!std::signbit(r.real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(r.real()) == std::signbit(cos(x[i].imag()))); + assert(std::isinf(r.imag())); + assert(std::signbit(r.imag()) == std::signbit(x[i].real() * sin(x[i].imag()))); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && x[i].imag() == 0) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp new file mode 100644 index 000000000000..e8b507572f1b --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// exp(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(exp(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(1, 0)); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = exp(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(r.real() == 1.0); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && x[i].imag() == 0) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(r.imag() == 0); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isnan(x[i].imag())) + { + assert(r.real() == 0); + assert(r.imag() == 0); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && x[i].imag() == 0) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isnan(x[i].real()) && x[i].imag() != 0) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].imag()) && std::abs(x[i].imag()) <= 1) + { + assert(!std::signbit(r.real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/log.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/log.pass.cpp new file mode 100644 index 000000000000..800b92474bf0 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/log.pass.cpp @@ -0,0 +1,131 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// log(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(log(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 0)); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = log(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + if (std::signbit(x[i].real())) + { + assert(std::isinf(r.real())); + assert(r.real() < 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi); + else + is_about(r.imag(), pi); + } + else + { + assert(std::isinf(r.real())); + assert(r.real() < 0); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + if (x[i].imag() > 0) + is_about(r.imag(), pi/2); + else + is_about(r.imag(), -pi/2); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real()) && r.real() > 0); + if (r.imag() > 0) + is_about(r.imag(), pi); + else + is_about(r.imag(), -pi); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real()) && r.real() > 0); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (x[i].real() == 1 && x[i].imag() == 0) + { + assert(r.real() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (x[i].real() == 0 && x[i].imag() == 1) + { + assert(r.real() == 0); + is_about(r.imag(), pi/2); + } + else if (x[i].real() == -1 && x[i].imag() == 0) + { + assert(r.real() == 0); + if (std::signbit(x[i].imag())) + is_about(r.imag(), -pi); + else + is_about(r.imag(), pi); + } + else if (x[i].real() == 0 && x[i].imag() == -1) + { + assert(r.real() == 0); + is_about(r.imag(), -pi/2); + } + else if (std::isfinite(x[i].real()) && std::isfinite(x[i].imag()) && abs(x[i]) < 1) + { + assert( std::signbit(r.real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isfinite(x[i].imag()) && abs(x[i]) > 1) + { + assert(!std::signbit(r.real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp new file mode 100644 index 000000000000..ba03ebf8ad28 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// log10(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(log10(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 0)); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = log10(x[i]); + std::complex<double> z = log(x[i])/std::log(10); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp new file mode 100644 index 000000000000..258193d257a8 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// pow(const complex<T>& x, const complex<T>& y); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& a, const std::complex<T>& b, std::complex<T> x) +{ + std::complex<T> c = pow(a, b); + is_about(real(c), real(x)); + is_about(imag(c), imag(x)); +} + +template <class T> +void +test() +{ + test(std::complex<T>(2, 3), std::complex<T>(2, 0), std::complex<T>(-5, 12)); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + for (unsigned j = 0; j < N; ++j) + { + std::complex<double> r = pow(x[i], x[j]); + std::complex<double> z = exp(x[j] * log(x[i])); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp new file mode 100644 index 000000000000..03bd10d465d1 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// pow(const complex<T>& x, const T& y); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& a, const T& b, std::complex<T> x) +{ + std::complex<T> c = pow(a, b); + is_about(real(c), real(x)); + is_about(imag(c), imag(x)); +} + +template <class T> +void +test() +{ + test(std::complex<T>(2, 3), T(2), std::complex<T>(-5, 12)); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + for (unsigned j = 0; j < N; ++j) + { + std::complex<double> r = pow(x[i], real(x[j])); + std::complex<double> z = exp(std::complex<double>(real(x[j])) * log(x[i])); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp new file mode 100644 index 000000000000..a48498cea92c --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// pow(const T& x, const complex<T>& y); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const T& a, const std::complex<T>& b, std::complex<T> x) +{ + std::complex<T> c = pow(a, b); + is_about(real(c), real(x)); + assert(std::abs(imag(c)) < 1.e-6); +} + +template <class T> +void +test() +{ + test(T(2), std::complex<T>(2), std::complex<T>(4)); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + for (unsigned j = 0; j < N; ++j) + { + std::complex<double> r = pow(real(x[i]), x[j]); + std::complex<double> z = exp(x[j] * log(std::complex<double>(real(x[i])))); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp new file mode 100644 index 000000000000..068222a27373 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// sin(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(sin(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = sin(x[i]); + std::complex<double> t1(-imag(x[i]), real(x[i])); + std::complex<double> t2 = sinh(t1); + std::complex<double> z(imag(t2), -real(t2)); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp new file mode 100644 index 000000000000..dcd30e48dff5 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// sinh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(sinh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = sinh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(r.real() == 0); + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (x[i].real() == 0 && std::isinf(x[i].imag())) + { + assert(r.real() == 0); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (x[i].real() == 0 && std::isnan(x[i].imag())) + { + assert(r.real() == 0); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].imag() == 0) + { + assert(std::isinf(r.real())); + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::signbit(r.real()) == std::signbit(x[i].real() * cos(x[i].imag()))); + assert(std::isinf(r.imag())); + assert(std::signbit(r.imag()) == std::signbit(sin(x[i].imag()))); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && x[i].imag() == 0) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp new file mode 100644 index 000000000000..69309d2b9ab1 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// sqrt(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + std::complex<T> a = sqrt(c); + is_about(real(a), real(x)); + assert(std::abs(imag(c)) < 1.e-6); +} + +template <class T> +void +test() +{ + test(std::complex<T>(64, 0), std::complex<T>(8, 0)); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = sqrt(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(!std::signbit(r.real())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isinf(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(std::isinf(r.imag())); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag())) + { + assert(r.real() == 0); + assert(!std::signbit(r.real())); + assert(std::isinf(r.imag())); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(r.imag() == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isinf(r.imag())); + } + else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isnan(x[i].imag())) + { + assert(std::isinf(r.real())); + assert(r.real() > 0); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && (std::isfinite(x[i].imag()) || std::isnan(x[i].imag()))) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::signbit(x[i].imag())) + { + assert(!std::signbit(r.real())); + assert(std::signbit(r.imag())); + } + else + { + assert(!std::signbit(r.real())); + assert(!std::signbit(r.imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp new file mode 100644 index 000000000000..881427600686 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// tan(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(tan(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); + test(std::complex<T>(10000, -10000), std::complex<T>(0, -1)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = tan(x[i]); + std::complex<double> t1(-imag(x[i]), real(x[i])); + std::complex<double> t2 = tanh(t1); + std::complex<double> z(imag(t2), -real(t2)); + if (std::isnan(real(r))) + assert(std::isnan(real(z))); + else + { + assert(real(r) == real(z)); + assert(std::signbit(real(r)) == std::signbit(real(z))); + } + if (std::isnan(imag(r))) + assert(std::isnan(imag(z))); + else + { + assert(imag(r) == imag(z)); + assert(std::signbit(imag(r)) == std::signbit(imag(z))); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp b/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp new file mode 100644 index 000000000000..907c0e64dba9 --- /dev/null +++ b/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// tanh(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& c, std::complex<T> x) +{ + assert(tanh(c) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(0, 0), std::complex<T>(0, 0)); +} + +void test_edges() +{ + typedef std::complex<double> C; + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = tanh(x[i]); + if (x[i].real() == 0 && x[i].imag() == 0) + { + assert(r.real() == 0); + assert(std::signbit(r.real()) == std::signbit(x[i].real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(r.real() == 1); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(sin(2*x[i].imag()))); + } + else if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + assert(r.real() == 1); + assert(r.imag() == 0); + } + else if (std::isinf(x[i].real()) && std::isnan(x[i].imag())) + { + assert(r.real() == 1); + assert(r.imag() == 0); + } + else if (std::isnan(x[i].real()) && x[i].imag() == 0) + { + assert(std::isnan(r.real())); + assert(r.imag() == 0); + assert(std::signbit(r.imag()) == std::signbit(x[i].imag())); + } + else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + else if (std::isnan(x[i].real()) && std::isnan(x[i].imag())) + { + assert(std::isnan(r.real())); + assert(std::isnan(r.imag())); + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp new file mode 100644 index 000000000000..5d841d6ee9f1 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// T +// abs(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test() +{ + std::complex<T> z(3, 4); + assert(abs(z) == 5); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + double r = abs(x[i]); + switch (classify(x[i])) + { + case zero: + assert(r == 0); + assert(!std::signbit(r)); + break; + case non_zero: + assert(std::isfinite(r) && r > 0); + break; + case inf: + assert(std::isinf(r) && r > 0); + break; + case NaN: + assert(std::isnan(r)); + break; + case non_zero_nan: + assert(std::isnan(r)); + break; + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp new file mode 100644 index 000000000000..a7da456b979c --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp @@ -0,0 +1,135 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// T +// arg(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test() +{ + std::complex<T> z(1, 0); + assert(arg(z) == 0); +} + +void test_edges() +{ + const double pi = std::atan2(+0., -0.); + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + double r = arg(x[i]); + if (std::isnan(x[i].real()) || std::isnan(x[i].imag())) + assert(std::isnan(r)); + else + { + switch (classify(x[i])) + { + case zero: + if (std::signbit(x[i].real())) + { + if (std::signbit(x[i].imag())) + is_about(r, -pi); + else + is_about(r, pi); + } + else + { + assert(std::signbit(x[i].imag()) == std::signbit(r)); + } + break; + case non_zero: + if (x[i].real() == 0) + { + if (x[i].imag() < 0) + is_about(r, -pi/2); + else + is_about(r, pi/2); + } + else if (x[i].imag() == 0) + { + if (x[i].real() < 0) + { + if (std::signbit(x[i].imag())) + is_about(r, -pi); + else + is_about(r, pi); + } + else + { + assert(r == 0); + assert(std::signbit(x[i].imag()) == std::signbit(r)); + } + } + else if (x[i].imag() > 0) + assert(r > 0); + else + assert(r < 0); + break; + case inf: + if (std::isinf(x[i].real()) && std::isinf(x[i].imag())) + { + if (x[i].real() < 0) + { + if (x[i].imag() > 0) + is_about(r, 0.75 * pi); + else + is_about(r, -0.75 * pi); + } + else + { + if (x[i].imag() > 0) + is_about(r, 0.25 * pi); + else + is_about(r, -0.25 * pi); + } + } + else if (std::isinf(x[i].real())) + { + if (x[i].real() < 0) + { + if (std::signbit(x[i].imag())) + is_about(r, -pi); + else + is_about(r, pi); + } + else + { + assert(r == 0); + assert(std::signbit(r) == std::signbit(x[i].imag())); + } + } + else + { + if (x[i].imag() < 0) + is_about(r, -pi/2); + else + is_about(r, pi/2); + } + break; + } + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp new file mode 100644 index 000000000000..71f276d8d470 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// conj(const complex<T>& x); + +#include <complex> +#include <cassert> + +template <class T> +void +test(const std::complex<T>& z, std::complex<T> x) +{ + assert(conj(z) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(1, 2), std::complex<T>(1, -2)); + test(std::complex<T>(-1, 2), std::complex<T>(-1, -2)); + test(std::complex<T>(1, -2), std::complex<T>(1, 2)); + test(std::complex<T>(-1, -2), std::complex<T>(-1, 2)); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp new file mode 100644 index 000000000000..fa7b7339a6d4 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// T +// imag(const complex<T>& x); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> z(1.5, 2.5); + assert(imag(z) == 2.5); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp new file mode 100644 index 000000000000..48f774e8e1c9 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// T +// norm(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test() +{ + std::complex<T> z(3, 4); + assert(norm(z) == 25); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + double r = norm(x[i]); + switch (classify(x[i])) + { + case zero: + assert(r == 0); + assert(!std::signbit(r)); + break; + case non_zero: + assert(std::isfinite(r) && r > 0); + break; + case inf: + assert(std::isinf(r) && r > 0); + break; + case NaN: + assert(std::isnan(r)); + break; + case non_zero_nan: + assert(std::isnan(r)); + break; + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp new file mode 100644 index 000000000000..a8747bd7c83b --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// polar(const T& rho, const T& theta = 0); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const T& rho, std::complex<T> x) +{ + assert(std::polar(rho) == x); +} + +template <class T> +void +test(const T& rho, const T& theta, std::complex<T> x) +{ + assert(std::polar(rho, theta) == x); +} + +template <class T> +void +test() +{ + test(T(0), std::complex<T>(0, 0)); + test(T(1), std::complex<T>(1, 0)); + test(T(100), std::complex<T>(100, 0)); + test(T(0), T(0), std::complex<T>(0, 0)); + test(T(1), T(0), std::complex<T>(1, 0)); + test(T(100), T(0), std::complex<T>(100, 0)); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + double r = real(x[i]); + double theta = imag(x[i]); + std::complex<double> z = std::polar(r, theta); + switch (classify(r)) + { + case zero: + if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN) + { + int c = classify(z); + assert(c == NaN || c == non_zero_nan); + } + else + { + assert(z == std::complex<double>()); + } + break; + case non_zero: + if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN) + { + int c = classify(z); + assert(c == NaN || c == non_zero_nan); + } + else + { + is_about(std::abs(z), r); + } + break; + case inf: + if (r < 0) + { + int c = classify(z); + assert(c == NaN || c == non_zero_nan); + } + else + { + assert(classify(z) == inf); + if (classify(theta) != NaN && classify(theta) != inf) + { + assert(classify(real(z)) != NaN); + assert(classify(imag(z)) != NaN); + } + } + break; + case NaN: + case non_zero_nan: + { + int c = classify(z); + assert(c == NaN || c == non_zero_nan); + } + break; + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp new file mode 100644 index 000000000000..10bf7f8576f6 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// complex<T> +// proj(const complex<T>& x); + +#include <complex> +#include <cassert> + +#include "../cases.h" + +template <class T> +void +test(const std::complex<T>& z, std::complex<T> x) +{ + assert(proj(z) == x); +} + +template <class T> +void +test() +{ + test(std::complex<T>(1, 2), std::complex<T>(1, 2)); + test(std::complex<T>(-1, 2), std::complex<T>(-1, 2)); + test(std::complex<T>(1, -2), std::complex<T>(1, -2)); + test(std::complex<T>(-1, -2), std::complex<T>(-1, -2)); +} + +void test_edges() +{ + const unsigned N = sizeof(x) / sizeof(x[0]); + for (unsigned i = 0; i < N; ++i) + { + std::complex<double> r = proj(x[i]); + switch (classify(x[i])) + { + case zero: + case non_zero: + assert(r == x[i]); + assert(std::signbit(real(r)) == std::signbit(real(x[i]))); + assert(std::signbit(imag(r)) == std::signbit(imag(x[i]))); + break; + case inf: + assert(std::isinf(real(r)) && real(r) > 0); + assert(imag(r) == 0); + assert(std::signbit(imag(r)) == std::signbit(imag(x[i]))); + break; + case NaN: + case non_zero_nan: + assert(classify(r) == classify(x[i])); + break; + } + } +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); + test_edges(); +} diff --git a/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp new file mode 100644 index 000000000000..fbb51f080640 --- /dev/null +++ b/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// T +// real(const complex<T>& x); + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> z(1.5, 2.5); + assert(real(z) == 1.5); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/complex/types.pass.cpp b/test/std/numerics/complex.number/complex/types.pass.cpp new file mode 100644 index 000000000000..4da9a2a90295 --- /dev/null +++ b/test/std/numerics/complex.number/complex/types.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +// template<class T> +// class complex +// { +// public: +// typedef T value_type; +// ... +// }; + +#include <complex> +#include <type_traits> + +template <class T> +void +test() +{ + typedef std::complex<T> C; + static_assert((std::is_same<typename C::value_type, T>::value), ""); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/layout.pass.cpp b/test/std/numerics/complex.number/layout.pass.cpp new file mode 100644 index 000000000000..a9f356d4a40a --- /dev/null +++ b/test/std/numerics/complex.number/layout.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +#include <complex> +#include <cassert> + +template <class T> +void +test() +{ + std::complex<T> z; + T* a = (T*)&z; + assert(0 == z.real()); + assert(0 == z.imag()); + assert(a[0] == z.real()); + assert(a[1] == z.imag()); + a[0] = 5; + a[1] = 6; + assert(a[0] == z.real()); + assert(a[1] == z.imag()); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/numerics/complex.number/version.pass.cpp b/test/std/numerics/complex.number/version.pass.cpp new file mode 100644 index 000000000000..316cfec739a9 --- /dev/null +++ b/test/std/numerics/complex.number/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <complex> + +#include <complex> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/nothing_to_do.pass.cpp b/test/std/numerics/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/class.gslice/gslice.access/tested_elsewhere.pass.cpp b/test/std/numerics/numarray/class.gslice/gslice.access/tested_elsewhere.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/class.gslice/gslice.access/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/class.gslice/gslice.cons/default.pass.cpp b/test/std/numerics/numarray/class.gslice/gslice.cons/default.pass.cpp new file mode 100644 index 000000000000..29cc34f0767a --- /dev/null +++ b/test/std/numerics/numarray/class.gslice/gslice.cons/default.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// class glice; + +// gslice(); + +#include <valarray> +#include <cassert> + +int main() +{ + std::gslice gs; + assert(gs.start() == 0); + assert(gs.size().size() == 0); + assert(gs.stride().size() == 0); +} diff --git a/test/std/numerics/numarray/class.gslice/gslice.cons/start_size_stride.pass.cpp b/test/std/numerics/numarray/class.gslice/gslice.cons/start_size_stride.pass.cpp new file mode 100644 index 000000000000..931c0d3c7bfe --- /dev/null +++ b/test/std/numerics/numarray/class.gslice/gslice.cons/start_size_stride.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// class glice; + +// gslice(size_t start, const valarray<size_t>& size, +// const valarray<size_t>& stride); + +#include <valarray> +#include <cassert> + +int main() +{ + std::size_t a1[] = {1, 2, 3}; + std::size_t a2[] = {4, 5, 6}; + std::valarray<std::size_t> size(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<std::size_t> stride(a2, sizeof(a2)/sizeof(a2[0])); + std::gslice gs(7, size, stride); + assert(gs.start() == 7); + std::valarray<std::size_t> r = gs.size(); + assert(r.size() == 3); + assert(r[0] == 1); + assert(r[1] == 2); + assert(r[2] == 3); + r = gs.stride(); + assert(r.size() == 3); + assert(r[0] == 4); + assert(r[1] == 5); + assert(r[2] == 6); +} diff --git a/test/std/numerics/numarray/class.gslice/nothing_to_do.pass.cpp b/test/std/numerics/numarray/class.gslice/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/class.gslice/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/class.slice/cons.slice/default.pass.cpp b/test/std/numerics/numarray/class.slice/cons.slice/default.pass.cpp new file mode 100644 index 000000000000..d0a6cc0d28dd --- /dev/null +++ b/test/std/numerics/numarray/class.slice/cons.slice/default.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// class slice; + +// slice(); + +#include <valarray> +#include <cassert> + +int main() +{ + std::slice s; + assert(s.start() == 0); + assert(s.size() == 0); + assert(s.stride() == 0); +} diff --git a/test/std/numerics/numarray/class.slice/cons.slice/start_size_stride.pass.cpp b/test/std/numerics/numarray/class.slice/cons.slice/start_size_stride.pass.cpp new file mode 100644 index 000000000000..84f7ed6a18e1 --- /dev/null +++ b/test/std/numerics/numarray/class.slice/cons.slice/start_size_stride.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// class slice; + +// slice(size_t start, size_t size, size_t stride); + +#include <valarray> +#include <cassert> + +int main() +{ + std::slice s(1, 3, 2); + assert(s.start() == 1); + assert(s.size() == 3); + assert(s.stride() == 2); +} diff --git a/test/std/numerics/numarray/class.slice/nothing_to_do.pass.cpp b/test/std/numerics/numarray/class.slice/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/class.slice/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/class.slice/slice.access/tested_elsewhere.pass.cpp b/test/std/numerics/numarray/class.slice/slice.access/tested_elsewhere.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/class.slice/slice.access/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/template.gslice.array/default.fail.cpp b/test/std/numerics/numarray/template.gslice.array/default.fail.cpp new file mode 100644 index 000000000000..d691cbe08a41 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/default.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// gslice_array() = delete; + +#include <valarray> +#include <type_traits> + +int main() +{ + std::gslice_array<int> gs; +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/gslice_array.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/gslice_array.pass.cpp new file mode 100644 index 000000000000..d26a7b36cade --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/gslice_array.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// const gslice_array& operator=(const gslice_array& ga) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, + -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35, + -36, -37}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + const std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] + = v2[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))]; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == -3); + assert(v1[ 4] == -4); + assert(v1[ 5] == -5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -7); + assert(v1[ 8] == -8); + assert(v1[ 9] == -9); + assert(v1[10] == 10); + assert(v1[11] == -11); + assert(v1[12] == -12); + assert(v1[13] == -13); + assert(v1[14] == 14); + assert(v1[15] == -15); + assert(v1[16] == -16); + assert(v1[17] == -17); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == -22); + assert(v1[23] == -23); + assert(v1[24] == -24); + assert(v1[25] == 25); + assert(v1[26] == -26); + assert(v1[27] == -27); + assert(v1[28] == -28); + assert(v1[29] == 29); + assert(v1[30] == -30); + assert(v1[31] == -31); + assert(v1[32] == -32); + assert(v1[33] == 33); + assert(v1[34] == -34); + assert(v1[35] == -35); + assert(v1[36] == -36); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/valarray.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/valarray.pass.cpp new file mode 100644 index 000000000000..2f960c12d6b0 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.assign/valarray.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] = v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == -1); + assert(v1[ 5] == -2); + assert(v1[ 6] == 6); + assert(v1[ 7] == -3); + assert(v1[ 8] == -4); + assert(v1[ 9] == -5); + assert(v1[10] == 10); + assert(v1[11] == -6); + assert(v1[12] == -7); + assert(v1[13] == -8); + assert(v1[14] == 14); + assert(v1[15] == -9); + assert(v1[16] == -10); + assert(v1[17] == -11); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == -12); + assert(v1[23] == -13); + assert(v1[24] == -14); + assert(v1[25] == 25); + assert(v1[26] == -15); + assert(v1[27] == -16); + assert(v1[28] == -17); + assert(v1[29] == 29); + assert(v1[30] == -18); + assert(v1[31] == -19); + assert(v1[32] == -20); + assert(v1[33] == 33); + assert(v1[34] == -21); + assert(v1[35] == -22); + assert(v1[36] == -23); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/addition.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/addition.pass.cpp new file mode 100644 index 000000000000..bd2ad7074c10 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/addition.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator+= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] += v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 3); + assert(v1[ 5] == 3); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 4); + assert(v1[ 9] == 4); + assert(v1[10] == 10); + assert(v1[11] == 5); + assert(v1[12] == 5); + assert(v1[13] == 5); + assert(v1[14] == 14); + assert(v1[15] == 6); + assert(v1[16] == 6); + assert(v1[17] == 6); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 10); + assert(v1[23] == 10); + assert(v1[24] == 10); + assert(v1[25] == 25); + assert(v1[26] == 11); + assert(v1[27] == 11); + assert(v1[28] == 11); + assert(v1[29] == 29); + assert(v1[30] == 12); + assert(v1[31] == 12); + assert(v1[32] == 12); + assert(v1[33] == 33); + assert(v1[34] == 13); + assert(v1[35] == 13); + assert(v1[36] == 13); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/and.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/and.pass.cpp new file mode 100644 index 000000000000..6875c5ea700b --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/and.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator&= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] &= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 0); + assert(v1[ 5] == 1); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 0); + assert(v1[ 9] == 0); + assert(v1[10] == 10); + assert(v1[11] == 3); + assert(v1[12] == 8); + assert(v1[13] == 9); + assert(v1[14] == 14); + assert(v1[15] == 10); + assert(v1[16] == 0); + assert(v1[17] == 0); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 4); + assert(v1[23] == 6); + assert(v1[24] == 8); + assert(v1[25] == 25); + assert(v1[26] == 16); + assert(v1[27] == 17); + assert(v1[28] == 16); + assert(v1[29] == 29); + assert(v1[30] == 18); + assert(v1[31] == 20); + assert(v1[32] == 0); + assert(v1[33] == 33); + assert(v1[34] == 2); + assert(v1[35] == 3); + assert(v1[36] == 0); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/divide.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/divide.pass.cpp new file mode 100644 index 000000000000..33a00328f34d --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/divide.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator/= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] /= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 2); + assert(v1[ 5] == 1); + assert(v1[ 6] == 6); + assert(v1[ 7] == 1); + assert(v1[ 8] == 1); + assert(v1[ 9] == 1); + assert(v1[10] == 10); + assert(v1[11] == 1); + assert(v1[12] == 1); + assert(v1[13] == 1); + assert(v1[14] == 14); + assert(v1[15] == 1); + assert(v1[16] == 1); + assert(v1[17] == 1); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 1); + assert(v1[23] == 1); + assert(v1[24] == 1); + assert(v1[25] == 25); + assert(v1[26] == 1); + assert(v1[27] == 1); + assert(v1[28] == 1); + assert(v1[29] == 29); + assert(v1[30] == 1); + assert(v1[31] == 1); + assert(v1[32] == 1); + assert(v1[33] == 33); + assert(v1[34] == 1); + assert(v1[35] == 1); + assert(v1[36] == 1); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/modulo.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/modulo.pass.cpp new file mode 100644 index 000000000000..addc43da09e0 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/modulo.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator%= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] %= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == 0); + assert(v1[ 5] == 2); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 3); + assert(v1[ 9] == 3); + assert(v1[10] == 10); + assert(v1[11] == 4); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 5); + assert(v1[17] == 5); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 9); + assert(v1[23] == 9); + assert(v1[24] == 9); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 10); + assert(v1[29] == 29); + assert(v1[30] == 11); + assert(v1[31] == 11); + assert(v1[32] == 11); + assert(v1[33] == 33); + assert(v1[34] == 12); + assert(v1[35] == 12); + assert(v1[36] == 12); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/multiply.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/multiply.pass.cpp new file mode 100644 index 000000000000..37555fdfa300 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/multiply.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator*= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] *= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 8); + assert(v1[ 5] == 15); + assert(v1[ 6] == 6); + assert(v1[ 7] == 28); + assert(v1[ 8] == 40); + assert(v1[ 9] == 54); + assert(v1[10] == 10); + assert(v1[11] == 77); + assert(v1[12] == 96); + assert(v1[13] == 117); + assert(v1[14] == 14); + assert(v1[15] == 150); + assert(v1[16] == 176); + assert(v1[17] == 204); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 286); + assert(v1[23] == 322); + assert(v1[24] == 360); + assert(v1[25] == 25); + assert(v1[26] == 416); + assert(v1[27] == 459); + assert(v1[28] == 504); + assert(v1[29] == 29); + assert(v1[30] == 570); + assert(v1[31] == 620); + assert(v1[32] == 672); + assert(v1[33] == 33); + assert(v1[34] == 748); + assert(v1[35] == 805); + assert(v1[36] == 864); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/or.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/or.pass.cpp new file mode 100644 index 000000000000..24e96e821a88 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/or.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator|= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] |= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 6); + assert(v1[ 5] == 7); + assert(v1[ 6] == 6); + assert(v1[ 7] == 7); + assert(v1[ 8] == 13); + assert(v1[ 9] == 15); + assert(v1[10] == 10); + assert(v1[11] == 15); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); + assert(v1[16] == 27); + assert(v1[17] == 29); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 31); + assert(v1[23] == 31); + assert(v1[24] == 31); + assert(v1[25] == 25); + assert(v1[26] == 26); + assert(v1[27] == 27); + assert(v1[28] == 30); + assert(v1[29] == 29); + assert(v1[30] == 31); + assert(v1[31] == 31); + assert(v1[32] == 53); + assert(v1[33] == 33); + assert(v1[34] == 54); + assert(v1[35] == 55); + assert(v1[36] == 60); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_left.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_left.pass.cpp new file mode 100644 index 000000000000..ddaf4f7ca5b8 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_left.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator<<= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] <<= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 6); + assert(v1[ 4] == 16); + assert(v1[ 5] == 40); + assert(v1[ 6] == 6); + assert(v1[ 7] == 112); + assert(v1[ 8] == 256); + assert(v1[ 9] == 576); + assert(v1[10] == 10); + assert(v1[11] == 1408); + assert(v1[12] == 3072); + assert(v1[13] == 6656); + assert(v1[14] == 14); + assert(v1[15] == 15360); + assert(v1[16] == 32768); + assert(v1[17] == 69632); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 180224); + assert(v1[23] == 376832); + assert(v1[24] == 786432); + assert(v1[25] == 25); + assert(v1[26] == 1703936); + assert(v1[27] == 3538944); + assert(v1[28] == 7340032); + assert(v1[29] == 29); + assert(v1[30] == 15728640); + assert(v1[31] == 32505856); + assert(v1[32] == 67108864); + assert(v1[33] == 33); + assert(v1[34] == 142606336); + assert(v1[35] == 293601280); + assert(v1[36] == 603979776); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_right.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_right.pass.cpp new file mode 100644 index 000000000000..4c06a29e51e6 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/shift_right.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator>>= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] >>= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 1); + assert(v1[ 5] == 0); + assert(v1[ 6] == 6); + assert(v1[ 7] == 0); + assert(v1[ 8] == 0); + assert(v1[ 9] == 0); + assert(v1[10] == 10); + assert(v1[11] == 0); + assert(v1[12] == 0); + assert(v1[13] == 0); + assert(v1[14] == 14); + assert(v1[15] == 0); + assert(v1[16] == 0); + assert(v1[17] == 0); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 0); + assert(v1[23] == 0); + assert(v1[24] == 0); + assert(v1[25] == 25); + assert(v1[26] == 0); + assert(v1[27] == 0); + assert(v1[28] == 0); + assert(v1[29] == 29); + assert(v1[30] == 0); + assert(v1[31] == 0); + assert(v1[32] == 0); + assert(v1[33] == 33); + assert(v1[34] == 0); + assert(v1[35] == 0); + assert(v1[36] == 0); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/subtraction.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/subtraction.pass.cpp new file mode 100644 index 000000000000..3feda53aef1d --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/subtraction.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator-= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] -= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 2); + assert(v1[ 5] == 2); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 3); + assert(v1[ 9] == 3); + assert(v1[10] == 10); + assert(v1[11] == 4); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 5); + assert(v1[17] == 5); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 9); + assert(v1[23] == 9); + assert(v1[24] == 9); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 10); + assert(v1[29] == 29); + assert(v1[30] == 11); + assert(v1[31] == 11); + assert(v1[32] == 11); + assert(v1[33] == 33); + assert(v1[34] == 12); + assert(v1[35] == 12); + assert(v1[36] == 12); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/xor.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/xor.pass.cpp new file mode 100644 index 000000000000..125935169e22 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.comp.assign/xor.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator^= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] ^= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 6); + assert(v1[ 5] == 6); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 13); + assert(v1[ 9] == 15); + assert(v1[10] == 10); + assert(v1[11] == 12); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 27); + assert(v1[17] == 29); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 27); + assert(v1[23] == 25); + assert(v1[24] == 23); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 14); + assert(v1[29] == 29); + assert(v1[30] == 13); + assert(v1[31] == 11); + assert(v1[32] == 53); + assert(v1[33] == 33); + assert(v1[34] == 52); + assert(v1[35] == 52); + assert(v1[36] == 60); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/gslice.array.fill/assign_value.pass.cpp b/test/std/numerics/numarray/template.gslice.array/gslice.array.fill/assign_value.pass.cpp new file mode 100644 index 000000000000..5c5591aa1093 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/gslice.array.fill/assign_value.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class gslice_array + +// void operator=(const value_type& x) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] = 51; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 51); + assert(v1[ 4] == 51); + assert(v1[ 5] == 51); + assert(v1[ 6] == 6); + assert(v1[ 7] == 51); + assert(v1[ 8] == 51); + assert(v1[ 9] == 51); + assert(v1[10] == 10); + assert(v1[11] == 51); + assert(v1[12] == 51); + assert(v1[13] == 51); + assert(v1[14] == 14); + assert(v1[15] == 51); + assert(v1[16] == 51); + assert(v1[17] == 51); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 51); + assert(v1[23] == 51); + assert(v1[24] == 51); + assert(v1[25] == 25); + assert(v1[26] == 51); + assert(v1[27] == 51); + assert(v1[28] == 51); + assert(v1[29] == 29); + assert(v1[30] == 51); + assert(v1[31] == 51); + assert(v1[32] == 51); + assert(v1[33] == 33); + assert(v1[34] == 51); + assert(v1[35] == 51); + assert(v1[36] == 51); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.gslice.array/types.pass.cpp b/test/std/numerics/numarray/template.gslice.array/types.pass.cpp new file mode 100644 index 000000000000..005d907b41c0 --- /dev/null +++ b/test/std/numerics/numarray/template.gslice.array/types.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> +// class gslice_array +// { +// public: +// typedef T value_type; + +#include <valarray> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::gslice_array<int>::value_type, int>::value), ""); +} diff --git a/test/std/numerics/numarray/template.indirect.array/default.fail.cpp b/test/std/numerics/numarray/template.indirect.array/default.fail.cpp new file mode 100644 index 000000000000..2f5e5d832835 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/default.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// indirect_array() = delete; + +#include <valarray> +#include <type_traits> + +int main() +{ + std::indirect_array<int> ia; +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/indirect_array.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/indirect_array.pass.cpp new file mode 100644 index 000000000000..9c7c816ce218 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/indirect_array.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// const indirect_array& operator=(const indirect_array& ia) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, + -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35, + -36, -37}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + std::valarray<int> v1(a1, N1); + const std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, S); + v1[ia] = v2[ia]; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == -3); + assert(v1[ 4] == -4); + assert(v1[ 5] == -5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -7); + assert(v1[ 8] == -8); + assert(v1[ 9] == -9); + assert(v1[10] == 10); + assert(v1[11] == -11); + assert(v1[12] == -12); + assert(v1[13] == -13); + assert(v1[14] == 14); + assert(v1[15] == -15); + assert(v1[16] == -16); + assert(v1[17] == -17); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == -22); + assert(v1[23] == -23); + assert(v1[24] == -24); + assert(v1[25] == 25); + assert(v1[26] == -26); + assert(v1[27] == -27); + assert(v1[28] == -28); + assert(v1[29] == 29); + assert(v1[30] == -30); + assert(v1[31] == -31); + assert(v1[32] == -32); + assert(v1[33] == 33); + assert(v1[34] == -34); + assert(v1[35] == -35); + assert(v1[36] == -36); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/valarray.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/valarray.pass.cpp new file mode 100644 index 000000000000..ad934aabcccb --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.assign/valarray.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] = v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == -1); + assert(v1[ 5] == -2); + assert(v1[ 6] == 6); + assert(v1[ 7] == -3); + assert(v1[ 8] == -4); + assert(v1[ 9] == -5); + assert(v1[10] == 10); + assert(v1[11] == -6); + assert(v1[12] == -7); + assert(v1[13] == -8); + assert(v1[14] == 14); + assert(v1[15] == -9); + assert(v1[16] == -10); + assert(v1[17] == -11); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == -12); + assert(v1[23] == -13); + assert(v1[24] == -14); + assert(v1[25] == 25); + assert(v1[26] == -15); + assert(v1[27] == -16); + assert(v1[28] == -17); + assert(v1[29] == 29); + assert(v1[30] == -18); + assert(v1[31] == -19); + assert(v1[32] == -20); + assert(v1[33] == 33); + assert(v1[34] == -21); + assert(v1[35] == -22); + assert(v1[36] == -23); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/addition.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/addition.pass.cpp new file mode 100644 index 000000000000..fa966d1b58bb --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/addition.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator+=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] += v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 3); + assert(v1[ 5] == 3); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 4); + assert(v1[ 9] == 4); + assert(v1[10] == 10); + assert(v1[11] == 5); + assert(v1[12] == 5); + assert(v1[13] == 5); + assert(v1[14] == 14); + assert(v1[15] == 6); + assert(v1[16] == 6); + assert(v1[17] == 6); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 10); + assert(v1[23] == 10); + assert(v1[24] == 10); + assert(v1[25] == 25); + assert(v1[26] == 11); + assert(v1[27] == 11); + assert(v1[28] == 11); + assert(v1[29] == 29); + assert(v1[30] == 12); + assert(v1[31] == 12); + assert(v1[32] == 12); + assert(v1[33] == 33); + assert(v1[34] == 13); + assert(v1[35] == 13); + assert(v1[36] == 13); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/and.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/and.pass.cpp new file mode 100644 index 000000000000..60f055276745 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/and.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator&=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] &= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 0); + assert(v1[ 5] == 1); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 0); + assert(v1[ 9] == 0); + assert(v1[10] == 10); + assert(v1[11] == 3); + assert(v1[12] == 8); + assert(v1[13] == 9); + assert(v1[14] == 14); + assert(v1[15] == 10); + assert(v1[16] == 0); + assert(v1[17] == 0); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 4); + assert(v1[23] == 6); + assert(v1[24] == 8); + assert(v1[25] == 25); + assert(v1[26] == 16); + assert(v1[27] == 17); + assert(v1[28] == 16); + assert(v1[29] == 29); + assert(v1[30] == 18); + assert(v1[31] == 20); + assert(v1[32] == 0); + assert(v1[33] == 33); + assert(v1[34] == 2); + assert(v1[35] == 3); + assert(v1[36] == 0); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/divide.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/divide.pass.cpp new file mode 100644 index 000000000000..11b5d83fe142 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/divide.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator/=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] /= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 2); + assert(v1[ 5] == 1); + assert(v1[ 6] == 6); + assert(v1[ 7] == 1); + assert(v1[ 8] == 1); + assert(v1[ 9] == 1); + assert(v1[10] == 10); + assert(v1[11] == 1); + assert(v1[12] == 1); + assert(v1[13] == 1); + assert(v1[14] == 14); + assert(v1[15] == 1); + assert(v1[16] == 1); + assert(v1[17] == 1); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 1); + assert(v1[23] == 1); + assert(v1[24] == 1); + assert(v1[25] == 25); + assert(v1[26] == 1); + assert(v1[27] == 1); + assert(v1[28] == 1); + assert(v1[29] == 29); + assert(v1[30] == 1); + assert(v1[31] == 1); + assert(v1[32] == 1); + assert(v1[33] == 33); + assert(v1[34] == 1); + assert(v1[35] == 1); + assert(v1[36] == 1); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/modulo.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/modulo.pass.cpp new file mode 100644 index 000000000000..4c63684ecb7f --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/modulo.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator%=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] %= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == 0); + assert(v1[ 5] == 2); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 3); + assert(v1[ 9] == 3); + assert(v1[10] == 10); + assert(v1[11] == 4); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 5); + assert(v1[17] == 5); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 9); + assert(v1[23] == 9); + assert(v1[24] == 9); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 10); + assert(v1[29] == 29); + assert(v1[30] == 11); + assert(v1[31] == 11); + assert(v1[32] == 11); + assert(v1[33] == 33); + assert(v1[34] == 12); + assert(v1[35] == 12); + assert(v1[36] == 12); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/multiply.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/multiply.pass.cpp new file mode 100644 index 000000000000..e477353107a7 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/multiply.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator*=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] *= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 8); + assert(v1[ 5] == 15); + assert(v1[ 6] == 6); + assert(v1[ 7] == 28); + assert(v1[ 8] == 40); + assert(v1[ 9] == 54); + assert(v1[10] == 10); + assert(v1[11] == 77); + assert(v1[12] == 96); + assert(v1[13] == 117); + assert(v1[14] == 14); + assert(v1[15] == 150); + assert(v1[16] == 176); + assert(v1[17] == 204); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 286); + assert(v1[23] == 322); + assert(v1[24] == 360); + assert(v1[25] == 25); + assert(v1[26] == 416); + assert(v1[27] == 459); + assert(v1[28] == 504); + assert(v1[29] == 29); + assert(v1[30] == 570); + assert(v1[31] == 620); + assert(v1[32] == 672); + assert(v1[33] == 33); + assert(v1[34] == 748); + assert(v1[35] == 805); + assert(v1[36] == 864); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/or.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/or.pass.cpp new file mode 100644 index 000000000000..b74ce8621eb3 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/or.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator|=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] |= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 6); + assert(v1[ 5] == 7); + assert(v1[ 6] == 6); + assert(v1[ 7] == 7); + assert(v1[ 8] == 13); + assert(v1[ 9] == 15); + assert(v1[10] == 10); + assert(v1[11] == 15); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); + assert(v1[16] == 27); + assert(v1[17] == 29); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 31); + assert(v1[23] == 31); + assert(v1[24] == 31); + assert(v1[25] == 25); + assert(v1[26] == 26); + assert(v1[27] == 27); + assert(v1[28] == 30); + assert(v1[29] == 29); + assert(v1[30] == 31); + assert(v1[31] == 31); + assert(v1[32] == 53); + assert(v1[33] == 33); + assert(v1[34] == 54); + assert(v1[35] == 55); + assert(v1[36] == 60); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_left.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_left.pass.cpp new file mode 100644 index 000000000000..e23f14299c9d --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_left.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator<<=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] <<= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 6); + assert(v1[ 4] == 16); + assert(v1[ 5] == 40); + assert(v1[ 6] == 6); + assert(v1[ 7] == 112); + assert(v1[ 8] == 256); + assert(v1[ 9] == 576); + assert(v1[10] == 10); + assert(v1[11] == 1408); + assert(v1[12] == 3072); + assert(v1[13] == 6656); + assert(v1[14] == 14); + assert(v1[15] == 15360); + assert(v1[16] == 32768); + assert(v1[17] == 69632); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 180224); + assert(v1[23] == 376832); + assert(v1[24] == 786432); + assert(v1[25] == 25); + assert(v1[26] == 1703936); + assert(v1[27] == 3538944); + assert(v1[28] == 7340032); + assert(v1[29] == 29); + assert(v1[30] == 15728640); + assert(v1[31] == 32505856); + assert(v1[32] == 67108864); + assert(v1[33] == 33); + assert(v1[34] == 142606336); + assert(v1[35] == 293601280); + assert(v1[36] == 603979776); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_right.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_right.pass.cpp new file mode 100644 index 000000000000..33db33f0c5fa --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/shift_right.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator>>=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] >>= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 1); + assert(v1[ 5] == 0); + assert(v1[ 6] == 6); + assert(v1[ 7] == 0); + assert(v1[ 8] == 0); + assert(v1[ 9] == 0); + assert(v1[10] == 10); + assert(v1[11] == 0); + assert(v1[12] == 0); + assert(v1[13] == 0); + assert(v1[14] == 14); + assert(v1[15] == 0); + assert(v1[16] == 0); + assert(v1[17] == 0); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 0); + assert(v1[23] == 0); + assert(v1[24] == 0); + assert(v1[25] == 25); + assert(v1[26] == 0); + assert(v1[27] == 0); + assert(v1[28] == 0); + assert(v1[29] == 29); + assert(v1[30] == 0); + assert(v1[31] == 0); + assert(v1[32] == 0); + assert(v1[33] == 33); + assert(v1[34] == 0); + assert(v1[35] == 0); + assert(v1[36] == 0); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/subtraction.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/subtraction.pass.cpp new file mode 100644 index 000000000000..dd2d35f99204 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/subtraction.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator-=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] -= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 2); + assert(v1[ 5] == 2); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 3); + assert(v1[ 9] == 3); + assert(v1[10] == 10); + assert(v1[11] == 4); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 5); + assert(v1[17] == 5); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 9); + assert(v1[23] == 9); + assert(v1[24] == 9); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 10); + assert(v1[29] == 29); + assert(v1[30] == 11); + assert(v1[31] == 11); + assert(v1[32] == 11); + assert(v1[33] == 33); + assert(v1[34] == 12); + assert(v1[35] == 12); + assert(v1[36] == 12); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/xor.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/xor.pass.cpp new file mode 100644 index 000000000000..f2c3427b9291 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.comp.assign/xor.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator^=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + std::size_t s[N2] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + std::valarray<std::size_t> ia(s, N2); + v1[ia] ^= v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 6); + assert(v1[ 5] == 6); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 13); + assert(v1[ 9] == 15); + assert(v1[10] == 10); + assert(v1[11] == 12); + assert(v1[12] == 4); + assert(v1[13] == 4); + assert(v1[14] == 14); + assert(v1[15] == 5); + assert(v1[16] == 27); + assert(v1[17] == 29); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 27); + assert(v1[23] == 25); + assert(v1[24] == 23); + assert(v1[25] == 25); + assert(v1[26] == 10); + assert(v1[27] == 10); + assert(v1[28] == 14); + assert(v1[29] == 29); + assert(v1[30] == 13); + assert(v1[31] == 11); + assert(v1[32] == 53); + assert(v1[33] == 33); + assert(v1[34] == 52); + assert(v1[35] == 52); + assert(v1[36] == 60); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/indirect.array.fill/assign_value.pass.cpp b/test/std/numerics/numarray/template.indirect.array/indirect.array.fill/assign_value.pass.cpp new file mode 100644 index 000000000000..de2bb43441c1 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/indirect.array.fill/assign_value.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class indirect_array + +// void operator=(const value_type& x) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + std::valarray<int> v1(a1, N1); + std::valarray<std::size_t> ia(s, S); + v1[ia] = 51; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 51); + assert(v1[ 4] == 51); + assert(v1[ 5] == 51); + assert(v1[ 6] == 6); + assert(v1[ 7] == 51); + assert(v1[ 8] == 51); + assert(v1[ 9] == 51); + assert(v1[10] == 10); + assert(v1[11] == 51); + assert(v1[12] == 51); + assert(v1[13] == 51); + assert(v1[14] == 14); + assert(v1[15] == 51); + assert(v1[16] == 51); + assert(v1[17] == 51); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == 51); + assert(v1[23] == 51); + assert(v1[24] == 51); + assert(v1[25] == 25); + assert(v1[26] == 51); + assert(v1[27] == 51); + assert(v1[28] == 51); + assert(v1[29] == 29); + assert(v1[30] == 51); + assert(v1[31] == 51); + assert(v1[32] == 51); + assert(v1[33] == 33); + assert(v1[34] == 51); + assert(v1[35] == 51); + assert(v1[36] == 51); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.indirect.array/types.pass.cpp b/test/std/numerics/numarray/template.indirect.array/types.pass.cpp new file mode 100644 index 000000000000..fe118ea329a3 --- /dev/null +++ b/test/std/numerics/numarray/template.indirect.array/types.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> +// class indirect_array +// { +// public: +// typedef T value_type; + +#include <valarray> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::indirect_array<int>::value_type, int>::value), ""); +} diff --git a/test/std/numerics/numarray/template.mask.array/default.fail.cpp b/test/std/numerics/numarray/template.mask.array/default.fail.cpp new file mode 100644 index 000000000000..97476c65c195 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/default.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// mask_array() = delete; + +#include <valarray> +#include <type_traits> + +int main() +{ + std::mask_array<int> s; +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp new file mode 100644 index 000000000000..29cb787d009e --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void mask_array& operator=(const mask_array& ma) const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b1[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + int a2[] = {-1, -2, -3, -4, -5, -6, -7, -8}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b2[N2] = {true, false, true, true, + false, false, true, true}; + std::valarray<int> v1(a1, N1); + const std::valarray<int> v2(a2, N2); + std::valarray<bool> vb1(b1, N1); + std::valarray<bool> vb2(b2, N2); + v1[vb1] = v2[vb2]; + assert(v1.size() == 16); + assert(v1[ 0] == -1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == -3); + assert(v1[ 4] == -4); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -7); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == -8); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); + } + // Test return value of assignment + { + int a1[] = {0, 1, 2}; + int a2[] = {3, 4, 5}; + bool b1[] = {true, false, true}; + std::valarray<int> v1(a1, 3); + std::valarray<int> v2(a2, 3); + std::valarray<bool> const vb1(b1, 3); + std::mask_array<int> m1 = v1[vb1]; + std::mask_array<int> const m2 = v2[vb1]; + std::mask_array<int> const & r = (m1 = m2); + assert(&r == &m1); + } +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.assign/valarray.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.assign/valarray.pass.cpp new file mode 100644 index 000000000000..63949e2449b8 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.assign/valarray.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] = v2; + assert(v1.size() == 16); + assert(v1[ 0] == 1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 3); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 5); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/addition.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/addition.pass.cpp new file mode 100644 index 000000000000..984762943c63 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/addition.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator+=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] += v2; + assert(v1.size() == 16); + assert(v1[ 0] == 1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 5); + assert(v1[ 4] == 7); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 11); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 16); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/and.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/and.pass.cpp new file mode 100644 index 000000000000..7e110b13af21 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/and.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator&=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] &= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 2); + assert(v1[ 4] == 0); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 1); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/divide.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/divide.pass.cpp new file mode 100644 index 000000000000..9fe243875ce5 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/divide.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator/=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] /= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 1); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 1); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 2); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/modulo.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/modulo.pass.cpp new file mode 100644 index 000000000000..bd0ee0836fb8 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/modulo.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator%=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] %= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 1); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 1); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/multiply.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/multiply.pass.cpp new file mode 100644 index 000000000000..13efefc375f2 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/multiply.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator*=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] *= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 6); + assert(v1[ 4] == 12); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 28); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 55); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/or.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/or.pass.cpp new file mode 100644 index 000000000000..9b06879a8a17 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/or.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator|=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] |= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 7); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 7); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 15); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_left.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_left.pass.cpp new file mode 100644 index 000000000000..9c1f92a3e807 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_left.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator<<=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] <<= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 12); + assert(v1[ 4] == 32); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 112); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 352); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_right.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_right.pass.cpp new file mode 100644 index 000000000000..438d3427d430 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/shift_right.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator>>=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] >>= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == 0); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 0); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 0); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/subtraction.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/subtraction.pass.cpp new file mode 100644 index 000000000000..16e387dc6d78 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/subtraction.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator-=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] -= v2; + assert(v1.size() == 16); + assert(v1[ 0] == -1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 1); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 6); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/xor.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/xor.pass.cpp new file mode 100644 index 000000000000..ae3c2383d4d0 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.comp.assign/xor.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator^=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + int a2[] = {1, 2, 3, 4, 5}; + const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<int> v2(a2, N2); + assert(N2 == std::count(b, b+N1, true)); + std::valarray<bool> vb(b, N1); + v1[vb] ^= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 1); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 1); + assert(v1[ 4] == 7); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == 14); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/mask.array.fill/assign_value.pass.cpp b/test/std/numerics/numarray/template.mask.array/mask.array.fill/assign_value.pass.cpp new file mode 100644 index 000000000000..c37916b0b7dc --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/mask.array.fill/assign_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class mask_array + +// void operator=(const value_type& x) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<bool> vb(b, N1); + v1[vb] = -5; + assert(v1.size() == 16); + assert(v1[ 0] == -5); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == -5); + assert(v1[ 4] == -5); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -5); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 10); + assert(v1[11] == -5); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.mask.array/types.pass.cpp b/test/std/numerics/numarray/template.mask.array/types.pass.cpp new file mode 100644 index 000000000000..c984c3feaa16 --- /dev/null +++ b/test/std/numerics/numarray/template.mask.array/types.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> +// class mask_array +// { +// public: +// typedef T value_type; + +#include <valarray> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::mask_array<int>::value_type, int>::value), ""); +} diff --git a/test/std/numerics/numarray/template.slice.array/default.fail.cpp b/test/std/numerics/numarray/template.slice.array/default.fail.cpp new file mode 100644 index 000000000000..3b522f0e12cb --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/default.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// slice_array() = delete; + +#include <valarray> +#include <type_traits> + +int main() +{ + std::slice_array<int> s; +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp new file mode 100644 index 000000000000..72275e01e1be --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// const slice_array& operator=(const slice_array& sa) const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + const std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] = v2[std::slice(2, 5, 2)]; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == -3); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == -5); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -7); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == -9); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == -11); + assert(v1[14] == 14); + assert(v1[15] == 15); + } + // Test return value of assignment. + { + int a1[] = {0, 1, 2}; + int a2[] = {3, 4, 3}; + std::valarray<int> v1(a1, 3); + std::slice_array<int> s1 = v1[std::slice(1, 1, 1)]; + std::slice_array<int> s2 = v1[std::slice(0, 1, 1)]; + std::slice_array<int> const & s3 = (s1 = s2); + assert(&s1 == &s3); + } +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.assign/valarray.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.assign/valarray.pass.cpp new file mode 100644 index 000000000000..d3857863f91d --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.assign/valarray.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] = v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == -1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == -2); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == -4); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == -5); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/addition.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/addition.pass.cpp new file mode 100644 index 000000000000..8b5bf75d414a --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/addition.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator+= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] += v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 0); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 2); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 6); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 8); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/and.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/and.pass.cpp new file mode 100644 index 000000000000..dbcae84771bc --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/and.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator&= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {1, 2, 3, 4, 5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] &= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 0); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 0); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 5); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/divide.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/divide.pass.cpp new file mode 100644 index 000000000000..71785015ba3b --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/divide.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator/= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] /= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == -1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == -2); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -2); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == -2); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == -2); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/modulo.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/modulo.pass.cpp new file mode 100644 index 000000000000..e08fb51a8c26 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/modulo.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator%= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] %= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 0); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 0); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 1); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 2); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 3); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/multiply.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/multiply.pass.cpp new file mode 100644 index 000000000000..257c03164209 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/multiply.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator*= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] *= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == -1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == -8); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -21); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == -40); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == -65); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/or.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/or.pass.cpp new file mode 100644 index 000000000000..0826708a36f3 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/or.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator|= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {1, 2, 3, 4, 5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] |= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 6); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 7); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 14); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 13); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_left.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_left.pass.cpp new file mode 100644 index 000000000000..84360d8c9405 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_left.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator<<=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {1, 2, 3, 4, 5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] <<= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 2); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 16); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 56); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 160); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 416); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_right.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_right.pass.cpp new file mode 100644 index 000000000000..c39cd53e9167 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/shift_right.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator>>=(const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {1, 2, 3, 4, 5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] >>= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 0); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 1); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 0); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 0); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 0); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/subtraction.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/subtraction.pass.cpp new file mode 100644 index 000000000000..e6419fb2cd1e --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/subtraction.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator-= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] -= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 2); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 6); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 10); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 14); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 18); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/xor.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/xor.pass.cpp new file mode 100644 index 000000000000..294106ed75a6 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.comp.assign/xor.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator^= (const valarray<value_type>& v) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {1, 2, 3, 4, 5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] ^= v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 0); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 6); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 4); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 14); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 8); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/slice.arr.fill/assign_value.pass.cpp b/test/std/numerics/numarray/template.slice.array/slice.arr.fill/assign_value.pass.cpp new file mode 100644 index 000000000000..4f7af4baf6f5 --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/slice.arr.fill/assign_value.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> class slice_array + +// void operator=(const value_type& x) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + v1[std::slice(1, 5, 3)] = 20; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == 20); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == 20); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == 20); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == 20); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == 20); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.slice.array/types.pass.cpp b/test/std/numerics/numarray/template.slice.array/types.pass.cpp new file mode 100644 index 000000000000..8c40b154f4dc --- /dev/null +++ b/test/std/numerics/numarray/template.slice.array/types.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template <class T> +// class slice_array +// { +// public: +// typedef T value_type; + +#include <valarray> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::slice_array<int>::value_type, int>::value), ""); +} diff --git a/test/std/numerics/numarray/template.valarray/types.pass.cpp b/test/std/numerics/numarray/template.valarray/types.pass.cpp new file mode 100644 index 000000000000..71421e543ffa --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> +// class valarray +// { +// public: +// typedef T value_type; +// ... + +#include <valarray> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::valarray<int>::value_type, int>::value), ""); + static_assert((std::is_same<std::valarray<double>::value_type, double>::value), ""); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.access/access.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.access/access.pass.cpp new file mode 100644 index 000000000000..7bf164aafc20 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.access/access.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// value_type& operator[](size_t i); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {5, 4, 3, 2, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + for (int i = 0; i < N; ++i) + { + assert(v[i] == a[i]); + v[i] = i; + assert(v[i] == i); + } + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.access/const_access.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.access/const_access.pass.cpp new file mode 100644 index 000000000000..b9736eedd73b --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.access/const_access.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// const value_type& operator[](size_t i) const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {5, 4, 3, 2, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + const std::valarray<T> v(a, N); + for (int i = 0; i < N; ++i) + { + assert(v[i] == a[i]); + } + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/copy_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/copy_assign.pass.cpp new file mode 100644 index 000000000000..2fc42ada85be --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/copy_assign.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2; + v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2; + v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2(a, N-2); + v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == v[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v2[i][j] == v[i][j]); + } + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/gslice_array_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/gslice_array_assign.pass.cpp new file mode 100644 index 000000000000..dff523f19e68 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/gslice_array_assign.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const gslice_array<value_type>& ga); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + std::valarray<int> v1(a, sizeof(a)/sizeof(a[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + std::valarray<int> v(24); + v = v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))]; + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/indirect_array_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/indirect_array_assign.pass.cpp new file mode 100644 index 000000000000..6e8069cc2fad --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/indirect_array_assign.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const indirect_array<value_type>& ia); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a)/sizeof(a[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + std::valarray<int> v1(a, N1); + std::valarray<std::size_t> ia(s, S); + std::valarray<int> v(24); + v = v1[ia]; + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/initializer_list_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/initializer_list_assign.pass.cpp new file mode 100644 index 000000000000..571f56acd575 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/initializer_list_assign.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(initializer_list<value_type> il); + +#include <valarray> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v2; + v2 = {1, 2, 3, 4, 5}; + assert(v2.size() == N); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v2; + v2 = {1, 2.5, 3, 4.25, 5}; + assert(v2.size() == N); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v2(a, N-2); + v2 = {T(1), T(2), T(3), T(4), T(5)}; + assert(v2.size() == N); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == a[i].size()); + for (int j = 0; j < a[i].size(); ++j) + assert(v2[i][j] == a[i][j]); + } + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/mask_array_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/mask_array_assign.pass.cpp new file mode 100644 index 000000000000..a52c9d9d6726 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/mask_array_assign.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const mask_array<value_type>& ma); + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<bool> vb(b, N1); + std::valarray<int> v2(5); + v2 = v1[vb]; + assert(v2.size() == 5); + assert(v2[ 0] == 0); + assert(v2[ 1] == 3); + assert(v2[ 2] == 4); + assert(v2[ 3] == 7); + assert(v2[ 4] == 11); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/move_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/move_assign.pass.cpp new file mode 100644 index 000000000000..d4f750652e28 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/move_assign.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(valarray&& v); + +#include <valarray> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2; + v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2; + v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2(a, N-2); + v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == a[i].size()); + for (int j = 0; j < a[i].size(); ++j) + assert(v2[i][j] == a[i][j]); + } + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/slice_array_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/slice_array_assign.pass.cpp new file mode 100644 index 000000000000..9a7517aa1f44 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/slice_array_assign.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const slice_array<value_type>& sa); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + std::valarray<int> v1(a, sizeof(a)/sizeof(a[0])); + std::valarray<int> v(5); + v = v1[std::slice(1, 5, 3)]; + assert(v.size() == 5); + assert(v[0] == 1); + assert(v[1] == 4); + assert(v[2] == 7); + assert(v[3] == 10); + assert(v[4] == 13); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.assign/value_assign.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.assign/value_assign.pass.cpp new file mode 100644 index 000000000000..b9d67f86a212 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.assign/value_assign.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + v = 7; + assert(v.size() == N); + for (int i = 0; i < v.size(); ++i) + assert(v[i] == 7); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/and_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/and_valarray.pass.cpp new file mode 100644 index 000000000000..5b1c1b9911b4 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/and_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator&=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {0, 2, 0, 0, 0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 &= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/and_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/and_value.pass.cpp new file mode 100644 index 000000000000..2106a13e2c35 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/and_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator&=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 1, 2, 3, 0, 1}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 &= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_valarray.pass.cpp new file mode 100644 index 000000000000..3992d0aa43da --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator/=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {6, 14, 24, 36, 50}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v3 /= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_value.pass.cpp new file mode 100644 index 000000000000..7bd1cc84df6c --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/divide_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator/=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 12, 18, 24, 30}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v2 /= 6; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_valarray.pass.cpp new file mode 100644 index 000000000000..e3d308abacc1 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator-=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 9, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v3 -= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_value.pass.cpp new file mode 100644 index 000000000000..27ea8c2c0366 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/minus_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator-=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = {-2, -1, 0, 1, 2}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 -= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_valarray.pass.cpp new file mode 100644 index 000000000000..1754a5575eb5 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator%=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {0, 1, 2, 1, 0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v2 %= v1; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v2[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_value.pass.cpp new file mode 100644 index 000000000000..794a0b629268 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/modulo_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator%=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {1, 2, 0, 1, 2}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 %= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/or_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/or_valarray.pass.cpp new file mode 100644 index 000000000000..0d70b4e715da --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/or_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator|=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 7, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 |= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/or_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/or_value.pass.cpp new file mode 100644 index 000000000000..4030907ff3e7 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/or_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator|=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 3, 3, 3, 7, 7}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 |= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_valarray.pass.cpp new file mode 100644 index 000000000000..fdf999c2a044 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator+=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 9, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 += v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_value.pass.cpp new file mode 100644 index 000000000000..23d6d9d05229 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/plus_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator+=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {4, 5, 6, 7, 8}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 += 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_valarray.pass.cpp new file mode 100644 index 000000000000..ad44e3887eca --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator<<=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 6, 7, 8, 9, 10}; + T a3[] = {64, 256, 768, 2048, 5120}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 <<= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_value.pass.cpp new file mode 100644 index 000000000000..366407a95c6f --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_left_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator<<=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 8, 16, 24, 32, 40}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 <<= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_valarray.pass.cpp new file mode 100644 index 000000000000..f7df16b843ca --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator>>=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 6, 7, 8, 9, 10}; + T a3[] = {64, 256, 768, 2048, 5120}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v3 >>= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_value.pass.cpp new file mode 100644 index 000000000000..7c568b14cbea --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/shift_right_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator>>=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 8, 16, 24, 32, 40}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v2 >>= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/times_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/times_valarray.pass.cpp new file mode 100644 index 000000000000..d3cf1eb88641 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/times_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator*=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {6, 14, 24, 36, 50}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 *= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/times_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/times_value.pass.cpp new file mode 100644 index 000000000000..aea9806bc0d0 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/times_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator*=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 12, 18, 24, 30}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 *= 6; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_valarray.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_valarray.pass.cpp new file mode 100644 index 000000000000..a10bd7e0a000 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_valarray.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator^=(const valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 5, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3(a3, N); + v1 ^= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v3[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_value.pass.cpp new file mode 100644 index 000000000000..327952f7b3aa --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cassign/xor_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray& operator^=(const value_type& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 2, 1, 0, 7, 6}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + v1 ^= 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/copy.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/copy.pass.cpp new file mode 100644 index 000000000000..04ac2cdf1b90 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/copy.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const valarray<value_type>& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = v; + assert(v2.size() == v.size()); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == v[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v2[i][j] == v[i][j]); + } + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/default.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/default.pass.cpp new file mode 100644 index 000000000000..f46e0bf28cf8 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/default.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(); + +#include <valarray> +#include <cassert> + +int main() +{ + { + std::valarray<int> v; + assert(v.size() == 0); + } + { + std::valarray<float> v; + assert(v.size() == 0); + } + { + std::valarray<double> v; + assert(v.size() == 0); + } + { + std::valarray<std::valarray<double> > v; + assert(v.size() == 0); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/gslice_array.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/gslice_array.pass.cpp new file mode 100644 index 000000000000..56601dc92531 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/gslice_array.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const gslice_array<value_type>& sa); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + std::valarray<int> v1(a, sizeof(a)/sizeof(a[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))]); + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/indirect_array.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/indirect_array.pass.cpp new file mode 100644 index 000000000000..dbca1f9c7661 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/indirect_array.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const indirect_array<value_type>& ia); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a)/sizeof(a[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + std::valarray<int> v1(a, N1); + std::valarray<std::size_t> ia(s, S); + std::valarray<int> v(v1[ia]); + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/initializer_list.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/initializer_list.pass.cpp new file mode 100644 index 000000000000..1ab460f1b9d5 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(initializer_list<value_type>); + +#include <valarray> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v = {1, 2, 3, 4, 5}; + assert(v.size() == N); + for (int i = 0; i < N; ++i) + assert(v[i] == a[i]); + } + { + typedef double T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v = {1, 2, 3, 4, 5}; + assert(v.size() == N); + for (int i = 0; i < N; ++i) + assert(v[i] == a[i]); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/mask_array.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/mask_array.pass.cpp new file mode 100644 index 000000000000..be4f7403945e --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/mask_array.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const mask_array<value_type>& ma); + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<bool> vb(b, N1); + std::valarray<int> v2(v1[vb]); + assert(v2.size() == 5); + assert(v2[ 0] == 0); + assert(v2[ 1] == 3); + assert(v2[ 2] == 4); + assert(v2[ 3] == 7); + assert(v2[ 4] == 11); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/move.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/move.pass.cpp new file mode 100644 index 000000000000..6ac8773fa4e2 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/move.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const valarray<value_type>& v); + +#include <valarray> +#include <utility> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = std::move(v); + assert(v2.size() == N); + assert(v.size() == 0); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == a[i].size()); + for (int j = 0; j < v2[i].size(); ++j) + assert(v2[i][j] == a[i][j]); + } + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/pointer_size.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/pointer_size.pass.cpp new file mode 100644 index 000000000000..3d3649ee40ac --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/pointer_size.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const value_type* p, size_t n); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + assert(v.size() == N); + for (int i = 0; i < N; ++i) + assert(v[i] == a[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + assert(v.size() == N); + for (int i = 0; i < N; ++i) + assert(v[i] == a[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + assert(v.size() == N); + for (int i = 0; i < N; ++i) + { + assert(v[i].size() == a[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v[i][j] == a[i][j]); + } + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp new file mode 100644 index 000000000000..359073eb3ae9 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// explicit valarray(size_t); + +#include <valarray> +#include <cassert> + +int main() +{ + { + std::valarray<int> v(100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i] == 0); + } + { + std::valarray<double> v(100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i] == 0); + } + { + std::valarray<std::valarray<double> > v(100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i].size() == 0); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/slice_array.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/slice_array.pass.cpp new file mode 100644 index 000000000000..b676414140c1 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/slice_array.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const slice_array<value_type>& sa); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + std::valarray<int> v1(a, sizeof(a)/sizeof(a[0])); + std::valarray<int> v(v1[std::slice(1, 5, 3)]); + assert(v.size() == 5); + assert(v[0] == 1); + assert(v[1] == 4); + assert(v[2] == 7); + assert(v[3] == 10); + assert(v[4] == 13); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.cons/value_size.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.cons/value_size.pass.cpp new file mode 100644 index 000000000000..336c898b548d --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.cons/value_size.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray(const value_type& x, size_t n); + +#include <valarray> +#include <cassert> + +int main() +{ + { + std::valarray<int> v(5, 100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i] == 5); + } + { + std::valarray<double> v(2.5, 100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i] == 2.5); + } + { + std::valarray<std::valarray<double> > v(std::valarray<double>(10), 100); + assert(v.size() == 100); + for (int i = 0; i < 100; ++i) + assert(v[i].size() == 10); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp new file mode 100644 index 000000000000..919a3a5e4997 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray apply(value_type f(const value_type&)) const; + +#include <valarray> +#include <cassert> + +typedef int T; + +T f(const T& t) {return t + 5;} + +int main() +{ + { + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.apply(f); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + const unsigned N1 = 0; + std::valarray<T> v1; + std::valarray<T> v2 = v1.apply(f); + assert(v2.size() == N1); + } + { + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1+v1).apply(f); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp new file mode 100644 index 000000000000..dc7a1a100a21 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray apply(value_type f(value_type)) const; + +#include <valarray> +#include <cassert> + +typedef int T; + +T f(T t) {return t + 5;} + +int main() +{ + { + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.apply(f); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + const unsigned N1 = 0; + std::valarray<T> v1; + std::valarray<T> v2 = v1.apply(f); + assert(v2.size() == N1); + } + { + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1+v1).apply(f); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp new file mode 100644 index 000000000000..601a6df8d5e5 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray cshift(int i) const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(0); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(10); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(17); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(-3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(-10); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.cshift(-17); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + const unsigned N1 = 0; + std::valarray<T> v1; + std::valarray<T> v2 = v1.cshift(-17); + assert(v2.size() == N1); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1 + v1).cshift(3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1 + v1).cshift(-3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp new file mode 100644 index 000000000000..697d4cd19ed6 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// value_type max() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef double T; + T a1[] = {1.5, 2.5, -3, 4, -5.5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert(v1.max() == 4.0); + } + { + typedef double T; + std::valarray<T> v1; + v1.max(); + } + { + typedef double T; + T a1[] = {1.5, 2.5, -3, 4, -5.5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert((2*v1).max() == 8.0); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp new file mode 100644 index 000000000000..dac59343715a --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// value_type min() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef double T; + T a1[] = {1.5, 2.5, -3, 4, 5.5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert(v1.min() == -3.0); + } + { + typedef double T; + std::valarray<T> v1; + v1.min(); + } + { + typedef double T; + T a1[] = {1.5, 2.5, -3, 4, 5.5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert((2*v1).min() == -6.0); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp new file mode 100644 index 000000000000..176d958aab92 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// void resize(size_t n, value_type x = value_type()); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + v1.resize(8); + assert(v1.size() == 8); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == 0); + v1.resize(0); + assert(v1.size() == 0); + v1.resize(80); + assert(v1.size() == 80); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == 0); + v1.resize(40); + assert(v1.size() == 40); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == 0); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp new file mode 100644 index 000000000000..9a617a91a417 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray shift(int i) const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(0); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 0}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(1); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {10, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(9); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(90); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(-1); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(-9); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = v1.shift(-90); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + const unsigned N1 = 0; + std::valarray<T> v1; + std::valarray<T> v2 = v1.shift(-90); + assert(v2.size() == N1); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {8, 10, 12, 14, 16, 18, 20, 0, 0, 0}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1 + v1).shift(3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + T a2[] = {0, 0, 0, 2, 4, 6, 8, 10, 12, 14}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2 = (v1 + v1).shift(-3); + assert(v2.size() == N1); + for (unsigned i = 0; i < N1; ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp new file mode 100644 index 000000000000..0aae5b8de7fa --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// size_t size() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert(v1.size() == N1); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + const unsigned N1 = 0; + std::valarray<T> v1(a1, N1); + assert(v1.size() == N1); + } + { + typedef int T; + const unsigned N1 = 0; + std::valarray<T> v1; + assert(v1.size() == N1); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp new file mode 100644 index 000000000000..189f03d25cf4 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// value_type sum() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef double T; + T a1[] = {1.5, 2.5, 3, 4, 5.5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N1); + assert(v1.sum() == 16.5); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp new file mode 100644 index 000000000000..a90a80936376 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// void swap(valarray& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10, 11, 12}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + const unsigned N2 = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2(a2, N2); + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + v1.swap(v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + const unsigned N2 = 0; + std::valarray<T> v1(a1, N1); + std::valarray<T> v2; + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + v1.swap(v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + T a2[] = {6, 7, 8, 9, 10, 11, 12}; + const unsigned N1 = 0; + const unsigned N2 = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v1; + std::valarray<T> v2(a2, N2); + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + v1.swap(v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + const unsigned N1 = 0; + const unsigned N2 = 0; + std::valarray<T> v1; + std::valarray<T> v2; + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + v1.swap(v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp new file mode 100644 index 000000000000..7bbd48c34538 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// gslice_array<value_type> operator[](const gslice& gs); + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, + -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))] = v2; + assert(v1.size() == 41); + assert(v1[ 0] == 0); + assert(v1[ 1] == 1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 0); + assert(v1[ 4] == -1); + assert(v1[ 5] == -2); + assert(v1[ 6] == 6); + assert(v1[ 7] == -3); + assert(v1[ 8] == -4); + assert(v1[ 9] == -5); + assert(v1[10] == 10); + assert(v1[11] == -6); + assert(v1[12] == -7); + assert(v1[13] == -8); + assert(v1[14] == 14); + assert(v1[15] == -9); + assert(v1[16] == -10); + assert(v1[17] == -11); + assert(v1[18] == 18); + assert(v1[19] == 19); + assert(v1[20] == 20); + assert(v1[21] == 21); + assert(v1[22] == -12); + assert(v1[23] == -13); + assert(v1[24] == -14); + assert(v1[25] == 25); + assert(v1[26] == -15); + assert(v1[27] == -16); + assert(v1[28] == -17); + assert(v1[29] == 29); + assert(v1[30] == -18); + assert(v1[31] == -19); + assert(v1[32] == -20); + assert(v1[33] == 33); + assert(v1[34] == -21); + assert(v1[35] == -22); + assert(v1[36] == -23); + assert(v1[37] == 37); + assert(v1[38] == 38); + assert(v1[39] == 39); + assert(v1[40] == 40); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp new file mode 100644 index 000000000000..282dcf1f6db9 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator[](const gslice& gs) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + std::valarray<int> v1(a, sizeof(a)/sizeof(a[0])); + std::size_t sz[] = {2, 4, 3}; + std::size_t st[] = {19, 4, 1}; + typedef std::valarray<std::size_t> sizes; + typedef std::valarray<std::size_t> strides; + std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])), + strides(st, sizeof(st)/sizeof(st[0])))]); + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp new file mode 100644 index 000000000000..1bc4fb929007 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator[](const valarray<size_t>& vs) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a)/sizeof(a[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + const std::valarray<int> v1(a, N1); + std::valarray<std::size_t> ia(s, S); + std::valarray<int> v = v1[ia]; + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp new file mode 100644 index 000000000000..d0b7438172ee --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// indirect_array<value_type> operator[](const valarray<size_t>& vs); + +#include <valarray> +#include <cassert> + +int main() +{ + int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40}; + const std::size_t N1 = sizeof(a)/sizeof(a[0]); + std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, + 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36}; + const std::size_t S = sizeof(s)/sizeof(s[0]); + std::valarray<int> v1(a, N1); + std::valarray<std::size_t> ia(s, S); + std::valarray<int> v(24); + v = v1[ia]; + assert(v.size() == 24); + assert(v[ 0] == 3); + assert(v[ 1] == 4); + assert(v[ 2] == 5); + assert(v[ 3] == 7); + assert(v[ 4] == 8); + assert(v[ 5] == 9); + assert(v[ 6] == 11); + assert(v[ 7] == 12); + assert(v[ 8] == 13); + assert(v[ 9] == 15); + assert(v[10] == 16); + assert(v[11] == 17); + assert(v[12] == 22); + assert(v[13] == 23); + assert(v[14] == 24); + assert(v[15] == 26); + assert(v[16] == 27); + assert(v[17] == 28); + assert(v[18] == 30); + assert(v[19] == 31); + assert(v[20] == 32); + assert(v[21] == 34); + assert(v[22] == 35); + assert(v[23] == 36); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp new file mode 100644 index 000000000000..7f8191035e7a --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator[](slice s) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2 = v1[std::slice(1, 5, 3)]; + assert(v2.size() == 5); + assert(v2[0] == 1); + assert(v2[1] == 4); + assert(v2[2] == 7); + assert(v2[3] == 10); + assert(v2[4] == 13); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp new file mode 100644 index 000000000000..6bf9b430ec84 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// slice_array<value_type> operator[](slice s); + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + int a2[] = {-1, -2, -3, -4, -5}; + std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); + std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0])); + v1[std::slice(1, 5, 3)] = v2; + assert(v1.size() == 16); + assert(v1[ 0] == 0); + assert(v1[ 1] == -1); + assert(v1[ 2] == 2); + assert(v1[ 3] == 3); + assert(v1[ 4] == -2); + assert(v1[ 5] == 5); + assert(v1[ 6] == 6); + assert(v1[ 7] == -3); + assert(v1[ 8] == 8); + assert(v1[ 9] == 9); + assert(v1[10] == -4); + assert(v1[11] == 11); + assert(v1[12] == 12); + assert(v1[13] == -5); + assert(v1[14] == 14); + assert(v1[15] == 15); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp new file mode 100644 index 000000000000..10bdd82e5536 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator[](const valarray<bool>& vb) const; + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<bool> vb(b, N1); + std::valarray<int> v2(v1[vb]); + assert(v2.size() == 5); + assert(v2[ 0] == 0); + assert(v2[ 1] == 3); + assert(v2[ 2] == 4); + assert(v2[ 3] == 7); + assert(v2[ 4] == 11); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp new file mode 100644 index 000000000000..cecf9502293d --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// mask_array<value_type> operator[](const valarray<bool>& vb); + +#include <valarray> +#include <cassert> + +int main() +{ + int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); + bool b[N1] = {true, false, false, true, true, false, + false, true, false, false, false, true}; + std::valarray<int> v1(a1, N1); + std::valarray<bool> vb(b, N1); + std::valarray<int> v2(5); + v2 = v1[vb]; + assert(v2.size() == 5); + assert(v2[ 0] == 0); + assert(v2[ 1] == 3); + assert(v2[ 2] == 4); + assert(v2[ 3] == 7); + assert(v2[ 4] == 11); +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.unary/bit_not.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.unary/bit_not.pass.cpp new file mode 100644 index 000000000000..c1d240cb6798 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.unary/bit_not.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator~() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = ~v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == ~v[i]); + } + { + typedef std::valarray<int> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = ~v; + assert(v2.size() == v.size()); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == v[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v2[i][j] == ~v[i][j]); + } + } + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = ~(v + v); + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == ~(2*v[i])); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.unary/negate.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.unary/negate.pass.cpp new file mode 100644 index 000000000000..25674bb44d92 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.unary/negate.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator-() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = -v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == -v[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = -v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == -v[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = -v; + assert(v2.size() == v.size()); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == v[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v2[i][j] == -v[i][j]); + } + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = -(v + v); + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == -2*v[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.unary/not.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.unary/not.pass.cpp new file mode 100644 index 000000000000..0b792c68fb94 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.unary/not.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray<bool> operator!() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<bool> v2 = !v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == !v[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<bool> v2 = !(v + v); + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == !2*v[i]); + } +} diff --git a/test/std/numerics/numarray/template.valarray/valarray.unary/plus.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.unary/plus.pass.cpp new file mode 100644 index 000000000000..4bcdaf095ff5 --- /dev/null +++ b/test/std/numerics/numarray/template.valarray/valarray.unary/plus.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// valarray operator+() const; + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = +v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == +v[i]); + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = +v; + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == +v[i]); + } + { + typedef std::valarray<double> T; + T a[] = {T(1), T(2), T(3), T(4), T(5)}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = +v; + assert(v2.size() == v.size()); + for (int i = 0; i < N; ++i) + { + assert(v2[i].size() == v[i].size()); + for (int j = 0; j < v[i].size(); ++j) + assert(v2[i][j] == +v[i][j]); + } + } + { + typedef double T; + T a[] = {1, 2.5, 3, 4.25, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + std::valarray<T> v2 = +(v + v); + assert(v2.size() == v.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == +2*v[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/nothing_to_do.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..9214e61fb4da --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator&(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {0, 2, 0, 0, 0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 & v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_value.pass.cpp new file mode 100644 index 000000000000..0976a88dcb81 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator&(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 1, 2, 3, 0, 1}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 & 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_value_valarray.pass.cpp new file mode 100644 index 000000000000..e3dd180b2181 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/and_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator&(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 1, 2, 3, 0, 1}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 & v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..ff250afd2a1a --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator/(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {6, 14, 24, 36, 50}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 / v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_value.pass.cpp new file mode 100644 index 000000000000..ffbebab1e1ae --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator/(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {6, 12, 18, 24, 30}; + T a2[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 / 6; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_value_valarray.pass.cpp new file mode 100644 index 000000000000..1a7f2f07c83a --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/divide_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator/(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {3, 1, 1, 0, 0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 / v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..1f0354e8ac63 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator-(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {7, 9, 11, 13, 15}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 - v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_value.pass.cpp new file mode 100644 index 000000000000..382cab8eae6e --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator-(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = {-2, -1, 0, 1, 2}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 - 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_value_valarray.pass.cpp new file mode 100644 index 000000000000..7f00aba84884 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/minus_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator-(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 2, 1, 0, -1, -2}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 - v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..0a9cf3884c08 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator%(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {6, 7, 8, 9, 10}; + T a2[] = {1, 2, 3, 4, 5}; + T a3[] = {0, 1, 2, 1, 0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 % v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_value.pass.cpp new file mode 100644 index 000000000000..12c4c2453702 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator%(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {1, 2, 0, 1, 2}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 % 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_value_valarray.pass.cpp new file mode 100644 index 000000000000..1d73887217e1 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/modulo_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator%(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {0, 1, 0, 3, 3}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 % v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..a23ea4f58b8c --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator|(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 7, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 | v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_value.pass.cpp new file mode 100644 index 000000000000..f617c27ae7fc --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator|(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 3, 3, 3, 7, 7}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 | 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_value_valarray.pass.cpp new file mode 100644 index 000000000000..8903f438aaf1 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/or_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator|(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 3, 3, 3, 7, 7}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 | v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..1167772aff6a --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator+(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 9, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 + v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_value.pass.cpp new file mode 100644 index 000000000000..b1b4e6931c0c --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator+(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {4, 5, 6, 7, 8}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 + 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_value_valarray.pass.cpp new file mode 100644 index 000000000000..df22853488e9 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/plus_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator+(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {4, 5, 6, 7, 8}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 + v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..42a7c419a3a3 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 6, 7, 8, 9, 10}; + T a3[] = {64, 256, 768, 2048, 5120}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 << v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_value.pass.cpp new file mode 100644 index 000000000000..753ba38f357f --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 8, 16, 24, 32, 40}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 << 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_value_valarray.pass.cpp new file mode 100644 index 000000000000..640ce1a47b32 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_left_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 6, 12, 24, 48, 96}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 << v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..8e6358d62060 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {64, 256, 768, 2048, 5120}; + T a2[] = { 6, 7, 8, 9, 10}; + T a3[] = { 1, 2, 3, 4, 5}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 >> v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_value.pass.cpp new file mode 100644 index 000000000000..0c0ba54463e1 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 8, 16, 24, 32, 40}; + T a2[] = { 1, 2, 3, 4, 5}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 >> 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_value_valarray.pass.cpp new file mode 100644 index 000000000000..ad5418af0267 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/shift_right_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = {20, 10, 5, 2, 1}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 40 >> v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..69a3bffc3e77 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator*(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {6, 14, 24, 36, 50}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 * v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_value.pass.cpp new file mode 100644 index 000000000000..c4fb410de768 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator+(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 12, 18, 24, 30}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 * 6; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_value_valarray.pass.cpp new file mode 100644 index 000000000000..f5d877783ded --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/times_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator*(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 12, 18, 24, 30}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 6 * v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..71b505b0cbe8 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_valarray.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator^(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10}; + T a3[] = {7, 5, 11, 13, 15}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = v1 ^ v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_value.pass.cpp new file mode 100644 index 000000000000..8dbe6843cd24 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_valarray_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator^(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 2, 1, 0, 7, 6}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = v1 ^ 3; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_value_valarray.pass.cpp new file mode 100644 index 000000000000..face0635dfb4 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.binary/xor_value_valarray.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> valarray<T> operator^(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = { 1, 2, 3, 4, 5}; + T a2[] = { 2, 1, 0, 7, 6}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2 = 3 ^ v1; + assert(v1.size() == v2.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == a2[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..af2a1b3ed792 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator&&(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + T a2[] = {6, 7, 0, 9, 10}; + bool a3[] = {true, true, false, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 && v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_value.pass.cpp new file mode 100644 index 000000000000..f34fe9642574 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_valarray_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator&&(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 && 5; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, false, false, false, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 && 0; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_value_valarray.pass.cpp new file mode 100644 index 000000000000..c323d13ff42d --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/and_value_valarray.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator&&(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 5 && v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, false, false, false, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 0 && v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..6222e91595dd --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator==(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 9, 10}; + bool a3[] = {false, false, true, false, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 == v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_value.pass.cpp new file mode 100644 index 000000000000..dca65055b2a0 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator==(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, true, false, false, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 == 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_value_valarray.pass.cpp new file mode 100644 index 000000000000..532219e2e858 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/equal_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator==(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, true, false, false, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 == v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..75e62693baef --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>=(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 2, 1}; + bool a3[] = {false, false, true, true, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 >= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_value.pass.cpp new file mode 100644 index 000000000000..020706dfa2ef --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>=(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, true, true, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 >= 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_value_valarray.pass.cpp new file mode 100644 index 000000000000..faf2003adb7f --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_equal_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>=(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, false, false, true}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 >= v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..3276085f37dc --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 2, 1}; + bool a3[] = {false, false, false, true, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 > v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_value.pass.cpp new file mode 100644 index 000000000000..1ab774cdfb48 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, false, true, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 > 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_value_valarray.pass.cpp new file mode 100644 index 000000000000..c5012d6fc0e5 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/greater_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator>(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, false, false, false, true}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 > v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..ceb6658833eb --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<=(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 2, 1}; + bool a3[] = {true, true, true, false, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 <= v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_value.pass.cpp new file mode 100644 index 000000000000..4a391a3f3799 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<=(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, false, false, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 <= 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_value_valarray.pass.cpp new file mode 100644 index 000000000000..cf34e18b92c0 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_equal_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<=(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, true, true, true, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 <= v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..0fa99488b791 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 2, 1}; + bool a3[] = {true, true, false, false, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 < v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_value.pass.cpp new file mode 100644 index 000000000000..7a47c900a8f8 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, false, false, false, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 < 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_value_valarray.pass.cpp new file mode 100644 index 000000000000..4d6cbadcc8b5 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/less_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator<(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {false, false, true, true, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 < v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..c9675a9ce3e7 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator!=(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 10}; + T a2[] = {6, 7, 0, 9, 10}; + bool a3[] = {true, true, false, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 != v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_value.pass.cpp new file mode 100644 index 000000000000..9daa7289b715 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_valarray_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator!=(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, false, true, true, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 != 2; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_value_valarray.pass.cpp new file mode 100644 index 000000000000..37439aabcb28 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/not_equal_value_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator!=(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, false, true, true, true}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 2 != v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..9a2f84e8f7da --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_valarray.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator||(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 0, 4, 0}; + T a2[] = {6, 7, 0, 9, 10}; + bool a3[] = {true, true, false, true, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = v1 || v2; + assert(v1.size() == v2.size()); + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_value.pass.cpp new file mode 100644 index 000000000000..789df5badf04 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_valarray_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator||(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, true}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 || 5; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, false}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<bool> v3 = v1 || 0; + assert(v1.size() == v3.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_value_valarray.pass.cpp new file mode 100644 index 000000000000..d66905960274 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.comparison/or_value_valarray.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<bool> +// operator||(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, true}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 5 || v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } + { + typedef int T; + T a2[] = {1, 2, 3, 4, 0}; + bool a3[] = {true, true, true, true, false}; + const unsigned N = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v2(a2, N); + std::valarray<bool> v3 = 0 || v2; + assert(v2.size() == v3.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.special/swap.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.special/swap.pass.cpp new file mode 100644 index 000000000000..84f73945c401 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.special/swap.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// void +// swap(valarray<T>& x, valarray<T>& y); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + T a2[] = {6, 7, 8, 9, 10, 11, 12}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + const unsigned N2 = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v1(a1, N1); + std::valarray<T> v2(a2, N2); + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + swap(v1, v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + T a1[] = {1, 2, 3, 4, 5}; + const unsigned N1 = sizeof(a1)/sizeof(a1[0]); + const unsigned N2 = 0; + std::valarray<T> v1(a1, N1); + std::valarray<T> v2; + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + swap(v1, v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + T a2[] = {6, 7, 8, 9, 10, 11, 12}; + const unsigned N1 = 0; + const unsigned N2 = sizeof(a2)/sizeof(a2[0]); + std::valarray<T> v1; + std::valarray<T> v2(a2, N2); + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + swap(v1, v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } + { + typedef int T; + const unsigned N1 = 0; + const unsigned N2 = 0; + std::valarray<T> v1; + std::valarray<T> v2; + std::valarray<T> v1_save = v1; + std::valarray<T> v2_save = v2; + swap(v1, v2); + assert(v1.size() == v2_save.size()); + for (int i = 0; i < v1.size(); ++i) + assert(v1[i] == v2_save[i]); + assert(v2.size() == v1_save.size()); + for (int i = 0; i < v2.size(); ++i) + assert(v2[i] == v1_save[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/abs_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/abs_valarray.pass.cpp new file mode 100644 index 000000000000..7d112a61140e --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/abs_valarray.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// abs(const valarray<T>& x); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef double T; + T a1[] = {1.5, -2.5, 3.4, -4.5, -5.0}; + T a3[] = {1.5, 2.5, 3.4, 4.5, 5.0}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = abs(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(v3[i] == a3[i]); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/acos_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/acos_valarray.pass.cpp new file mode 100644 index 000000000000..ef2451d76457 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/acos_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// acos(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {2.6905658417935308e+00, + 2.0943951023931957e+00, + 1.5707963267948966e+00, + 1.0471975511965976e+00, + 7.2273424781341566e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = acos(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/asin_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/asin_valarray.pass.cpp new file mode 100644 index 000000000000..11c7c68d664a --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/asin_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// asin(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-1.1197695149986342e+00, + -5.2359877559829882e-01, + 0.0000000000000000e+00, + 5.2359877559829882e-01, + 8.4806207898148100e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = asin(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..b860413805b8 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_valarray.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// atan2(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a2[] = {-.8, .25, 0.375, -.5, .75}; + T a3[] = {-2.2974386674766221e+00, + -1.1071487177940904e+00, + 0.0000000000000000e+00, + 2.3561944901923448e+00, + 7.8539816339744828e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = atan2(v1, v2); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_value.pass.cpp new file mode 100644 index 000000000000..94ffebf79d8d --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// atan2(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-8.7605805059819342e-01, + -5.8800260354756750e-01, + 0.0000000000000000e+00, + 5.8800260354756750e-01, + 7.8539816339744828e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = atan2(v1, .75); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_value_valarray.pass.cpp new file mode 100644 index 000000000000..360e70ee7cdd --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_value_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// atan2(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {2.4468543773930902e+00, + 2.1587989303424640e+00, + 1.5707963267948966e+00, + 9.8279372324732905e-01, + 7.8539816339744828e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = atan2(.75, v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan_valarray.pass.cpp new file mode 100644 index 000000000000..e66118b1d6de --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// atan(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-7.3281510178650666e-01, + -4.6364760900080615e-01, + 0.0000000000000000e+00, + 4.6364760900080615e-01, + 6.4350110879328437e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = atan(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cos_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cos_valarray.pass.cpp new file mode 100644 index 000000000000..baeb0d067008 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cos_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// cos(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {6.2160996827066450e-01, + 8.7758256189037276e-01, + 1.0000000000000000e+00, + 8.7758256189037276e-01, + 7.3168886887382090e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = cos(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cosh_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cosh_valarray.pass.cpp new file mode 100644 index 000000000000..02a547a54404 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cosh_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// cosh(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {1.4330863854487743e+00, + 1.1276259652063807e+00, + 1.0000000000000000e+00, + 1.1276259652063807e+00, + 1.2946832846768448e+00}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = cosh(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/exp_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/exp_valarray.pass.cpp new file mode 100644 index 000000000000..dce9c5546f78 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/exp_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// exp(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {4.0656965974059911e-01, + 6.0653065971263342e-01, + 1.0000000000000000e+00, + 1.6487212707001282e+00, + 2.1170000166126748e+00}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = exp(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log10_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log10_valarray.pass.cpp new file mode 100644 index 000000000000..2b9908198476 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log10_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// log10(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.5, .75, 1, 3, 7}; + T a3[] = {-3.0102999566398120e-01, + -1.2493873660829995e-01, + 0.0000000000000000e+00, + 4.7712125471966244e-01, + 8.4509804001425681e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = log10(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log_valarray.pass.cpp new file mode 100644 index 000000000000..2c51cd6ed405 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// log(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.5, .75, 1, 3, 7}; + T a3[] = {-6.9314718055994529e-01, + -2.8768207245178090e-01, + 0.0000000000000000e+00, + 1.0986122886681098e+00, + 1.9459101490553132e+00}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = log(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_valarray.pass.cpp new file mode 100644 index 000000000000..37ca74292aad --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_valarray.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// pow(const valarray<T>& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.9, .5, 0., .5, .75}; + T a2[] = {-.8, .25, 0.375, -.5, .75}; + T a3[] = {1.0879426248455297e+00, + 8.4089641525371450e-01, + 0.0000000000000000e+00, + 1.4142135623730949e+00, + 8.0592744886765644e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v2(a2, N); + std::valarray<T> v3 = pow(v1, v2); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_value.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_value.pass.cpp new file mode 100644 index 000000000000..290ddc6f63da --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// pow(const valarray<T>& x, const T& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.9, .5, 0., .5, .75}; + T a3[] = {8.1000000000000005e-01, + 2.5000000000000000e-01, + 0.0000000000000000e+00, + 2.5000000000000000e-01, + 5.6250000000000000e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = pow(v1, 2.0); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_value_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_value_valarray.pass.cpp new file mode 100644 index 000000000000..f52990b4be7d --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_value_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// pow(const T& x, const valarray<T>& y); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.9, .5, 0., .5, .75}; + T a3[] = {1.8660659830736148e+00, + 1.4142135623730951e+00, + 1.0000000000000000e+00, + 1.4142135623730951e+00, + 1.6817928305074290e+00}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = pow(2.0, v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sin_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sin_valarray.pass.cpp new file mode 100644 index 000000000000..f05bd058fd72 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sin_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// sin(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-7.8332690962748330e-01, + -4.7942553860420301e-01, + 0.0000000000000000e+00, + 4.7942553860420301e-01, + 6.8163876002333423e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = sin(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sinh_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sinh_valarray.pass.cpp new file mode 100644 index 000000000000..73dca833bf24 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sinh_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// sinh(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-1.0265167257081753e+00, + -5.2109530549374738e-01, + 0.0000000000000000e+00, + 5.2109530549374738e-01, + 8.2231673193582999e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = sinh(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sqrt_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sqrt_valarray.pass.cpp new file mode 100644 index 000000000000..193dcd21fd1e --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sqrt_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// sqrt(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {.5, .75, 1, 3, 7}; + T a3[] = {7.0710678118654757e-01, + 8.6602540378443860e-01, + 1.0000000000000000e+00, + 1.7320508075688772e+00, + 2.6457513110645907e+00}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = sqrt(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp new file mode 100644 index 000000000000..021dbc4d7754 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// tan(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-1.2601582175503390e+00, + -5.4630248984379048e-01, + 0.0000000000000000e+00, + 5.4630248984379048e-01, + 9.3159645994407259e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = tan(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp new file mode 100644 index 000000000000..4cc58c321af1 --- /dev/null +++ b/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template<class T> +// valarray<T> +// tanh(const valarray<T>& x); + +#include <valarray> +#include <cassert> +#include <sstream> + +bool is_about(double x, double y, int p) +{ + std::ostringstream o; + o.precision(p); + scientific(o); + o << x; + std::string a = o.str(); + o.str(""); + o << y; + return a == o.str(); +} + +int main() +{ + { + typedef double T; + T a1[] = {-.9, -.5, 0., .5, .75}; + T a3[] = {-7.1629787019902447e-01, + -4.6211715726000974e-01, + 0.0000000000000000e+00, + 4.6211715726000974e-01, + 6.3514895238728730e-01}; + const unsigned N = sizeof(a1)/sizeof(a1[0]); + std::valarray<T> v1(a1, N); + std::valarray<T> v3 = tanh(v1); + assert(v3.size() == v1.size()); + for (int i = 0; i < v3.size(); ++i) + assert(is_about(v3[i], a3[i], 10)); + } +} diff --git a/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp b/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp new file mode 100644 index 000000000000..873c4847e8d2 --- /dev/null +++ b/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template <class T> +// unspecified1 +// begin(const valarray<T>& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + const std::valarray<T> v(a, N); + assert(v[0] == 1); + } +} diff --git a/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp b/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp new file mode 100644 index 000000000000..0a39d009fd9b --- /dev/null +++ b/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template <class T> +// unspecified1 +// begin(valarray<T>& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + *begin(v) = 10; + assert(v[0] == 10); + } +} diff --git a/test/std/numerics/numarray/valarray.range/end_const.pass.cpp b/test/std/numerics/numarray/valarray.range/end_const.pass.cpp new file mode 100644 index 000000000000..7363508943bb --- /dev/null +++ b/test/std/numerics/numarray/valarray.range/end_const.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template <class T> +// unspecified1 +// end(const valarray<T>& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + const std::valarray<T> v(a, N); + assert(v[v.size()-1] == 5); + assert(end(v) - begin(v) == v.size()); + } +} diff --git a/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp b/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp new file mode 100644 index 000000000000..f095f5cc35ee --- /dev/null +++ b/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +// template<class T> class valarray; + +// template <class T> +// unspecified1 +// end(valarray<T>& v); + +#include <valarray> +#include <cassert> + +int main() +{ + { + typedef int T; + T a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::valarray<T> v(a, N); + *(end(v) - 1) = 10; + assert(v[v.size()-1] == 10); + assert(end(v) - begin(v) == v.size()); + } +} diff --git a/test/std/numerics/numarray/valarray.syn/nothing_to_do.pass.cpp b/test/std/numerics/numarray/valarray.syn/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numarray/valarray.syn/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numarray/version.pass.cpp b/test/std/numerics/numarray/version.pass.cpp new file mode 100644 index 000000000000..85457d4329ec --- /dev/null +++ b/test/std/numerics/numarray/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <valarray> + +#include <valarray> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp b/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp new file mode 100644 index 000000000000..aae97ef41175 --- /dev/null +++ b/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator Iter, MoveConstructible T> +// requires HasPlus<T, Iter::reference> +// && HasAssign<T, HasPlus<T, Iter::reference>::result_type> +// T +// accumulate(Iter first, Iter last, T init); + +#include <numeric> +#include <cassert> + +#include "test_iterators.h" + +template <class Iter, class T> +void +test(Iter first, Iter last, T init, T x) +{ + assert(std::accumulate(first, last, init) == x); +} + +template <class Iter> +void +test() +{ + int ia[] = {1, 2, 3, 4, 5, 6}; + unsigned sa = sizeof(ia) / sizeof(ia[0]); + test(Iter(ia), Iter(ia), 0, 0); + test(Iter(ia), Iter(ia), 10, 10); + test(Iter(ia), Iter(ia+1), 0, 1); + test(Iter(ia), Iter(ia+1), 10, 11); + test(Iter(ia), Iter(ia+2), 0, 3); + test(Iter(ia), Iter(ia+2), 10, 13); + test(Iter(ia), Iter(ia+sa), 0, 21); + test(Iter(ia), Iter(ia+sa), 10, 31); +} + +int main() +{ + test<input_iterator<const int*> >(); + test<forward_iterator<const int*> >(); + test<bidirectional_iterator<const int*> >(); + test<random_access_iterator<const int*> >(); + test<const int*>(); +} diff --git a/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp b/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp new file mode 100644 index 000000000000..19a872868bf6 --- /dev/null +++ b/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator Iter, MoveConstructible T, +// Callable<auto, const T&, Iter::reference> BinaryOperation> +// requires HasAssign<T, BinaryOperation::result_type> +// && CopyConstructible<BinaryOperation> +// T +// accumulate(Iter first, Iter last, T init, BinaryOperation binary_op); + +#include <numeric> +#include <functional> +#include <cassert> + +#include "test_iterators.h" + +template <class Iter, class T> +void +test(Iter first, Iter last, T init, T x) +{ + assert(std::accumulate(first, last, init, std::multiplies<T>()) == x); +} + +template <class Iter> +void +test() +{ + int ia[] = {1, 2, 3, 4, 5, 6}; + unsigned sa = sizeof(ia) / sizeof(ia[0]); + test(Iter(ia), Iter(ia), 1, 1); + test(Iter(ia), Iter(ia), 10, 10); + test(Iter(ia), Iter(ia+1), 1, 1); + test(Iter(ia), Iter(ia+1), 10, 10); + test(Iter(ia), Iter(ia+2), 1, 2); + test(Iter(ia), Iter(ia+2), 10, 20); + test(Iter(ia), Iter(ia+sa), 1, 720); + test(Iter(ia), Iter(ia+sa), 10, 7200); +} + +int main() +{ + test<input_iterator<const int*> >(); + test<forward_iterator<const int*> >(); + test<bidirectional_iterator<const int*> >(); + test<random_access_iterator<const int*> >(); + test<const int*>(); +} diff --git a/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp new file mode 100644 index 000000000000..46741e1e41b7 --- /dev/null +++ b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator InIter, +// OutputIterator<auto, const InIter::value_type&> OutIter> +// requires HasMinus<InIter::value_type, InIter::value_type> +// && Constructible<InIter::value_type, InIter::reference> +// && OutputIterator<OutIter, +// HasMinus<InIter::value_type, InIter::value_type>::result_type> +// && MoveAssignable<InIter::value_type> +// OutIter +// adjacent_difference(InIter first, InIter last, OutIter result); + +#include <numeric> +#include <cassert> + +#include "test_iterators.h" + +template <class InIter, class OutIter> +void +test() +{ + int ia[] = {15, 10, 6, 3, 1}; + int ir[] = {15, -5, -4, -3, -2}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib)); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class Y; + +class X +{ + int i_; + + X& operator=(const X&); +public: + explicit X(int i) : i_(i) {} + X(const X& x) : i_(x.i_) {} + X& operator=(X&& x) + { + i_ = x.i_; + x.i_ = -1; + return *this; + } + + friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + + friend class Y; +}; + +class Y +{ + int i_; + + Y& operator=(const Y&); +public: + explicit Y(int i) : i_(i) {} + Y(const Y& y) : i_(y.i_) {} + void operator=(const X& x) {i_ = x.i_;} +}; + +#endif + +int main() +{ + test<input_iterator<const int*>, output_iterator<int*> >(); + test<input_iterator<const int*>, forward_iterator<int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<int*> >(); + test<input_iterator<const int*>, random_access_iterator<int*> >(); + test<input_iterator<const int*>, int*>(); + + test<forward_iterator<const int*>, output_iterator<int*> >(); + test<forward_iterator<const int*>, forward_iterator<int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); + test<forward_iterator<const int*>, random_access_iterator<int*> >(); + test<forward_iterator<const int*>, int*>(); + + test<bidirectional_iterator<const int*>, output_iterator<int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); + test<bidirectional_iterator<const int*>, int*>(); + + test<random_access_iterator<const int*>, output_iterator<int*> >(); + test<random_access_iterator<const int*>, forward_iterator<int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<int*> >(); + test<random_access_iterator<const int*>, int*>(); + + test<const int*, output_iterator<int*> >(); + test<const int*, forward_iterator<int*> >(); + test<const int*, bidirectional_iterator<int*> >(); + test<const int*, random_access_iterator<int*> >(); + test<const int*, int*>(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + X x[3] = {X(1), X(2), X(3)}; + Y y[3] = {Y(1), Y(2), Y(3)}; + std::adjacent_difference(x, x+3, y); +#endif +} diff --git a/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp new file mode 100644 index 000000000000..fb0bbdc2836d --- /dev/null +++ b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator InIter, +// OutputIterator<auto, const InIter::value_type&> OutIter, +// Callable<auto, const InIter::value_type&, const InIter::value_type&> BinaryOperation> +// requires Constructible<InIter::value_type, InIter::reference> +// && OutputIterator<OutIter, BinaryOperation::result_type> +// && MoveAssignable<InIter::value_type> +// && CopyConstructible<BinaryOperation> +// OutIter +// adjacent_difference(InIter first, InIter last, OutIter result, BinaryOperation binary_op); + +#include <numeric> +#include <functional> +#include <cassert> + +#include "test_iterators.h" + +template <class InIter, class OutIter> +void +test() +{ + int ia[] = {15, 10, 6, 3, 1}; + int ir[] = {15, 25, 16, 9, 4}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib), + std::plus<int>()); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class Y; + +class X +{ + int i_; + + X& operator=(const X&); +public: + explicit X(int i) : i_(i) {} + X(const X& x) : i_(x.i_) {} + X& operator=(X&& x) + { + i_ = x.i_; + x.i_ = -1; + return *this; + } + + friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + + friend class Y; +}; + +class Y +{ + int i_; + + Y& operator=(const Y&); +public: + explicit Y(int i) : i_(i) {} + Y(const Y& y) : i_(y.i_) {} + void operator=(const X& x) {i_ = x.i_;} +}; + +#endif + + +int main() +{ + test<input_iterator<const int*>, output_iterator<int*> >(); + test<input_iterator<const int*>, forward_iterator<int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<int*> >(); + test<input_iterator<const int*>, random_access_iterator<int*> >(); + test<input_iterator<const int*>, int*>(); + + test<forward_iterator<const int*>, output_iterator<int*> >(); + test<forward_iterator<const int*>, forward_iterator<int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); + test<forward_iterator<const int*>, random_access_iterator<int*> >(); + test<forward_iterator<const int*>, int*>(); + + test<bidirectional_iterator<const int*>, output_iterator<int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); + test<bidirectional_iterator<const int*>, int*>(); + + test<random_access_iterator<const int*>, output_iterator<int*> >(); + test<random_access_iterator<const int*>, forward_iterator<int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<int*> >(); + test<random_access_iterator<const int*>, int*>(); + + test<const int*, output_iterator<int*> >(); + test<const int*, forward_iterator<int*> >(); + test<const int*, bidirectional_iterator<int*> >(); + test<const int*, random_access_iterator<int*> >(); + test<const int*, int*>(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + X x[3] = {X(1), X(2), X(3)}; + Y y[3] = {Y(1), Y(2), Y(3)}; + std::adjacent_difference(x, x+3, y, std::minus<X>()); +#endif +} diff --git a/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp b/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp new file mode 100644 index 000000000000..68a8c49b82ba --- /dev/null +++ b/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator Iter1, InputIterator Iter2, MoveConstructible T> +// requires HasMultiply<Iter1::reference, Iter2::reference> +// && HasPlus<T, HasMultiply<Iter1::reference, Iter2::reference>::result_type> +// && HasAssign<T, +// HasPlus<T, +// HasMultiply<Iter1::reference, +// Iter2::reference>::result_type>::result_type> +// T +// inner_product(Iter1 first1, Iter1 last1, Iter2 first2, T init); + +#include <numeric> +#include <cassert> + +#include "test_iterators.h" + +template <class Iter1, class Iter2, class T> +void +test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) +{ + assert(std::inner_product(first1, last1, first2, init) == x); +} + +template <class Iter1, class Iter2> +void +test() +{ + int a[] = {1, 2, 3, 4, 5, 6}; + int b[] = {6, 5, 4, 3, 2, 1}; + unsigned sa = sizeof(a) / sizeof(a[0]); + test(Iter1(a), Iter1(a), Iter2(b), 0, 0); + test(Iter1(a), Iter1(a), Iter2(b), 10, 10); + test(Iter1(a), Iter1(a+1), Iter2(b), 0, 6); + test(Iter1(a), Iter1(a+1), Iter2(b), 10, 16); + test(Iter1(a), Iter1(a+2), Iter2(b), 0, 16); + test(Iter1(a), Iter1(a+2), Iter2(b), 10, 26); + test(Iter1(a), Iter1(a+sa), Iter2(b), 0, 56); + test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 66); +} + +int main() +{ + test<input_iterator<const int*>, input_iterator<const int*> >(); + test<input_iterator<const int*>, forward_iterator<const int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<input_iterator<const int*>, random_access_iterator<const int*> >(); + test<input_iterator<const int*>, const int*>(); + + test<forward_iterator<const int*>, input_iterator<const int*> >(); + test<forward_iterator<const int*>, forward_iterator<const int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<forward_iterator<const int*>, random_access_iterator<const int*> >(); + test<forward_iterator<const int*>, const int*>(); + + test<bidirectional_iterator<const int*>, input_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, const int*>(); + + test<random_access_iterator<const int*>, input_iterator<const int*> >(); + test<random_access_iterator<const int*>, forward_iterator<const int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); + test<random_access_iterator<const int*>, const int*>(); + + test<const int*, input_iterator<const int*> >(); + test<const int*, forward_iterator<const int*> >(); + test<const int*, bidirectional_iterator<const int*> >(); + test<const int*, random_access_iterator<const int*> >(); + test<const int*, const int*>(); +} diff --git a/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp b/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp new file mode 100644 index 000000000000..31dbbd0bec50 --- /dev/null +++ b/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator Iter1, InputIterator Iter2, MoveConstructible T, +// class BinaryOperation1, +// Callable<auto, Iter1::reference, Iter2::reference> BinaryOperation2> +// requires Callable<BinaryOperation1, const T&, BinaryOperation2::result_type> +// && HasAssign<T, BinaryOperation1::result_type> +// && CopyConstructible<BinaryOperation1> +// && CopyConstructible<BinaryOperation2> +// T +// inner_product(Iter1 first1, Iter1 last1, Iter2 first2, +// T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); + +#include <numeric> +#include <functional> +#include <cassert> + +#include "test_iterators.h" + +template <class Iter1, class Iter2, class T> +void +test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) +{ + assert(std::inner_product(first1, last1, first2, init, + std::multiplies<int>(), std::plus<int>()) == x); +} + +template <class Iter1, class Iter2> +void +test() +{ + int a[] = {1, 2, 3, 4, 5, 6}; + int b[] = {6, 5, 4, 3, 2, 1}; + unsigned sa = sizeof(a) / sizeof(a[0]); + test(Iter1(a), Iter1(a), Iter2(b), 1, 1); + test(Iter1(a), Iter1(a), Iter2(b), 10, 10); + test(Iter1(a), Iter1(a+1), Iter2(b), 1, 7); + test(Iter1(a), Iter1(a+1), Iter2(b), 10, 70); + test(Iter1(a), Iter1(a+2), Iter2(b), 1, 49); + test(Iter1(a), Iter1(a+2), Iter2(b), 10, 490); + test(Iter1(a), Iter1(a+sa), Iter2(b), 1, 117649); + test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 1176490); +} + +int main() +{ + test<input_iterator<const int*>, input_iterator<const int*> >(); + test<input_iterator<const int*>, forward_iterator<const int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<input_iterator<const int*>, random_access_iterator<const int*> >(); + test<input_iterator<const int*>, const int*>(); + + test<forward_iterator<const int*>, input_iterator<const int*> >(); + test<forward_iterator<const int*>, forward_iterator<const int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<forward_iterator<const int*>, random_access_iterator<const int*> >(); + test<forward_iterator<const int*>, const int*>(); + + test<bidirectional_iterator<const int*>, input_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >(); + test<bidirectional_iterator<const int*>, const int*>(); + + test<random_access_iterator<const int*>, input_iterator<const int*> >(); + test<random_access_iterator<const int*>, forward_iterator<const int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); + test<random_access_iterator<const int*>, const int*>(); + + test<const int*, input_iterator<const int*> >(); + test<const int*, forward_iterator<const int*> >(); + test<const int*, bidirectional_iterator<const int*> >(); + test<const int*, random_access_iterator<const int*> >(); + test<const int*, const int*>(); +} diff --git a/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp b/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp new file mode 100644 index 000000000000..eb7c8373ad58 --- /dev/null +++ b/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <class ForwardIterator, class T> +// void iota(ForwardIterator first, ForwardIterator last, T value); + +#include <numeric> +#include <cassert> + +#include "test_iterators.h" + +template <class InIter> +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {5, 6, 7, 8, 9}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + std::iota(InIter(ia), InIter(ia+s), 5); + for (unsigned i = 0; i < s; ++i) + assert(ia[i] == ir[i]); +} + +int main() +{ + test<forward_iterator<int*> >(); + test<bidirectional_iterator<int*> >(); + test<random_access_iterator<int*> >(); + test<int*>(); +} diff --git a/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp b/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp new file mode 100644 index 000000000000..cb468e019bb1 --- /dev/null +++ b/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template <InputIterator InIter, OutputIterator<auto, const InIter::value_type&> OutIter> +// requires HasPlus<InIter::value_type, InIter::reference> +// && HasAssign<InIter::value_type, +// HasPlus<InIter::value_type, InIter::reference>::result_type> +// && Constructible<InIter::value_type, InIter::reference> +// OutIter +// partial_sum(InIter first, InIter last, OutIter result); + +#include <numeric> +#include <cassert> + +#include "test_iterators.h" + +template <class InIter, class OutIter> +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {1, 3, 6, 10, 15}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib)); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +int main() +{ + test<input_iterator<const int*>, output_iterator<int*> >(); + test<input_iterator<const int*>, forward_iterator<int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<int*> >(); + test<input_iterator<const int*>, random_access_iterator<int*> >(); + test<input_iterator<const int*>, int*>(); + + test<forward_iterator<const int*>, output_iterator<int*> >(); + test<forward_iterator<const int*>, forward_iterator<int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); + test<forward_iterator<const int*>, random_access_iterator<int*> >(); + test<forward_iterator<const int*>, int*>(); + + test<bidirectional_iterator<const int*>, output_iterator<int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); + test<bidirectional_iterator<const int*>, int*>(); + + test<random_access_iterator<const int*>, output_iterator<int*> >(); + test<random_access_iterator<const int*>, forward_iterator<int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<int*> >(); + test<random_access_iterator<const int*>, int*>(); + + test<const int*, output_iterator<int*> >(); + test<const int*, forward_iterator<int*> >(); + test<const int*, bidirectional_iterator<int*> >(); + test<const int*, random_access_iterator<int*> >(); + test<const int*, int*>(); +} diff --git a/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp b/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp new file mode 100644 index 000000000000..d8f2a93e41ce --- /dev/null +++ b/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +// template<InputIterator InIter, +// OutputIterator<auto, const InIter::value_type&> OutIter, +// Callable<auto, const InIter::value_type&, InIter::reference> BinaryOperation> +// requires HasAssign<InIter::value_type, BinaryOperation::result_type> +// && Constructible<InIter::value_type, InIter::reference> +// && CopyConstructible<BinaryOperation> +// OutIter +// partial_sum(InIter first, InIter last, OutIter result, BinaryOperation binary_op); + +#include <numeric> +#include <functional> +#include <cassert> + +#include "test_iterators.h" + +template <class InIter, class OutIter> +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {1, -1, -4, -8, -13}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib), std::minus<int>()); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +int main() +{ + test<input_iterator<const int*>, output_iterator<int*> >(); + test<input_iterator<const int*>, forward_iterator<int*> >(); + test<input_iterator<const int*>, bidirectional_iterator<int*> >(); + test<input_iterator<const int*>, random_access_iterator<int*> >(); + test<input_iterator<const int*>, int*>(); + + test<forward_iterator<const int*>, output_iterator<int*> >(); + test<forward_iterator<const int*>, forward_iterator<int*> >(); + test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); + test<forward_iterator<const int*>, random_access_iterator<int*> >(); + test<forward_iterator<const int*>, int*>(); + + test<bidirectional_iterator<const int*>, output_iterator<int*> >(); + test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); + test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); + test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); + test<bidirectional_iterator<const int*>, int*>(); + + test<random_access_iterator<const int*>, output_iterator<int*> >(); + test<random_access_iterator<const int*>, forward_iterator<int*> >(); + test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); + test<random_access_iterator<const int*>, random_access_iterator<int*> >(); + test<random_access_iterator<const int*>, int*>(); + + test<const int*, output_iterator<int*> >(); + test<const int*, forward_iterator<int*> >(); + test<const int*, bidirectional_iterator<int*> >(); + test<const int*, random_access_iterator<int*> >(); + test<const int*, int*>(); +} diff --git a/test/std/numerics/numeric.ops/version.pass.cpp b/test/std/numerics/numeric.ops/version.pass.cpp new file mode 100644 index 000000000000..fb6e0a1063ce --- /dev/null +++ b/test/std/numerics/numeric.ops/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <numeric> + +#include <numeric> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/numeric.requirements/nothing_to_do.pass.cpp b/test/std/numerics/numeric.requirements/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numeric.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/numerics.general/nothing_to_do.pass.cpp b/test/std/numerics/numerics.general/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/numerics.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/nothing_to_do.pass.cpp b/test/std/numerics/rand/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.adapt/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.adapt/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/assign.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/assign.pass.cpp new file mode 100644 index 000000000000..18c8947af6ee --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/assign.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// discard_block_engine& operator=(const discard_block_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24 E; + E e1(2); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48 E; + E e1(3); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/copy.pass.cpp new file mode 100644 index 000000000000..d6c64fa37dcc --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/copy.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// discard_block_engine(const discard_block_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24 E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48 E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000000..d6b8b33ad01b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// explicit discard_block_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::ranlux24_base Engine; + typedef std::ranlux24 Adaptor; + Engine e; + Adaptor a(e); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp new file mode 100644 index 000000000000..1e8e2fe6fbbe --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// explicit discard_block_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::ranlux24_base Engine; + typedef std::ranlux24 Adaptor; + Engine e; + Engine e0 = e; + Adaptor a(std::move(e0)); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..dba254f1a73e --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_result_type.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// explicit discard_block_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "15136306 8587749 2346244 16479026 15515802 9510553 " + "16090340 14501685 13839944 10789678 11581259 9590790 5840316 5953700 " + "13398366 8134459 16629731 6851902 15583892 1317475 4231148 9092691 " + "5707268 2355175 0 0"; + std::ranlux24 e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "10880375256626 126660097854724 33643165434010 " + "78293780235492 179418984296008 96783156950859 238199764491708 " + "34339434557790 155299155394531 29014415493780 209265474179052 " + "263777435457028 0 0"; + std::ranlux48 e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..b64d4b31682b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/ctor_sseq.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// template<class Sseq> explicit discard_block_engine(Sseq& q); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 " + "3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 " + "14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 " + "889045 0 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::ranlux24 e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "241408498702289 172342669275054 191026374555184 " + "61020585639411 231929771458953 142769679250755 198672786411514 " + "183712717244841 227473912549724 62843577252444 68782400568421 " + "159248704678140 0 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::ranlux48 e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/default.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/default.pass.cpp new file mode 100644 index 000000000000..ffdaebc17142 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/default.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// explicit discard_block_engine(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24 e1; + std::ranlux24 e2(std::ranlux24_base::default_seed); + assert(e1 == e2); + assert(e1() == 15039276); +} + +void +test2() +{ + std::ranlux48 e1; + std::ranlux48 e2(std::ranlux48_base::default_seed); + assert(e1 == e2); + assert(e1() == 23459059301164ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/discard.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/discard.pass.cpp new file mode 100644 index 000000000000..2dada0d6345f --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/discard.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// void discard(unsigned long long z); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24 e1; + std::ranlux24 e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +void +test2() +{ + std::ranlux48 e1; + std::ranlux48 e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/eval.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/eval.pass.cpp new file mode 100644 index 000000000000..f819d6a97699 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/eval.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// result_type operator()(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24 e; + assert(e() == 15039276u); + assert(e() == 16323925u); + assert(e() == 14283486u); +} + +void +test2() +{ + std::ranlux48 e; + assert(e() == 23459059301164ull); + assert(e() == 28639057539807ull); + assert(e() == 276846226770426ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/io.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/io.pass.cpp new file mode 100644 index 000000000000..4b742f06a5eb --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/io.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// template <class charT, class traits, +// class Engine, size_t p, size_t r> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const discard_block_engine<Engine, p, r>& x); +// +// template <class charT, class traits, +// class Engine, size_t p, size_t r> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// discard_block_engine<Engine, p, r>& x); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24 E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48 E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/result_type.pass.cpp new file mode 100644 index 000000000000..2634aba3823b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/result_type.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine +// { +// public: +// // types +// typedef typename Engine::result_type result_type; + +#include <random> +#include <type_traits> + +void +test1() +{ + static_assert((std::is_same< + std::ranlux24::result_type, + std::uint_fast32_t>::value), ""); +} + +void +test2() +{ + static_assert((std::is_same< + std::ranlux48::result_type, + std::uint_fast64_t>::value), ""); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_result_type.pass.cpp new file mode 100644 index 000000000000..6a5ff14f77ab --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_result_type.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::ranlux24 E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +void +test2() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::ranlux48 E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_sseq.pass.cpp new file mode 100644 index 000000000000..0da09a379e6f --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/seed_sseq.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +void +test1() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::ranlux24 e1; + std::ranlux24 e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +void +test2() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::ranlux48 e1; + std::ranlux48 e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp new file mode 100644 index 000000000000..53e4c29affc4 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t p, size_t r> +// class discard_block_engine +// { +// public: +// // types +// typedef typename Engine::result_type result_type; +// +// // engine characteristics +// static constexpr size_t block_size = p; +// static constexpr size_t used_block = r; +// static constexpr result_type min() { return Engine::min(); } +// static constexpr result_type max() { return Engine::max(); } + +#include <random> +#include <type_traits> +#include <cassert> + +template <class _Tp> +void where(const _Tp &) {} + +void +test1() +{ + typedef std::ranlux24 E; + static_assert((E::block_size == 223), ""); + static_assert((E::used_block == 23), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFF)/*, ""*/); + where(E::block_size); + where(E::used_block); +} + +void +test2() +{ + typedef std::ranlux48 E; + static_assert((E::block_size == 389), ""); + static_assert((E::used_block == 11), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFFFFFFull)/*, ""*/); + where(E::block_size); + where(E::used_block); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/assign.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/assign.pass.cpp new file mode 100644 index 000000000000..e4cd4f7396be --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/assign.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// independent_bits_engine& operator=(const independent_bits_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E; + E e1(2); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E; + E e1(3); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/copy.pass.cpp new file mode 100644 index 000000000000..e3e497ec8c6e --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/copy.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// independent_bits_engine(const independent_bits_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000000..193f5c33ec11 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// explicit independent_bits_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::mt19937 Engine; + typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor; + Engine e; + Adaptor a(e); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp new file mode 100644 index 000000000000..60a661d398f6 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// explicit independent_bits_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::mt19937 Engine; + typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor; + Engine e; + Engine e0 = e; + Adaptor a(std::move(e0)); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..8e8d3091a4e3 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_result_type.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// explicit independent_bits_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "15136306 8587749 2346244 16479026 15515802 9510553 " + "16090340 14501685 13839944 10789678 11581259 9590790 5840316 5953700 " + "13398366 8134459 16629731 6851902 15583892 1317475 4231148 9092691 " + "5707268 2355175 0 0"; + std::independent_bits_engine<std::ranlux24, 32, unsigned> e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "10880375256626 126660097854724 33643165434010 " + "78293780235492 179418984296008 96783156950859 238199764491708 " + "34339434557790 155299155394531 29014415493780 209265474179052 " + "263777435457028 0 0"; + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..7965f4397f5a --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_sseq.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// template<class Sseq> explicit independent_bits_engine(Sseq& q); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 " + "3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 " + "14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 " + "889045 0 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::independent_bits_engine<std::ranlux24, 32, unsigned> e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "241408498702289 172342669275054 191026374555184 " + "61020585639411 231929771458953 142769679250755 198672786411514 " + "183712717244841 227473912549724 62843577252444 68782400568421 " + "159248704678140 0 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/default.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/default.pass.cpp new file mode 100644 index 000000000000..ccb6f379d50c --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/default.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// explicit independent_bits_engine(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::independent_bits_engine<std::ranlux24, 32, unsigned> e1; + std::independent_bits_engine<std::ranlux24, 32, unsigned> e2(std::ranlux24_base::default_seed); + assert(e1 == e2); + assert(e1() == 2066486613); +} + +void +test2() +{ + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1; + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2(std::ranlux48_base::default_seed); + assert(e1 == e2); + assert(e1() == 18223106896348967647ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/discard.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/discard.pass.cpp new file mode 100644 index 000000000000..2a356a1c80db --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/discard.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// void discard(unsigned long long z); + +#include <random> +#include <cassert> + +void +test1() +{ + std::independent_bits_engine<std::ranlux24, 32, unsigned> e1; + std::independent_bits_engine<std::ranlux24, 32, unsigned> e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +void +test2() +{ + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1; + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/eval.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/eval.pass.cpp new file mode 100644 index 000000000000..1c2b2a80c59b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/eval.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// result_type operator()(); + +#include <random> +#include <cassert> + +template <class UIntType, UIntType Min, UIntType Max> +class rand1 +{ +public: + // types + typedef UIntType result_type; + +private: + result_type x_; + + static_assert(Min < Max, "rand1 invalid parameters"); +public: + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR + // Workaround for lack of constexpr in C++03 + static const result_type _Min = Min; + static const result_type _Max = Max; +#endif + + static _LIBCPP_CONSTEXPR result_type min() {return Min;} + static _LIBCPP_CONSTEXPR result_type max() {return Max;} + + explicit rand1(result_type sd = Min) : x_(sd) + { + if (x_ > Max) + x_ = Max; + } + + result_type operator()() + { + result_type r = x_; + if (x_ < Max) + ++x_; + else + x_ = Min; + return r; + } +}; + +void +test1() +{ + typedef std::independent_bits_engine<rand1<unsigned, 0, 10>, 16, unsigned> E; + + E e; + assert(e() == 6958); +} + +void +test2() +{ + typedef std::independent_bits_engine<rand1<unsigned, 0, 100>, 16, unsigned> E; + + E e; + assert(e() == 66); +} + +void +test3() +{ + typedef std::independent_bits_engine<rand1<unsigned, 0, 0xFFFFFFFF>, 32, unsigned> E; + + E e(5); + assert(e() == 5); +} + +void +test4() +{ + typedef std::independent_bits_engine<rand1<unsigned, 0, 0xFFFFFFFF>, 7, unsigned> E; + + E e(129); + assert(e() == 1); +} + +void +test5() +{ + typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 1, unsigned> E; + + E e(6); + assert(e() == 1); +} + +void +test6() +{ + typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 11, unsigned> E; + + E e(6); + assert(e() == 1365); +} + +void +test7() +{ + typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 32, unsigned> E; + + E e(6); + assert(e() == 2863311530u); +} + +void +test8() +{ + typedef std::independent_bits_engine<std::mt19937, 64, unsigned long long> E; + + E e(6); + assert(e() == 16470362623952407241ull); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/io.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/io.pass.cpp new file mode 100644 index 000000000000..9bcf06488247 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/io.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// template <class charT, class traits, +// class Engine, size_t w, class UIntType> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const independent_bits_engine<Engine, w, UIntType>& x); +// +// template <class charT, class traits, +// class Engine, size_t w, class UIntType> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// independent_bits_engine<Engine, w, UIntType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +void +test2() +{ + typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/result_type.pass.cpp new file mode 100644 index 000000000000..78040ad987d1 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/result_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine +// { +// public: +// // types +// typedef UIntType result_type; + +#include <random> +#include <type_traits> + +template <class UIntType, UIntType Min, UIntType Max> +class rand1 +{ +public: + // types + typedef UIntType result_type; + +private: + result_type x_; + + static_assert(Min < Max, "rand1 invalid parameters"); +public: + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR + // Workaround for lack of constexpr in C++03 + static const result_type _Min = Min; + static const result_type _Max = Max; +#endif + + static _LIBCPP_CONSTEXPR result_type min() {return Min;} + static _LIBCPP_CONSTEXPR result_type max() {return Max;} + + explicit rand1(result_type sd = Min) : x_(sd) + { + if (x_ < Min) + x_ = Min; + if (x_ > Max) + x_ = Max; + } + + result_type operator()() + { + result_type r = x_; + if (x_ < Max) + ++x_; + else + x_ = Min; + return r; + } +}; + +void +test1() +{ + static_assert((std::is_same< + std::independent_bits_engine<rand1<unsigned long, 0, 10>, 16, unsigned>::result_type, + unsigned>::value), ""); +} + +void +test2() +{ + static_assert((std::is_same< + std::independent_bits_engine<rand1<unsigned long, 0, 10>, 16, unsigned long long>::result_type, + unsigned long long>::value), ""); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_result_type.pass.cpp new file mode 100644 index 000000000000..e8c24ca5fee9 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_result_type.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +void +test2() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_sseq.pass.cpp new file mode 100644 index 000000000000..ec83fff7f83b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_sseq.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +void +test1() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::independent_bits_engine<std::ranlux24, 32, unsigned> e1; + std::independent_bits_engine<std::ranlux24, 32, unsigned> e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +void +test2() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1; + std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp new file mode 100644 index 000000000000..20ca7d5510bf --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t w, class UIntType> +// class independent_bits_engine +// { +// public: +// // types +// typedef UIntType result_type; +// +// // engine characteristics +// static constexpr result_type min() { return 0; } +// static constexpr result_type max() { return 2^w - 1; } + +#include <random> +#include <type_traits> +#include <cassert> + +void +test1() +{ + typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E; + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/); +} + +void +test2() +{ + typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E; + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/assign.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/assign.pass.cpp new file mode 100644 index 000000000000..dae8c7c919af --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/assign.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// shuffle_order_engine& operator=(const shuffle_order_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::knuth_b E; + E e1(2); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/copy.pass.cpp new file mode 100644 index 000000000000..c9e9893dee4b --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/copy.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// shuffle_order_engine(const shuffle_order_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::knuth_b E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000000..a20c494f334c --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// explicit shuffle_order_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::minstd_rand0 Engine; + typedef std::knuth_b Adaptor; + Engine e; + Adaptor a(e); + for (unsigned k = 0; k <= Adaptor::table_size; ++k) + e(); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp new file mode 100644 index 000000000000..9811787821d9 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// explicit shuffle_order_engine(const Engine& e); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::minstd_rand0 Engine; + typedef std::knuth_b Adaptor; + Engine e; + Engine e0 = e; + Adaptor a(std::move(e0)); + for (unsigned k = 0; k <= Adaptor::table_size; ++k) + e(); + assert(a.base() == e); + } +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..320249497289 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_result_type.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// explicit shuffle_order_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "1771550148 168070 677268843 1194115201 1259501992 " + "703671065 407145426 1010275440 1693606898 1702877348 745024267 " + "1793193459 416963415 664975744 742430420 1148079870 637806795 " + "1527921388 165317290 1791337459 1435426120 375508442 1863429808 " + "1910758855 653618747 991426424 578291095 1974930990 1157900898 " + "343583572 25567821 221638147 1335692731 1341167826 1019292670 " + "774852571 606325389 700907908 1211405961 1955012967 1403137269 " + "1010152376 1772753897 486628401 1145807831 1106352968 1560917450 " + "679350398 1819071734 1561434646 781928982 1427964481 1669276942 " + "811199786 1608612146 1272705739 1428231253 1857946652 2097152784 " + "197742477 1300609030 99924397 97128425 349867255 408729299 1860625187 " + "2018133942 1420442476 1948474080 1025729457 1583749330 15184745 " + "1806938869 1655319056 296727307 638820415 1383963552 880037807 " + "1075545360 1321008721 1507631161 597371974 544717293 340756290 " + "1899563128 1465595994 634440068 777915521 545718511 2135841687 " + "1902073804 712854586 135760289 1095544109 285050585 1956649285 " + "987446484 259432572 891434194 1488577086 330596852 801096775 " + "1458514382 1872871416 1682074633 1153627723 1538775345 51662594 " + "709823970 739804705 2114844452 1188863267 1037076781 1172179215 " + "1948572574 533634468 902793804 1283497773 273836696 315894151 " + "653420473 1954002600 1601768276 64415940 306945492 577163950 " + "210874151 813838307 857078006 1737226413 376658679 1868110244 " + "1117951768 1080937173 1746896638 1842856729 1883887269 2141922362 " + "1020763473 1872318475 978729834 1935067665 1189895487 1205729145 " + "1034046923 1788963337 188263312 898072753 1393688555 1119406056 " + "1900835472 1375045132 1312008157 559007303 2142269543 413383599 " + "628550348 573639243 1100665718 464587168 65992084 1027393936 " + "1641360472 1918007189 69800406 609352380 35938117 569027612 902394793 " + "1019770837 221470752 669768613 1839284764 1979413630 1335703733 " + "1526078440 1403144959 1139398206 753967943 1785700701 1187714882 " + "1063522909 1123137582 192083544 680202567 1109090588 327456556 " + "1709233078 191596027 1076438936 1306955024 1530346852 127901445 " + "8455468 377129974 1199230721 1336700752 1103107597 703058228 " + "844612202 530372344 1910850558 47387421 1871435357 1168551137 " + "1101007744 1918050856 803711675 309982095 73743043 301259382 " + "1647477295 1644236294 859823662 638826571 1487427444 335916581 " + "15468904 140348241 895842081 410006250 1847504174 536600445 " + "1359845362 1400027760 288242141 1910039802 1453396858 1761991428 " + "2137921913 357210187 1414819544 1933136424 943782705 841706193 " + "1081202962 1919045067 333546776 988345562 337850989 314809455 " + "1750287624 853099962 1450233962 142805884 1399258689 247367726 " + "2128513937 1151147433 654730608 351121428 12778440 18876380 " + "1575222551 587014441 411835569 380613902 1771550148"; + std::knuth_b e1(10); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..a08df07b3a87 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_sseq.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// template<class Sseq> explicit shuffle_order_engine(Sseq& q); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "1894661934 884942216 1899568837 1561547157 525417712 " + "242729120 1476874187 1208468883 1983666902 1953485886 1507290666 " + "1317123450 632390874 696850315 1734917114 218976032 1690682513 " + "1944862534 456017951 2072049961 1348874775 1700965693 828093387 " + "2071522749 1077957279 1055942061 413360419 238964088 475007126 " + "1248050783 1516729632 1044035134 9617501 580065782 1737324341 " + "2022534575 219953662 941840747 415472792 1381878747 200458524 " + "1852054372 1849850586 1318041283 1026024576 101363422 660501483 " + "705453438 298717379 1873705814 673416290 868766340 614560427 " + "1668238166 532360730 969915708 1972423626 1966307090 97417947 " + "920896215 588041576 495024338 522400288 1068491480 878048146 " + "1995051285 17282737 560668414 2143274709 127339385 1299331283 " + "99667038 66663006 1566161755 773555006 272986904 1065825536 " + "1168683925 1185292013 1144552919 1489883454 811887358 279732868 " + "628609193 1562647158 1833265343 1742736292 639398211 357562689 " + "896869717 501615326 1775469607 1032409784 43371928 955037563 " + "1023543663 1354331571 1071539244 562210166 138213162 1518791327 " + "1335204647 1727874626 2114964448 1058152392 1055171537 348065433 " + "190278003 399246038 1389247438 1639480282 382424917 2144508195 " + "1531185764 1342593547 1359065400 1176108308 1412845568 968776497 " + "5573525 1332437854 323541262 329396230 2097079291 1110029273 " + "1071549822 739994612 1011644107 1074473050 478563727 894301674 " + "290189565 280656618 1121689914 1630931232 579945916 1870220126 " + "71516543 1535179528 1893792038 1107650479 1893348357 93154853 " + "138035708 683805596 1535656875 1326628479 1469623399 1751042846 " + "661214234 1947241260 1780560187 690441964 1403944207 1687457460 " + "1428487938 1877084153 1618585041 1383427538 461185097 869443256 " + "1254069404 1739961370 1245924391 138197640 1257913073 1915996843 " + "641653536 1755587965 1889101622 1732723706 2009073422 1611621773 " + "315899200 738279016 94909546 1711873548 1620302377 181922632 " + "1704446343 1345319468 2076463060 357902023 157605314 1025175647 " + "865799248 138769064 124418006 1591838311 675218651 1096276609 " + "1858759850 732186041 769493777 735387805 894450150 638142050 " + "720101232 1671055379 636619387 898507955 118193981 63865192 " + "1787942091 204050966 2100684950 1580797970 1951284753 1020070334 " + "960149537 1041144801 823914651 558983501 1742229329 708805658 " + "804904097 1023665826 1260041465 1180659188 590074436 301564006 " + "324841922 714752380 1967212989 290476911 815113546 815183409 " + "1989370850 1182975807 870784323 171062356 1711897606 2024645183 " + "1333203966 314683764 1785282634 603713754 1904315050 1874254109 " + "1298675767 1967311508 1946285744 753588304 1847558969 1457540010 " + "528986741 97857407 1864449494 1868752281 1171249392 1353422942 " + "832597170 457192338 335135800 1925268166 1845956613 296546482 " + "1894661934"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::knuth_b e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/default.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/default.pass.cpp new file mode 100644 index 000000000000..7b4bc582095f --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/default.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// explicit shuffle_order_engine(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::knuth_b e1; + std::knuth_b e2(std::minstd_rand0::default_seed); + assert(e1 == e2); + assert(e1() == 152607844u); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/discard.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/discard.pass.cpp new file mode 100644 index 000000000000..6e04e26c7e55 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/discard.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// void discard(unsigned long long z); + +#include <random> +#include <cassert> + +void +test1() +{ + std::knuth_b e1; + std::knuth_b e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp new file mode 100644 index 000000000000..c218c17dde69 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// result_type operator()(); + +#include <random> +#include <cassert> + +template <class UIntType, UIntType Min, UIntType Max> +class rand1 +{ +public: + // types + typedef UIntType result_type; + +private: + result_type x_; + + static_assert(Min < Max, "rand1 invalid parameters"); +public: + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR + // Workaround for lack of constexpr in C++03 + static const result_type _Min = Min; + static const result_type _Max = Max; +#endif + + static _LIBCPP_CONSTEXPR result_type min() {return Min;} + static _LIBCPP_CONSTEXPR result_type max() {return Max;} + + explicit rand1(result_type sd = Min) : x_(sd) + { + if (x_ > Max) + x_ = Max; + } + + result_type operator()() + { + result_type r = x_; + if (x_ < Max) + ++x_; + else + x_ = Min; + return r; + } +}; + +void +test1() +{ + typedef std::knuth_b E; + + E e; + assert(e() == 152607844u); +} + +void +test2() +{ + typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0; + typedef std::shuffle_order_engine<E0, 101> E; + E e; + e.discard(400); + assert(e() == 501); +} + +void +test3() +{ + typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0; + typedef std::shuffle_order_engine<E0, 100> E; + E e; + e.discard(400); + assert(e() == 500); +} + +int main() +{ + test1(); + test2(); + test3(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/io.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/io.pass.cpp new file mode 100644 index 000000000000..6c8fdb998bfd --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/io.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// template <class charT, class traits, +// class Engine, size_t k> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const shuffle_order_engine<Engine, k>& x); +// +// template <class charT, class traits, +// class Engine, size_t k> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// shuffle_order_engine<Engine, k>& x); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + typedef std::knuth_b E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/result_type.pass.cpp new file mode 100644 index 000000000000..3271d933cb27 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/result_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine +// { +// public: +// // types +// typedef typename Engine::result_type result_type; + +#include <random> +#include <type_traits> + +template <class UIntType, UIntType Min, UIntType Max> +class rand1 +{ +public: + // types + typedef UIntType result_type; + +private: + result_type x_; + + static_assert(Min < Max, "rand1 invalid parameters"); +public: + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR + // Workaround for lack of constexpr in C++03 + static const result_type _Min = Min; + static const result_type _Max = Max; +#endif + + static _LIBCPP_CONSTEXPR result_type min() {return Min;} + static _LIBCPP_CONSTEXPR result_type max() {return Max;} + + explicit rand1(result_type sd = Min) : x_(sd) + { + if (x_ < Min) + x_ = Min; + if (x_ > Max) + x_ = Max; + } + + result_type operator()() + { + result_type r = x_; + if (x_ < Max) + ++x_; + else + x_ = Min; + return r; + } +}; + +void +test1() +{ + static_assert((std::is_same< + std::shuffle_order_engine<rand1<unsigned long, 0, 10>, 16>::result_type, + unsigned long>::value), ""); +} + +void +test2() +{ + static_assert((std::is_same< + std::shuffle_order_engine<rand1<unsigned long long, 0, 10>, 16>::result_type, + unsigned long long>::value), ""); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_result_type.pass.cpp new file mode 100644 index 000000000000..57ded845e1ee --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_result_type.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::knuth_b E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_sseq.pass.cpp new file mode 100644 index 000000000000..4b4b099bce41 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/seed_sseq.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +void +test1() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::knuth_b e1; + std::knuth_b e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp new file mode 100644 index 000000000000..eb42d644d301 --- /dev/null +++ b/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class Engine, size_t k> +// class shuffle_order_engine +// { +// public: +// // types +// typedef typename Engine::result_type result_type; +// +// // engine characteristics +// static constexpr size_t table_size = k; +// static constexpr result_type min() { return Engine::min; } +// static constexpr result_type max() { return Engine::max; } + +#include <random> +#include <type_traits> +#include <cassert> + +template <class _Tp> +void where(const _Tp &) {} + +void +test1() +{ + typedef std::knuth_b E; + static_assert(E::table_size == 256, ""); + /*static_*/assert((E::min() == 1)/*, ""*/); + /*static_*/assert((E::max() == 2147483646)/*, ""*/); + where(E::table_size); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.device/ctor.pass.cpp b/test/std/numerics/rand/rand.device/ctor.pass.cpp new file mode 100644 index 000000000000..97f46b26aa27 --- /dev/null +++ b/test/std/numerics/rand/rand.device/ctor.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class random_device; + +// explicit random_device(const string& token = implementation-defined); + +// For the following ctors, the standard states: "The semantics and default +// value of the token parameter are implementation-defined". Implementations +// therefore aren't required to accept any string, but the default shouldn't +// throw. + +#include <random> +#include <cassert> +#include <unistd.h> + +bool is_valid_random_device(const std::string &token) { +#if defined(_LIBCPP_USING_DEV_RANDOM) + // Not an exhaustive list: they're the only tokens that are tested below. + return token == "/dev/urandom" || token == "/dev/random"; +#else + return token == "/dev/urandom"; +#endif +} + +void check_random_device_valid(const std::string &token) { + std::random_device r(token); +} + +void check_random_device_invalid(const std::string &token) { + try { + std::random_device r(token); + assert(false); + } catch (const std::system_error &e) { + } +} + +int main() { + { std::random_device r; } + + { + int ec; + ec = close(STDIN_FILENO); + assert(!ec); + ec = close(STDOUT_FILENO); + assert(!ec); + ec = close(STDERR_FILENO); + assert(!ec); + std::random_device r; + } + + { + std::string token = "wrong file"; + if (is_valid_random_device(token)) + check_random_device_valid(token); + else + check_random_device_invalid(token); + } + + { + std::string token = "/dev/urandom"; + if (is_valid_random_device(token)) + check_random_device_valid(token); + else + check_random_device_invalid(token); + } + + { + std::string token = "/dev/random"; + if (is_valid_random_device(token)) + check_random_device_valid(token); + else + check_random_device_invalid(token); + } +} diff --git a/test/std/numerics/rand/rand.device/entropy.pass.cpp b/test/std/numerics/rand/rand.device/entropy.pass.cpp new file mode 100644 index 000000000000..f01e5653391f --- /dev/null +++ b/test/std/numerics/rand/rand.device/entropy.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class random_device; + +// double entropy() const; + +#include <random> +#include <cassert> + +int main() +{ + std::random_device r; + double e = r.entropy(); +} diff --git a/test/std/numerics/rand/rand.device/eval.pass.cpp b/test/std/numerics/rand/rand.device/eval.pass.cpp new file mode 100644 index 000000000000..72aff076a5df --- /dev/null +++ b/test/std/numerics/rand/rand.device/eval.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class random_device; + +// result_type operator()(); + +#include <random> +#include <cassert> + +int main() +{ + { + std::random_device r; + std::random_device::result_type e = r(); + } + + try + { + std::random_device r("/dev/null"); + r(); + assert(false); + } + catch (const std::system_error& e) + { + } +} diff --git a/test/std/numerics/rand/rand.dis/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/assign.pass.cpp new file mode 100644 index 000000000000..e55c1579c4cb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/assign.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// bernoulli_distribution& operator=(const bernoulli_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::bernoulli_distribution D; + D d1(0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/copy.pass.cpp new file mode 100644 index 000000000000..c64f925b4c6b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// bernoulli_distribution(const bernoulli_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::bernoulli_distribution D; + D d1(0.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_double.pass.cpp new file mode 100644 index 000000000000..5d511fcc6739 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_double.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// explicit bernoulli_distribution(double p = 0.5); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + D d; + assert(d.p() == 0.5); + } + { + typedef std::bernoulli_distribution D; + D d(0); + assert(d.p() == 0); + } + { + typedef std::bernoulli_distribution D; + D d(0.75); + assert(d.p() == 0.75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_param.pass.cpp new file mode 100644 index 000000000000..a143b5a68f4c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/ctor_param.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// explicit bernoulli_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eq.pass.cpp new file mode 100644 index 000000000000..b77c12eed22e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eq.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// bool operator=(const bernoulli_distribution& x, +// const bernoulli_distribution& y); +// bool operator!(const bernoulli_distribution& x, +// const bernoulli_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + D d1(.25); + D d2(.25); + assert(d1 == d2); + } + { + typedef std::bernoulli_distribution D; + D d1(.28); + D d2(.25); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval.pass.cpp new file mode 100644 index 000000000000..f071e8507478 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef std::minstd_rand G; + G g; + D d(.75); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.p(); + double x_var = d.p()*(1-d.p()); + double x_skew = (1 - 2 * d.p())/std::sqrt(x_var); + double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::bernoulli_distribution D; + typedef std::minstd_rand G; + G g; + D d(.25); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.p(); + double x_var = d.p()*(1-d.p()); + double x_skew = (1 - 2 * d.p())/std::sqrt(x_var); + double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval_param.pass.cpp new file mode 100644 index 000000000000..e03fb57f380c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/eval_param.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(.75); + P p(.25); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.p(); + double x_var = p.p()*(1-p.p()); + double x_skew = (1 - 2 * p.p())/std::sqrt(x_var); + double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::bernoulli_distribution D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(.25); + P p(.75); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.p(); + double x_var = p.p()*(1-p.p()); + double x_skew = (1 - 2 * p.p())/std::sqrt(x_var); + double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/get_param.pass.cpp new file mode 100644 index 000000000000..1b4eae90b6a3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/get_param.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type P; + P p(.125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/io.pass.cpp new file mode 100644 index 000000000000..5f57145e1311 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/io.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const bernoulli_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// bernoulli_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + D d1(.25); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/max.pass.cpp new file mode 100644 index 000000000000..8e669bbda34a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/max.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + D d(.25); + assert(d.max() == true); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/min.pass.cpp new file mode 100644 index 000000000000..296ad1474ecf --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/min.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + D d(.5); + assert(d.min() == false); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_assign.pass.cpp new file mode 100644 index 000000000000..a24dd0dfc930 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_assign.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p0(.7); + param_type p; + p = p0; + assert(p.p() == .7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_copy.pass.cpp new file mode 100644 index 000000000000..6c4eaeee4da9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_copy.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p0(.125); + param_type p = p0; + assert(p.p() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_ctor.pass.cpp new file mode 100644 index 000000000000..c43f44721a60 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_ctor.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p; + assert(p.p() == 0.5); + } + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p(0.25); + assert(p.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_eq.pass.cpp new file mode 100644 index 000000000000..ee5dfe867b7e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_eq.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::bernoulli_distribution D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_types.pass.cpp new file mode 100644 index 000000000000..5a3b90332120 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/param_types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::bernoulli_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/set_param.pass.cpp new file mode 100644 index 000000000000..9869ac6fc39c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/set_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::bernoulli_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/types.pass.cpp new file mode 100644 index 000000000000..4b6c4be1a240 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class bernoulli_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::bernoulli_distribution D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, bool>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/assign.pass.cpp new file mode 100644 index 000000000000..82473d2883b4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// binomial_distribution& operator=(const binomial_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::binomial_distribution<> D; + D d1(2, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/copy.pass.cpp new file mode 100644 index 000000000000..715494886787 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// binomial_distribution(const binomial_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::binomial_distribution<> D; + D d1(2, 0.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_int_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_int_double.pass.cpp new file mode 100644 index 000000000000..5a3a22eeebdd --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_int_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// explicit binomial_distribution(IntType t = 1, double p = 0.5); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + D d; + assert(d.t() == 1); + assert(d.p() == 0.5); + } + { + typedef std::binomial_distribution<> D; + D d(3); + assert(d.t() == 3); + assert(d.p() == 0.5); + } + { + typedef std::binomial_distribution<> D; + D d(3, 0.75); + assert(d.t() == 3); + assert(d.p() == 0.75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_param.pass.cpp new file mode 100644 index 000000000000..cfb98f2985e1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// explicit binomial_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + P p(5, 0.25); + D d(p); + assert(d.t() == 5); + assert(d.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eq.pass.cpp new file mode 100644 index 000000000000..738bdc80e934 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eq.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// bool operator=(const binomial_distribution& x, +// const binomial_distribution& y); +// bool operator!(const binomial_distribution& x, +// const binomial_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + D d1(3, .25); + D d2(3, .25); + assert(d1 == d2); + } + { + typedef std::binomial_distribution<> D; + D d1(3, .28); + D d2(3, .25); + assert(d1 != d2); + } + { + typedef std::binomial_distribution<> D; + D d1(3, .25); + D d2(4, .25); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp new file mode 100644 index 000000000000..43c6b546bdb2 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp @@ -0,0 +1,475 @@ +//===----------------------------------------------------------------------===// +// +// 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 binomial_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef std::mt19937_64 G; + G g; + D d(5, .75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); + double x_skew = (1-2*d.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(30, .03125); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); + double x_skew = (1-2*d.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(40, .25); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); + double x_skew = (1-2*d.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.03); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(40, 0); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + // In this case: + // skew computes to 0./0. == nan + // kurtosis computes to 0./0. == nan + // x_skew == inf + // x_kurtosis == inf + // These tests are commented out because UBSan warns about division by 0 +// skew /= u.size() * dev * var; +// kurtosis /= u.size() * var * var; +// kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); +// double x_skew = (1-2*d.p()) / std::sqrt(x_var); +// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(mean == x_mean); + assert(var == x_var); +// assert(skew == x_skew); +// assert(kurtosis == x_kurtosis); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(40, 1); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + // In this case: + // skew computes to 0./0. == nan + // kurtosis computes to 0./0. == nan + // x_skew == -inf + // x_kurtosis == inf + // These tests are commented out because UBSan warns about division by 0 +// skew /= u.size() * dev * var; +// kurtosis /= u.size() * var * var; +// kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); +// double x_skew = (1-2*d.p()) / std::sqrt(x_var); +// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(mean == x_mean); + assert(var == x_var); +// assert(skew == x_skew); +// assert(kurtosis == x_kurtosis); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(400, 0.5); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); + double x_skew = (1-2*d.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs(kurtosis - x_kurtosis) < 0.01); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(1, 0.5); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); + double x_skew = (1-2*d.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + const int N = 100000; + std::mt19937 gen1; + std::mt19937 gen2; + + std::binomial_distribution<> dist1(5, 0.1); + std::binomial_distribution<unsigned> dist2(5, 0.1); + + for(int i = 0; i < N; ++i) + assert(dist1(gen1) == dist2(gen2)); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0, 0.005); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + // In this case: + // skew computes to 0./0. == nan + // kurtosis computes to 0./0. == nan + // x_skew == inf + // x_kurtosis == inf + // These tests are commented out because UBSan warns about division by 0 +// skew /= u.size() * dev * var; +// kurtosis /= u.size() * var * var; +// kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); +// double x_skew = (1-2*d.p()) / std::sqrt(x_var); +// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(mean == x_mean); + assert(var == x_var); +// assert(skew == x_skew); +// assert(kurtosis == x_kurtosis); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0, 0); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + // In this case: + // skew computes to 0./0. == nan + // kurtosis computes to 0./0. == nan + // x_skew == inf + // x_kurtosis == inf + // These tests are commented out because UBSan warns about division by 0 +// skew /= u.size() * dev * var; +// kurtosis /= u.size() * var * var; +// kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); +// double x_skew = (1-2*d.p()) / std::sqrt(x_var); +// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(mean == x_mean); + assert(var == x_var); +// assert(skew == x_skew); +// assert(kurtosis == x_kurtosis); + } + { + typedef std::binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0, 1); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + // In this case: + // skew computes to 0./0. == nan + // kurtosis computes to 0./0. == nan + // x_skew == -inf + // x_kurtosis == inf + // These tests are commented out because UBSan warns about division by 0 +// skew /= u.size() * dev * var; +// kurtosis /= u.size() * var * var; +// kurtosis -= 3; + double x_mean = d.t() * d.p(); + double x_var = x_mean*(1-d.p()); +// double x_skew = (1-2*d.p()) / std::sqrt(x_var); +// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var; + assert(mean == x_mean); + assert(var == x_var); +// assert(skew == x_skew); +// assert(kurtosis == x_kurtosis); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp new file mode 100644 index 000000000000..1aa66ed57ad1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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 binomial_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + D d(16, .75); + P p(5, .75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(0 <= v && v <= p.t()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.t() * p.p(); + double x_var = x_mean*(1-p.p()); + double x_skew = (1-2*p.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(16, .75); + P p(30, .03125); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(0 <= v && v <= p.t()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.t() * p.p(); + double x_var = x_mean*(1-p.p()); + double x_skew = (1-2*p.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(16, .75); + P p(40, .25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(0 <= v && v <= p.t()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.t() * p.p(); + double x_var = x_mean*(1-p.p()); + double x_skew = (1-2*p.p()) / std::sqrt(x_var); + double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.04); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/get_param.pass.cpp new file mode 100644 index 000000000000..88c8424b0934 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + P p(5, .125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/io.pass.cpp new file mode 100644 index 000000000000..1276454b597b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const binomial_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// binomial_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + D d1(7, .25); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/max.pass.cpp new file mode 100644 index 000000000000..9c88faabe60b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + D d(4, .25); + assert(d.max() == 4); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/min.pass.cpp new file mode 100644 index 000000000000..678a34b2f54b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + D d(4, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_assign.pass.cpp new file mode 100644 index 000000000000..553f8ad82689 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p0(6, .7); + param_type p; + p = p0; + assert(p.t() == 6); + assert(p.p() == .7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_copy.pass.cpp new file mode 100644 index 000000000000..a9770efa282f --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.t() == 10); + assert(p.p() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_ctor.pass.cpp new file mode 100644 index 000000000000..cadf84a89044 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.t() == 1); + assert(p.p() == 0.5); + } + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.t() == 10); + assert(p.p() == 0.5); + } + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 0.25); + assert(p.t() == 10); + assert(p.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_eq.pass.cpp new file mode 100644 index 000000000000..3c2c1faa5c1b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p1(3, 0.75); + param_type p2(3, 0.75); + assert(p1 == p2); + } + { + typedef std::binomial_distribution<> D; + typedef D::param_type param_type; + param_type p1(3, 0.75); + param_type p2(3, 0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_types.pass.cpp new file mode 100644 index 000000000000..6c745611cd44 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::binomial_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/set_param.pass.cpp new file mode 100644 index 000000000000..612f5e2def02 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::param_type P; + P p(10, 0.25); + D d(8, 0.75); + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/types.pass.cpp new file mode 100644 index 000000000000..0e71aa019e7e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class binomial_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::binomial_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::binomial_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp new file mode 100644 index 000000000000..f71b37482ca7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// geometric_distribution& operator=(const geometric_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::geometric_distribution<> D; + D d1(0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp new file mode 100644 index 000000000000..00f3d04aefdb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// geometric_distribution(const geometric_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::geometric_distribution<> D; + D d1(0.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp new file mode 100644 index 000000000000..461542896ecf --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// explicit geometric_distribution(double p = 0.5); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + D d; + assert(d.p() == 0.5); + } + { + typedef std::geometric_distribution<> D; + D d(0.75); + assert(d.p() == 0.75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp new file mode 100644 index 000000000000..5cf93eb4646f --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// explicit geometric_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp new file mode 100644 index 000000000000..38d423bb5f76 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// bool operator=(const geometric_distribution& x, +// const geometric_distribution& y); +// bool operator!(const geometric_distribution& x, +// const geometric_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + D d1(.25); + D d2(.25); + assert(d1 == d2); + } + { + typedef std::geometric_distribution<> D; + D d1(.28); + D d2(.25); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp new file mode 100644 index 000000000000..a8ef221e3b67 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp @@ -0,0 +1,274 @@ +//===----------------------------------------------------------------------===// +// +// 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 geometric_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef std::mt19937 G; + G g; + D d(.03125); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::geometric_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0.05); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::geometric_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::geometric_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::geometric_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0.75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::geometric_distribution<> D; + typedef std::mt19937 G; + G g; + D d(0.96875); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt((1 - d.p())); + double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp new file mode 100644 index 000000000000..91dea8aa1337 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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 geometric_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(.75); + P p(.03125); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt((1 - p.p())); + double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::geometric_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(.75); + P p(.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt((1 - p.p())); + double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::geometric_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(.5); + P p(.75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt((1 - p.p())); + double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p()); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp new file mode 100644 index 000000000000..00797a119968 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type P; + P p(.125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp new file mode 100644 index 000000000000..3e3752af7b13 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const geometric_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// geometric_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + D d1(.25); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp new file mode 100644 index 000000000000..b381bc438ad8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + D d(.25); + assert(d.max() == std::numeric_limits<int>::max()); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp new file mode 100644 index 000000000000..56b75a7f8666 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + D d(.5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp new file mode 100644 index 000000000000..98b84d59ab4d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p0(.7); + param_type p; + p = p0; + assert(p.p() == .7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp new file mode 100644 index 000000000000..4397aecfb39c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p0(.125); + param_type p = p0; + assert(p.p() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp new file mode 100644 index 000000000000..c78525fea303 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.p() == 0.5); + } + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p(0.25); + assert(p.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp new file mode 100644 index 000000000000..374f2b0b8e97 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::geometric_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp new file mode 100644 index 000000000000..33a4c6fff6ca --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::geometric_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp new file mode 100644 index 000000000000..e8aee01fbea8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::geometric_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp new file mode 100644 index 000000000000..367e3f9871ef --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class geometric_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::geometric_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::geometric_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/assign.pass.cpp new file mode 100644 index 000000000000..f62c52eca851 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// negative_binomial_distribution& operator=(const negative_binomial_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::negative_binomial_distribution<> D; + D d1(2, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/copy.pass.cpp new file mode 100644 index 000000000000..37c003d353e3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// negative_binomial_distribution(const negative_binomial_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::negative_binomial_distribution<> D; + D d1(2, 0.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_int_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_int_double.pass.cpp new file mode 100644 index 000000000000..babf1d464a40 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_int_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// explicit negative_binomial_distribution(IntType t = 1, double p = 0.5); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + D d; + assert(d.k() == 1); + assert(d.p() == 0.5); + } + { + typedef std::negative_binomial_distribution<> D; + D d(3); + assert(d.k() == 3); + assert(d.p() == 0.5); + } + { + typedef std::negative_binomial_distribution<> D; + D d(3, 0.75); + assert(d.k() == 3); + assert(d.p() == 0.75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_param.pass.cpp new file mode 100644 index 000000000000..109a47e87183 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// explicit negative_binomial_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + P p(5, 0.25); + D d(p); + assert(d.k() == 5); + assert(d.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eq.pass.cpp new file mode 100644 index 000000000000..0bf34eed6db9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eq.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// bool operator=(const negative_binomial_distribution& x, +// const negative_binomial_distribution& y); +// bool operator!(const negative_binomial_distribution& x, +// const negative_binomial_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + D d1(3, .25); + D d2(3, .25); + assert(d1 == d2); + } + { + typedef std::negative_binomial_distribution<> D; + D d1(3, .28); + D d2(3, .25); + assert(d1 != d2); + } + { + typedef std::negative_binomial_distribution<> D; + D d1(3, .25); + D d2(4, .25); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp new file mode 100644 index 000000000000..853161e9f9b7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp @@ -0,0 +1,272 @@ +//===----------------------------------------------------------------------===// +// +// 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 negative_binomial_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(5, .25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } + { + typedef std::negative_binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(30, .03125); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::negative_binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(40, .25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::negative_binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(40, 1); + const int N = 1000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(mean == x_mean); + assert(var == x_var); + } + { + typedef std::negative_binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(400, 0.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.04); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.05); + } + { + typedef std::negative_binomial_distribution<> D; + typedef std::mt19937 G; + G g; + D d(1, 0.05); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.k() * (1 - d.p()) / d.p(); + double x_var = x_mean / d.p(); + double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p())); + double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval_param.pass.cpp new file mode 100644 index 000000000000..f2f2a07879e2 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/eval_param.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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 negative_binomial_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <numeric> +#include <vector> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(16, .75); + P p(5, .75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.k() * (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p())); + double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(16, .75); + P p(30, .03125); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.k() * (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p())); + double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(16, .75); + P p(40, .25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.k() * (1 - p.p()) / p.p(); + double x_var = x_mean / p.p(); + double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p())); + double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p())); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/get_param.pass.cpp new file mode 100644 index 000000000000..65f4a978cb05 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + P p(5, .125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/io.pass.cpp new file mode 100644 index 000000000000..da5e8af616ec --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const negative_binomial_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// negative_binomial_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + D d1(7, .25); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/max.pass.cpp new file mode 100644 index 000000000000..2fe7184e6ec9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + D d(4, .25); + assert(d.max() == std::numeric_limits<int>::max()); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/min.pass.cpp new file mode 100644 index 000000000000..15bec5a7dc6a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + D d(4, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_assign.pass.cpp new file mode 100644 index 000000000000..dc4d35c700ae --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p0(6, .7); + param_type p; + p = p0; + assert(p.k() == 6); + assert(p.p() == .7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_copy.pass.cpp new file mode 100644 index 000000000000..ec5af5b85030 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.k() == 10); + assert(p.p() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_ctor.pass.cpp new file mode 100644 index 000000000000..6d713ce71b23 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.k() == 1); + assert(p.p() == 0.5); + } + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.k() == 10); + assert(p.p() == 0.5); + } + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 0.25); + assert(p.k() == 10); + assert(p.p() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_eq.pass.cpp new file mode 100644 index 000000000000..b0f81cdfa7a0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p1(3, 0.75); + param_type p2(3, 0.75); + assert(p1 == p2); + } + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type param_type; + param_type p1(3, 0.75); + param_type p2(3, 0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_types.pass.cpp new file mode 100644 index 000000000000..282ca190c232 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::negative_binomial_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/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/set_param.pass.cpp new file mode 100644 index 000000000000..05c204f5c649 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::param_type P; + P p(10, 0.25); + D d(8, 0.75); + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/types.pass.cpp new file mode 100644 index 000000000000..149f5075236d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class negative_binomial_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::negative_binomial_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::negative_binomial_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/assign.pass.cpp new file mode 100644 index 000000000000..3003e0db94d1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// cauchy_distribution& operator=(const cauchy_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::cauchy_distribution<> D; + D d1(.5, 2); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/copy.pass.cpp new file mode 100644 index 000000000000..032191493e54 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// cauchy_distribution(const cauchy_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::cauchy_distribution<> D; + D d1(.5, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..a0406b026b96 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// explicit cauchy_distribution(result_type a = 0, result_type b = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + D d; + assert(d.a() == 0); + assert(d.b() == 1); + } + { + typedef std::cauchy_distribution<> D; + D d(14.5); + assert(d.a() == 14.5); + assert(d.b() == 1); + } + { + typedef std::cauchy_distribution<> D; + D d(14.5, 5.25); + assert(d.a() == 14.5); + assert(d.b() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_param.pass.cpp new file mode 100644 index 000000000000..0973b60a7248 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// explicit cauchy_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.a() == 0.25); + assert(d.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eq.pass.cpp new file mode 100644 index 000000000000..005e141b46c0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// bool operator=(const cauchy_distribution& x, +// const cauchy_distribution& y); +// bool operator!(const cauchy_distribution& x, +// const cauchy_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::cauchy_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval.pass.cpp new file mode 100644 index 000000000000..d70d8f072c39 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class cauchy_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <cassert> +#include <vector> +#include <algorithm> + +double +f(double x, double a, double b) +{ + return 1/3.1415926535897932 * std::atan((x - a)/b) + .5; +} + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = 10; + const double b = .5; + D d(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = -1.5; + const double b = 1; + D d(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = .5; + const double b = 2; + D d(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval_param.pass.cpp new file mode 100644 index 000000000000..318c29e7694e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/eval_param.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class cauchy_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <cassert> +#include <vector> +#include <algorithm> + +double +f(double x, double a, double b) +{ + return 1/3.1415926535897932 * std::atan((x - a)/b) + .5; +} + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = 10; + const double b = .5; + D d; + P p(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = -1.5; + const double b = 1; + D d; + P p(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + const double a = .5; + const double b = 2; + D d; + P p(a, b); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/get_param.pass.cpp new file mode 100644 index 000000000000..0e2d6b049f67 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/io.pass.cpp new file mode 100644 index 000000000000..ca53792c6af8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const cauchy_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// cauchy_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + D d1(7.5, 5.5); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/max.pass.cpp new file mode 100644 index 000000000000..263c1773a8f0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/min.pass.cpp new file mode 100644 index 000000000000..0d52179ae7e3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + D d(.5, .5); + assert(d.min() == -INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_assign.pass.cpp new file mode 100644 index 000000000000..f8e0852834d3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.a() == .75); + assert(p.b() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_copy.pass.cpp new file mode 100644 index 000000000000..28ef06827757 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.a() == 10); + assert(p.b() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_ctor.pass.cpp new file mode 100644 index 000000000000..8ae5137aa3af --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 0); + assert(p.b() == 1); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.a() == 10); + assert(p.b() == 1); + } + { + typedef std::cauchy_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.a() == 10); + assert(p.b() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_eq.pass.cpp new file mode 100644 index 000000000000..6210321fb343 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_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::cauchy_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_types.pass.cpp new file mode 100644 index 000000000000..56b1f6f91501 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::cauchy_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/set_param.pass.cpp new file mode 100644 index 000000000000..201ec60b00e3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::cauchy_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/types.pass.cpp new file mode 100644 index 000000000000..919a7b1b65b2 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class cauchy_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::cauchy_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::cauchy_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/assign.pass.cpp new file mode 100644 index 000000000000..0c3a0aed2df8 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/copy.pass.cpp new file mode 100644 index 000000000000..9496184d4333 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_double.pass.cpp new file mode 100644 index 000000000000..27401d91e10c --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/ctor_param.pass.cpp new file mode 100644 index 000000000000..afd5aa91c7cd --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eq.pass.cpp new file mode 100644 index 000000000000..88630b0cf521 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp new file mode 100644 index 000000000000..6fbdd93f8ffd --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// 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 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 = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.n(); + double x_var = 2 * d.n(); + double x_skew = std::sqrt(8 / d.n()); + double x_kurtosis = 12 / d.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(1); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.n(); + double x_var = 2 * d.n(); + double x_skew = std::sqrt(8 / d.n()); + double x_kurtosis = 12 / d.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.n(); + double x_var = 2 * d.n(); + double x_skew = std::sqrt(8 / d.n()); + double x_kurtosis = 12 / d.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp new file mode 100644 index 000000000000..548848d19f3e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/eval_param.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// 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 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 = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.n(); + double x_var = 2 * p.n(); + double x_skew = std::sqrt(8 / p.n()); + double x_kurtosis = 12 / p.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::chi_squared_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1); + P p(2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.n(); + double x_var = 2 * p.n(); + double x_skew = std::sqrt(8 / p.n()); + double x_kurtosis = 12 / p.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + 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 = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.n(); + double x_var = 2 * p.n(); + double x_skew = std::sqrt(8 / p.n()); + double x_kurtosis = 12 / p.n(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/get_param.pass.cpp new file mode 100644 index 000000000000..f12a0519bfca --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/io.pass.cpp new file mode 100644 index 000000000000..de16fa1e1eb7 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/max.pass.cpp new file mode 100644 index 000000000000..adf4f96ebec0 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/min.pass.cpp new file mode 100644 index 000000000000..4e51590bbce6 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_assign.pass.cpp new file mode 100644 index 000000000000..85730f619187 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_copy.pass.cpp new file mode 100644 index 000000000000..3ddb02b72713 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_ctor.pass.cpp new file mode 100644 index 000000000000..34d8651156b6 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_eq.pass.cpp new file mode 100644 index 000000000000..cb738ea858a3 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/param_types.pass.cpp new file mode 100644 index 000000000000..257016b3c332 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/set_param.pass.cpp new file mode 100644 index 000000000000..a8d4e52b8bb7 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/types.pass.cpp new file mode 100644 index 000000000000..614da1979ee5 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/assign.pass.cpp new file mode 100644 index 000000000000..f5294bdc54b1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// fisher_f_distribution& operator=(const fisher_f_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::fisher_f_distribution<> D; + D d1(20, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/copy.pass.cpp new file mode 100644 index 000000000000..047d5133583c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// fisher_f_distribution(const fisher_f_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::fisher_f_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..1dd628b625aa --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// explicit fisher_f_distribution(result_type alpha = 0, result_type beta = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + D d; + assert(d.m() == 1); + assert(d.n() == 1); + } + { + typedef std::fisher_f_distribution<> D; + D d(14.5); + assert(d.m() == 14.5); + assert(d.n() == 1); + } + { + typedef std::fisher_f_distribution<> D; + D d(14.5, 5.25); + assert(d.m() == 14.5); + assert(d.n() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_param.pass.cpp new file mode 100644 index 000000000000..83a81cf4068b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// explicit fisher_f_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.m() == 0.25); + assert(d.n() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eq.pass.cpp new file mode 100644 index 000000000000..405c906cbdc3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// bool operator=(const fisher_f_distribution& x, +// const fisher_f_distribution& y); +// bool operator!(const fisher_f_distribution& x, +// const fisher_f_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::fisher_f_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval.pass.cpp new file mode 100644 index 000000000000..091bbb9bb452 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class fisher_f_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <cassert> +#include <vector> +#include <algorithm> +#include <cmath> + +double fac(double x) +{ + double r = 1; + for (; x > 1; --x) + r *= x; + return r; +} + +double +I(double x, unsigned a, unsigned b) +{ + double r = 0; + for (int j = a; j <= a+b-1; ++j) + r += fac(a+b-1)/(fac(j) * fac(a + b - 1 - j)) * std::pow(x, j) * + std::pow(1-x, a+b-1-j); + return r; +} + +double +f(double x, double m, double n) +{ + return I(m * x / (m*x + n), static_cast<unsigned>(m/2), static_cast<unsigned>(n/2)); +} + +int main() +{ + // Purposefully only testing even integral values of m and n (for now) + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 4); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(4, 2); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(18, 20); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval_param.pass.cpp new file mode 100644 index 000000000000..774137154e09 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval_param.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class fisher_f_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <cassert> +#include <vector> +#include <algorithm> +#include <cmath> + +double fac(double x) +{ + double r = 1; + for (; x > 1; --x) + r *= x; + return r; +} + +double +I(double x, unsigned a, unsigned b) +{ + double r = 0; + for (int j = a; j <= a+b-1; ++j) + r += fac(a+b-1)/(fac(j) * fac(a + b - 1 - j)) * std::pow(x, j) * + std::pow(1-x, a+b-1-j); + return r; +} + +double +f(double x, double m, double n) +{ + return I(m * x / (m*x + n), static_cast<unsigned>(m/2), static_cast<unsigned>(n/2)); +} + +int main() +{ + // Purposefully only testing even integral values of m and n (for now) + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 4); + P p(4, 2); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(4, 2); + P p(6, 8); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(18, 20); + P p(16, 14); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v >= 0); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + for (int i = 0; i < N; ++i) + assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/get_param.pass.cpp new file mode 100644 index 000000000000..572df9bed67e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/io.pass.cpp new file mode 100644 index 000000000000..8872a274b2ec --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const fisher_f_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// fisher_f_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/max.pass.cpp new file mode 100644 index 000000000000..dfdbd5d7df8d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/min.pass.cpp new file mode 100644 index 000000000000..bd4c5d1a6fcf --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + D d(.5, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_assign.pass.cpp new file mode 100644 index 000000000000..ea44645e66f9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.m() == .75); + assert(p.n() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_copy.pass.cpp new file mode 100644 index 000000000000..d6ce53ae136c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.m() == 10); + assert(p.n() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_ctor.pass.cpp new file mode 100644 index 000000000000..1ab9138eb2fb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.m() == 1); + assert(p.n() == 1); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.m() == 10); + assert(p.n() == 1); + } + { + typedef std::fisher_f_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.m() == 10); + assert(p.n() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_eq.pass.cpp new file mode 100644 index 000000000000..16eea408a8cf --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_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::fisher_f_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_types.pass.cpp new file mode 100644 index 000000000000..8391eedd23ac --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::fisher_f_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/set_param.pass.cpp new file mode 100644 index 000000000000..a7a1af662bfc --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::fisher_f_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/types.pass.cpp new file mode 100644 index 000000000000..b765725d1c58 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class fisher_f_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::fisher_f_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::fisher_f_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/assign.pass.cpp new file mode 100644 index 000000000000..4da6451d9bfc --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// lognormal_distribution& operator=(const lognormal_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::lognormal_distribution<> D; + D d1(20, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/copy.pass.cpp new file mode 100644 index 000000000000..777f4a1ac9d5 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// lognormal_distribution(const lognormal_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::lognormal_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..39d53393dd29 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// explicit lognormal_distribution(result_type mean = 0, result_type stddev = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + D d; + assert(d.m() == 0); + assert(d.s() == 1); + } + { + typedef std::lognormal_distribution<> D; + D d(14.5); + assert(d.m() == 14.5); + assert(d.s() == 1); + } + { + typedef std::lognormal_distribution<> D; + D d(14.5, 5.25); + assert(d.m() == 14.5); + assert(d.s() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_param.pass.cpp new file mode 100644 index 000000000000..f16567788066 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// explicit lognormal_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.m() == 0.25); + assert(d.s() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eq.pass.cpp new file mode 100644 index 000000000000..5fee0fd4ce17 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// bool operator=(const lognormal_distribution& x, +// const lognormal_distribution& y); +// bool operator!(const lognormal_distribution& x, +// const lognormal_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::lognormal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval.pass.cpp new file mode 100644 index 000000000000..9b111cced8a8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval.pass.cpp @@ -0,0 +1,244 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class lognormal_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::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-1./8192, 0.015625); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(d.m() + sqr(d.s())/2); + double x_var = (std::exp(sqr(d.s())) - 1) * std::exp(2*d.m() + sqr(d.s())); + double x_skew = (std::exp(sqr(d.s())) + 2) * + std::sqrt((std::exp(sqr(d.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(d.s())) + 2*std::exp(3*sqr(d.s())) + + 3*std::exp(2*sqr(d.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.05); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.25); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-1./32, 0.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(d.m() + sqr(d.s())/2); + double x_var = (std::exp(sqr(d.s())) - 1) * std::exp(2*d.m() + sqr(d.s())); + double x_skew = (std::exp(sqr(d.s())) + 2) * + std::sqrt((std::exp(sqr(d.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(d.s())) + 2*std::exp(3*sqr(d.s())) + + 3*std::exp(2*sqr(d.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-1./8, 0.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(d.m() + sqr(d.s())/2); + double x_var = (std::exp(sqr(d.s())) - 1) * std::exp(2*d.m() + sqr(d.s())); + double x_skew = (std::exp(sqr(d.s())) + 2) * + std::sqrt((std::exp(sqr(d.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(d.s())) + 2*std::exp(3*sqr(d.s())) + + 3*std::exp(2*sqr(d.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.02); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.05); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d; + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(d.m() + sqr(d.s())/2); + double x_var = (std::exp(sqr(d.s())) - 1) * std::exp(2*d.m() + sqr(d.s())); + double x_skew = (std::exp(sqr(d.s())) + 2) * + std::sqrt((std::exp(sqr(d.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(d.s())) + 2*std::exp(3*sqr(d.s())) + + 3*std::exp(2*sqr(d.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.02); + assert(std::abs((skew - x_skew) / x_skew) < 0.08); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.4); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-0.78125, 1.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(d.m() + sqr(d.s())/2); + double x_var = (std::exp(sqr(d.s())) - 1) * std::exp(2*d.m() + sqr(d.s())); + double x_skew = (std::exp(sqr(d.s())) + 2) * + std::sqrt((std::exp(sqr(d.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(d.s())) + 2*std::exp(3*sqr(d.s())) + + 3*std::exp(2*sqr(d.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.04); + assert(std::abs((skew - x_skew) / x_skew) < 0.2); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval_param.pass.cpp new file mode 100644 index 000000000000..283403ea1a0d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval_param.pass.cpp @@ -0,0 +1,250 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class lognormal_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::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d; + P p(-1./8192, 0.015625); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(p.m() + sqr(p.s())/2); + double x_var = (std::exp(sqr(p.s())) - 1) * std::exp(2*p.m() + sqr(p.s())); + double x_skew = (std::exp(sqr(p.s())) + 2) * + std::sqrt((std::exp(sqr(p.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(p.s())) + 2*std::exp(3*sqr(p.s())) + + 3*std::exp(2*sqr(p.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.05); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.25); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d; + P p(-1./32, 0.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(p.m() + sqr(p.s())/2); + double x_var = (std::exp(sqr(p.s())) - 1) * std::exp(2*p.m() + sqr(p.s())); + double x_skew = (std::exp(sqr(p.s())) + 2) * + std::sqrt((std::exp(sqr(p.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(p.s())) + 2*std::exp(3*sqr(p.s())) + + 3*std::exp(2*sqr(p.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d; + P p(-1./8, 0.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(p.m() + sqr(p.s())/2); + double x_var = (std::exp(sqr(p.s())) - 1) * std::exp(2*p.m() + sqr(p.s())); + double x_skew = (std::exp(sqr(p.s())) + 2) * + std::sqrt((std::exp(sqr(p.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(p.s())) + 2*std::exp(3*sqr(p.s())) + + 3*std::exp(2*sqr(p.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.02); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.05); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(3, 4); + P p; + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(p.m() + sqr(p.s())/2); + double x_var = (std::exp(sqr(p.s())) - 1) * std::exp(2*p.m() + sqr(p.s())); + double x_skew = (std::exp(sqr(p.s())) + 2) * + std::sqrt((std::exp(sqr(p.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(p.s())) + 2*std::exp(3*sqr(p.s())) + + 3*std::exp(2*sqr(p.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.02); + assert(std::abs((skew - x_skew) / x_skew) < 0.08); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.4); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d; + P p(-0.78125, 1.25); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(v > 0); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = std::exp(p.m() + sqr(p.s())/2); + double x_var = (std::exp(sqr(p.s())) - 1) * std::exp(2*p.m() + sqr(p.s())); + double x_skew = (std::exp(sqr(p.s())) + 2) * + std::sqrt((std::exp(sqr(p.s())) - 1)); + double x_kurtosis = std::exp(4*sqr(p.s())) + 2*std::exp(3*sqr(p.s())) + + 3*std::exp(2*sqr(p.s())) - 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.04); + assert(std::abs((skew - x_skew) / x_skew) < 0.2); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/get_param.pass.cpp new file mode 100644 index 000000000000..348ca6cfd7e6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/io.pass.cpp new file mode 100644 index 000000000000..4af0f2eafed8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const lognormal_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// lognormal_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/max.pass.cpp new file mode 100644 index 000000000000..7ebfc43a3217 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/min.pass.cpp new file mode 100644 index 000000000000..6af4df777ec3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + D d(.5, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_assign.pass.cpp new file mode 100644 index 000000000000..b23c770f5aae --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.m() == .75); + assert(p.s() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_copy.pass.cpp new file mode 100644 index 000000000000..32ecc68da3c8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.m() == 10); + assert(p.s() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_ctor.pass.cpp new file mode 100644 index 000000000000..2f109e3f57af --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.m() == 0); + assert(p.s() == 1); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.m() == 10); + assert(p.s() == 1); + } + { + typedef std::lognormal_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.m() == 10); + assert(p.s() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_eq.pass.cpp new file mode 100644 index 000000000000..2f4293a737d6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_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::lognormal_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_types.pass.cpp new file mode 100644 index 000000000000..6e53b269ee8a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::lognormal_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/set_param.pass.cpp new file mode 100644 index 000000000000..09c183f51048 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::lognormal_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/types.pass.cpp new file mode 100644 index 000000000000..1a07000d5197 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class lognormal_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::lognormal_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::lognormal_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp new file mode 100644 index 000000000000..a7b2f71abb17 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp new file mode 100644 index 000000000000..63f5be3c1c3a --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..24a45f757ee6 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp new file mode 100644 index 000000000000..11c7fbd6e89e --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp new file mode 100644 index 000000000000..b6bd3d3166f1 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp new file mode 100644 index 000000000000..95d0272dbc32 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 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 = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.mean(); + double x_var = sqr(d.stddev()); + double x_skew = 0; + double x_kurtosis = 0; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs(kurtosis - x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp new file mode 100644 index 000000000000..20c3a44f13e1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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 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 = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.mean(); + double x_var = sqr(p.stddev()); + double x_skew = 0; + double x_kurtosis = 0; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs(kurtosis - x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp new file mode 100644 index 000000000000..8b5d4328c9e3 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp new file mode 100644 index 000000000000..6d79433490ad --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp new file mode 100644 index 000000000000..3825704f5be6 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp new file mode 100644 index 000000000000..9ba754d37fcb --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp new file mode 100644 index 000000000000..2f7329b478e8 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp new file mode 100644 index 000000000000..bddf0023f84e --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp new file mode 100644 index 000000000000..a1add140c930 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp new file mode 100644 index 000000000000..cf2093808804 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp new file mode 100644 index 000000000000..8d9b97e74fc3 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp new file mode 100644 index 000000000000..bb01bb1c009e --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp new file mode 100644 index 000000000000..771685a8c352 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/assign.pass.cpp new file mode 100644 index 000000000000..80c0a19783b5 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// student_t_distribution& operator=(const student_t_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::student_t_distribution<> D; + D d1(20.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/copy.pass.cpp new file mode 100644 index 000000000000..032cf77e8645 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// student_t_distribution(const student_t_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::student_t_distribution<> D; + D d1(21.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_double.pass.cpp new file mode 100644 index 000000000000..7dfb97fb09c1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_double.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// explicit student_t_distribution(result_type alpha = 0, result_type beta = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + D d; + assert(d.n() == 1); + } + { + typedef std::student_t_distribution<> D; + D d(14.5); + assert(d.n() == 14.5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_param.pass.cpp new file mode 100644 index 000000000000..57dedea87ed8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/ctor_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// explicit student_t_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.n() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eq.pass.cpp new file mode 100644 index 000000000000..73e8340439ce --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// bool operator=(const student_t_distribution& x, +// const student_t_distribution& y); +// bool operator!(const student_t_distribution& x, +// const student_t_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + D d1(2.5); + D d2(2.5); + assert(d1 == d2); + } + { + typedef std::student_t_distribution<> D; + D d1(4); + D d2(4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval.pass.cpp new file mode 100644 index 000000000000..ef6b37e9f9cc --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval.pass.cpp @@ -0,0 +1,142 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class student_t_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::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(5.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = d.n() / (d.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (d.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.2); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(10); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = d.n() / (d.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (d.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(100); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = d.n() / (d.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (d.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval_param.pass.cpp new file mode 100644 index 000000000000..70bc29e3ad13 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval_param.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class student_t_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::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d; + P p(5.5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = p.n() / (p.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (p.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.2); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d; + P p(10); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = p.n() / (p.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (p.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d; + P p(100); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 0; + double x_var = p.n() / (p.n() - 2); + double x_skew = 0; + double x_kurtosis = 6 / (p.n() - 4); + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/get_param.pass.cpp new file mode 100644 index 000000000000..a702a9fc5a01 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type P; + P p(.125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/io.pass.cpp new file mode 100644 index 000000000000..d3ca6ee28c73 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const student_t_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// student_t_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::student_t_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/max.pass.cpp new file mode 100644 index 000000000000..aab361eaa3c3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + D d(5); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/min.pass.cpp new file mode 100644 index 000000000000..a615f8efea90 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + D d(.5); + assert(d.min() == -INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_assign.pass.cpp new file mode 100644 index 000000000000..e900c2566777 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_assign.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75); + param_type p; + p = p0; + assert(p.n() == .75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_copy.pass.cpp new file mode 100644 index 000000000000..9ce6a916275c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_copy.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p0(10); + param_type p = p0; + assert(p.n() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_ctor.pass.cpp new file mode 100644 index 000000000000..c9d0e131da0b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_ctor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.n() == 1); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.n() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_eq.pass.cpp new file mode 100644 index 000000000000..83634b2e3e93 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::student_t_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_types.pass.cpp new file mode 100644 index 000000000000..6cdd5c403e8d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::student_t_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/set_param.pass.cpp new file mode 100644 index 000000000000..681d335a537f --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::student_t_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/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/types.pass.cpp new file mode 100644 index 000000000000..9a25ce2d6181 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class student_t_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::student_t_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::student_t_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp new file mode 100644 index 000000000000..c2a11a15b505 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp new file mode 100644 index 000000000000..81ae8e012614 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp new file mode 100644 index 000000000000..92205a8abed1 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp new file mode 100644 index 000000000000..cd9782bf4370 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp new file mode 100644 index 000000000000..e31a14d0d0b8 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp new file mode 100644 index 000000000000..b2fe52676e7e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// 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 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::mt19937 G; + G g; + D d(.75); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 1/d.lambda(); + double x_var = 1/sqr(d.lambda()); + double x_skew = 2; + double x_kurtosis = 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 1/d.lambda(); + double x_var = 1/sqr(d.lambda()); + double x_skew = 2; + double x_kurtosis = 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::exponential_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(10); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 1/d.lambda(); + double x_var = 1/sqr(d.lambda()); + double x_skew = 2; + double x_kurtosis = 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp new file mode 100644 index 000000000000..9879e63a33e9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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 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::mt19937 G; + G g; + D d(.75); + P p(2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = 1/p.lambda(); + double x_var = 1/sqr(p.lambda()); + double x_skew = 2; + double x_kurtosis = 6; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp new file mode 100644 index 000000000000..f5bd8107e4b3 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp new file mode 100644 index 000000000000..eaedc8770efd --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp new file mode 100644 index 000000000000..204cd7c0c97b --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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(m == std::numeric_limits<D::result_type>::infinity()); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp new file mode 100644 index 000000000000..60af4bc81a99 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp new file mode 100644 index 000000000000..1f5352192bd1 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp new file mode 100644 index 000000000000..360bd5daa60d --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp new file mode 100644 index 000000000000..7d74c7fccd1c --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp new file mode 100644 index 000000000000..416d18cab930 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp new file mode 100644 index 000000000000..3d7371165e5b --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp new file mode 100644 index 000000000000..6c295aa1b07e --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp new file mode 100644 index 000000000000..3d444e631db9 --- /dev/null +++ b/test/std/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 dual licensed under the MIT and the University of Illinois Open +// Source Licenses. 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), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/assign.pass.cpp new file mode 100644 index 000000000000..ff7cff45e994 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// extreme_value_distribution& operator=(const extreme_value_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::extreme_value_distribution<> D; + D d1(.5, 2); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/copy.pass.cpp new file mode 100644 index 000000000000..303779768c21 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// extreme_value_distribution(const extreme_value_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::extreme_value_distribution<> D; + D d1(.5, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..f5068d98dc68 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// explicit extreme_value_distribution(result_type a = 0, result_type b = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + D d; + assert(d.a() == 0); + assert(d.b() == 1); + } + { + typedef std::extreme_value_distribution<> D; + D d(14.5); + assert(d.a() == 14.5); + assert(d.b() == 1); + } + { + typedef std::extreme_value_distribution<> D; + D d(14.5, 5.25); + assert(d.a() == 14.5); + assert(d.b() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_param.pass.cpp new file mode 100644 index 000000000000..cac06699e417 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// explicit extreme_value_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.a() == 0.25); + assert(d.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eq.pass.cpp new file mode 100644 index 000000000000..6280df4f54a3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// bool operator=(const extreme_value_distribution& x, +// const extreme_value_distribution& y); +// bool operator!(const extreme_value_distribution& x, +// const extreme_value_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::extreme_value_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp new file mode 100644 index 000000000000..6390acef8941 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class extreme_value_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::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(0.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.a() + d.b() * 0.577215665; + double x_var = sqr(d.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.a() + d.b() * 0.577215665; + double x_var = sqr(d.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1.5, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.a() + d.b() * 0.577215665; + double x_var = sqr(d.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(3, 4); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.a() + d.b() * 0.577215665; + double x_var = sqr(d.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval_param.pass.cpp new file mode 100644 index 000000000000..6152cce8f4f8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval_param.pass.cpp @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class extreme_value_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::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-0.5, 1); + P p(0.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.a() + p.b() * 0.577215665; + double x_var = sqr(p.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-0.5, 1); + P p(1, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.a() + p.b() * 0.577215665; + double x_var = sqr(p.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-0.5, 1); + P p(1.5, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.a() + p.b() * 0.577215665; + double x_var = sqr(p.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(-0.5, 1); + P p(3, 4); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.a() + p.b() * 0.577215665; + double x_var = sqr(p.b()) * 1.644934067; + double x_skew = 1.139547; + double x_kurtosis = 12./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/get_param.pass.cpp new file mode 100644 index 000000000000..1855d5f73b2b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/io.pass.cpp new file mode 100644 index 000000000000..0beaf429301b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const extreme_value_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// extreme_value_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + D d1(7.5, 5.5); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/max.pass.cpp new file mode 100644 index 000000000000..ca89e355b2fe --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/min.pass.cpp new file mode 100644 index 000000000000..1f98a5b17390 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + D d(.5, .5); + assert(d.min() == -INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_assign.pass.cpp new file mode 100644 index 000000000000..44f587f625b5 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.a() == .75); + assert(p.b() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_copy.pass.cpp new file mode 100644 index 000000000000..6675bab61589 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.a() == 10); + assert(p.b() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_ctor.pass.cpp new file mode 100644 index 000000000000..3fe3d49c334d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 0); + assert(p.b() == 1); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.a() == 10); + assert(p.b() == 1); + } + { + typedef std::extreme_value_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.a() == 10); + assert(p.b() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_eq.pass.cpp new file mode 100644 index 000000000000..3b55d569f5f4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_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::extreme_value_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_types.pass.cpp new file mode 100644 index 000000000000..d6ffb5f0c10d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::extreme_value_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/set_param.pass.cpp new file mode 100644 index 000000000000..dcf0b1659bea --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::extreme_value_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/types.pass.cpp new file mode 100644 index 000000000000..44dd1816c1a6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class extreme_value_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::extreme_value_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::extreme_value_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp new file mode 100644 index 000000000000..671f4b1cde44 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// gamma_distribution& operator=(const gamma_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::gamma_distribution<> D; + D d1(20, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp new file mode 100644 index 000000000000..876ecb27f8b1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// gamma_distribution(const gamma_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::gamma_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..5bc4bbaea893 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// explicit gamma_distribution(result_type alpha = 0, result_type beta = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + D d; + assert(d.alpha() == 1); + assert(d.beta() == 1); + } + { + typedef std::gamma_distribution<> D; + D d(14.5); + assert(d.alpha() == 14.5); + assert(d.beta() == 1); + } + { + typedef std::gamma_distribution<> D; + D d(14.5, 5.25); + assert(d.alpha() == 14.5); + assert(d.beta() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp new file mode 100644 index 000000000000..35de51b1c4b0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// explicit gamma_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.alpha() == 0.25); + assert(d.beta() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp new file mode 100644 index 000000000000..48331a609ce4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// bool operator=(const gamma_distribution& x, +// const gamma_distribution& y); +// bool operator!(const gamma_distribution& x, +// const gamma_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::gamma_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp new file mode 100644 index 000000000000..7c26cc8a1c47 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class gamma_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::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(0.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.alpha() * d.beta(); + double x_var = d.alpha() * sqr(d.beta()); + double x_skew = 2 / std::sqrt(d.alpha()); + double x_kurtosis = 6 / d.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1, .5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.alpha() * d.beta(); + double x_var = d.alpha() * sqr(d.beta()); + double x_skew = 2 / std::sqrt(d.alpha()); + double x_kurtosis = 6 / d.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.alpha() * d.beta(); + double x_var = d.alpha() * sqr(d.beta()); + double x_skew = 2 / std::sqrt(d.alpha()); + double x_kurtosis = 6 / d.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp new file mode 100644 index 000000000000..8ed39df819d7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class gamma_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::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(0.5, 2); + P p(1, .5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.alpha() * p.beta(); + double x_var = p.alpha() * sqr(p.beta()); + double x_skew = 2 / std::sqrt(p.alpha()); + double x_kurtosis = 6 / p.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1, .5); + P p(2, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.alpha() * p.beta(); + double x_var = p.alpha() * sqr(p.beta()); + double x_skew = 2 / std::sqrt(p.alpha()); + double x_kurtosis = 6 / p.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 3); + P p(.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() < v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.alpha() * p.beta(); + double x_var = p.alpha() * sqr(p.beta()); + double x_skew = 2 / std::sqrt(p.alpha()); + double x_kurtosis = 6 / p.alpha(); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp new file mode 100644 index 000000000000..0aad32c64697 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp new file mode 100644 index 000000000000..a2a288adf595 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const gamma_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// gamma_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::gamma_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp new file mode 100644 index 000000000000..9ec51932a5d5 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp new file mode 100644 index 000000000000..a918c147900f --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + D d(.5, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp new file mode 100644 index 000000000000..31f346ed5d65 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.alpha() == .75); + assert(p.beta() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp new file mode 100644 index 000000000000..c96cbcd2ead7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.alpha() == 10); + assert(p.beta() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp new file mode 100644 index 000000000000..c0e34f0b56e9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.alpha() == 1); + assert(p.beta() == 1); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.alpha() == 10); + assert(p.beta() == 1); + } + { + typedef std::gamma_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.alpha() == 10); + assert(p.beta() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp new file mode 100644 index 000000000000..2fe9c2d71fac --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::gamma_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::gamma_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp new file mode 100644 index 000000000000..51e8eb123e6c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::gamma_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp new file mode 100644 index 000000000000..7e226299014d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::gamma_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp new file mode 100644 index 000000000000..65459e00f3ef --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class gamma_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::gamma_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::gamma_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/assign.pass.cpp new file mode 100644 index 000000000000..5f145552511c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// poisson_distribution& operator=(const poisson_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::poisson_distribution<> D; + D d1(0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/copy.pass.cpp new file mode 100644 index 000000000000..8abf7ffbd536 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// poisson_distribution(const poisson_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::poisson_distribution<> D; + D d1(1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_double.pass.cpp new file mode 100644 index 000000000000..0cc82cac5065 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_double.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// explicit poisson_distribution(RealType lambda = 1.0); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + D d; + assert(d.mean() == 1); + } + { + typedef std::poisson_distribution<> D; + D d(3.5); + assert(d.mean() == 3.5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_param.pass.cpp new file mode 100644 index 000000000000..a24d7550b7d7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/ctor_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// explicit poisson_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type P; + P p(0.25); + D d(p); + assert(d.mean() == 0.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eq.pass.cpp new file mode 100644 index 000000000000..7bea12ec6cb1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// bool operator=(const poisson_distribution& x, +// const poisson_distribution& y); +// bool operator!(const poisson_distribution& x, +// const poisson_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + D d1(.25); + D d2(.25); + assert(d1 == d2); + } + { + typedef std::poisson_distribution<> D; + D d1(.28); + D d2(.25); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval.pass.cpp new file mode 100644 index 000000000000..f5598978bf0a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval.pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// 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 poisson_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::poisson_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(2); + const int N = 100000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.mean(); + double x_var = d.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::poisson_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(0.75); + const int N = 100000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.mean(); + double x_var = d.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::poisson_distribution<> D; + typedef std::mt19937 G; + G g; + D d(20); + const int N = 1000000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.mean(); + double x_var = d.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval_param.pass.cpp new file mode 100644 index 000000000000..c3bbdeb0ed6c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/eval_param.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// 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 poisson_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::poisson_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(.75); + P p(2); + const int N = 100000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.mean(); + double x_var = p.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::poisson_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(2); + P p(.75); + const int N = 100000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.mean(); + double x_var = p.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04); + } + { + typedef std::poisson_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2); + P p(20); + const int N = 1000000; + std::vector<double> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v && v <= d.max()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.mean(); + double x_var = p.mean(); + double x_skew = 1 / std::sqrt(x_var); + double x_kurtosis = 1 / x_var; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/get_param.pass.cpp new file mode 100644 index 000000000000..3f5f36769836 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type P; + P p(.125); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/io.pass.cpp new file mode 100644 index 000000000000..63805591bab4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// template <class CharT, class Traits, class IntType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const poisson_distribution<RealType>& x); + +// template <class CharT, class Traits, class IntType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// poisson_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::poisson_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/max.pass.cpp new file mode 100644 index 000000000000..2dffab3d15fc --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + D d(.25); + D::result_type m = d.max(); + assert(m == std::numeric_limits<int>::max()); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/min.pass.cpp new file mode 100644 index 000000000000..607d49b0e8bc --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + D d(.5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_assign.pass.cpp new file mode 100644 index 000000000000..1c31ea34a07c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_assign.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p0(.7); + param_type p; + p = p0; + assert(p.mean() == .7); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_copy.pass.cpp new file mode 100644 index 000000000000..19c05136e3f4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_copy.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p0(.125); + param_type p = p0; + assert(p.mean() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_ctor.pass.cpp new file mode 100644 index 000000000000..081e3a2d5551 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_ctor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.mean() == 1); + } + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.mean() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_eq.pass.cpp new file mode 100644 index 000000000000..cbee35845063 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.75); + assert(p1 == p2); + } + { + typedef std::poisson_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75); + param_type p2(0.5); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_types.pass.cpp new file mode 100644 index 000000000000..c3136e048e03 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::poisson_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/set_param.pass.cpp new file mode 100644 index 000000000000..86fe1f422a3a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class poisson_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::poisson_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/types.pass.cpp new file mode 100644 index 000000000000..05e8b112e5b3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class poisson_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::poisson_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::poisson_distribution<unsigned long long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, unsigned long long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/assign.pass.cpp new file mode 100644 index 000000000000..31a2c4ad6899 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// weibull_distribution& operator=(const weibull_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::weibull_distribution<> D; + D d1(20, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/copy.pass.cpp new file mode 100644 index 000000000000..68ef4dfea51b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// weibull_distribution(const weibull_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::weibull_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_double_double.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_double_double.pass.cpp new file mode 100644 index 000000000000..34c6705641c4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// explicit weibull_distribution(result_type a = 0, result_type b = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + D d; + assert(d.a() == 1); + assert(d.b() == 1); + } + { + typedef std::weibull_distribution<> D; + D d(14.5); + assert(d.a() == 14.5); + assert(d.b() == 1); + } + { + typedef std::weibull_distribution<> D; + D d(14.5, 5.25); + assert(d.a() == 14.5); + assert(d.b() == 5.25); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_param.pass.cpp new file mode 100644 index 000000000000..5db4f1da7ef9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// explicit weibull_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.a() == 0.25); + assert(d.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eq.pass.cpp new file mode 100644 index 000000000000..4c681c18b2f4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// bool operator=(const weibull_distribution& x, +// const weibull_distribution& y); +// bool operator!(const weibull_distribution& x, +// const weibull_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::weibull_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval.pass.cpp new file mode 100644 index 000000000000..e414932dc870 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval.pass.cpp @@ -0,0 +1,166 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class weibull_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::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(0.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.b() * std::tgamma(1 + 1/d.a()); + double x_var = sqr(d.b()) * std::tgamma(1 + 2/d.a()) - sqr(x_mean); + double x_skew = (sqr(d.b())*d.b() * std::tgamma(1 + 3/d.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(d.b())) * std::tgamma(1 + 4/d.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1, .5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.b() * std::tgamma(1 + 1/d.a()); + double x_var = sqr(d.b()) * std::tgamma(1 + 2/d.a()) - sqr(x_mean); + double x_skew = (sqr(d.b())*d.b() * std::tgamma(1 + 3/d.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(d.b())) * std::tgamma(1 + 4/d.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = d.b() * std::tgamma(1 + 1/d.a()); + double x_var = sqr(d.b()) * std::tgamma(1 + 2/d.a()) - sqr(x_mean); + double x_skew = (sqr(d.b())*d.b() * std::tgamma(1 + 3/d.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(d.b())) * std::tgamma(1 + 4/d.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval_param.pass.cpp new file mode 100644 index 000000000000..6da705eb26c7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/eval_param.pass.cpp @@ -0,0 +1,169 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class weibull_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::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(0.5, 2); + P p(1, .5); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.b() * std::tgamma(1 + 1/p.a()); + double x_var = sqr(p.b()) * std::tgamma(1 + 2/p.a()) - sqr(x_mean); + double x_skew = (sqr(p.b())*p.b() * std::tgamma(1 + 3/p.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(p.b())) * std::tgamma(1 + 4/p.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(1, .5); + P p(2, 3); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.b() * std::tgamma(1 + 1/p.a()); + double x_var = sqr(p.b()) * std::tgamma(1 + 2/p.a()) - sqr(x_mean); + double x_skew = (sqr(p.b())*p.b() * std::tgamma(1 + 3/p.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(p.b())) * std::tgamma(1 + 4/p.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + typedef std::mt19937 G; + G g; + D d(2, 3); + P p(.5, 2); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(d.min() <= v); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = p.b() * std::tgamma(1 + 1/p.a()); + double x_var = sqr(p.b()) * std::tgamma(1 + 2/p.a()) - sqr(x_mean); + double x_skew = (sqr(p.b())*p.b() * std::tgamma(1 + 3/p.a()) - + 3*x_mean*x_var - sqr(x_mean)*x_mean) / + (std::sqrt(x_var)*x_var); + double x_kurtosis = (sqr(sqr(p.b())) * std::tgamma(1 + 4/p.a()) - + 4*x_skew*x_var*sqrt(x_var)*x_mean - + 6*sqr(x_mean)*x_var - sqr(sqr(x_mean))) / sqr(x_var) - 3; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs((skew - x_skew) / x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/get_param.pass.cpp new file mode 100644 index 000000000000..5047a93e663e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/io.pass.cpp new file mode 100644 index 000000000000..73b9aedbacf6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// template <class CharT, class Traits, class RealType> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, +// const weibull_distribution<RealType>& x); + +// template <class CharT, class Traits, class RealType> +// basic_istream<CharT, Traits>& +// operator>>(basic_istream<CharT, Traits>& is, +// weibull_distribution<RealType>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::weibull_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/max.pass.cpp new file mode 100644 index 000000000000..d3a44b305aa6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/min.pass.cpp new file mode 100644 index 000000000000..fee46ab51ea8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + D d(.5, .5); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_assign.pass.cpp new file mode 100644 index 000000000000..2d978cda24b6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.a() == .75); + assert(p.b() == 6); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_copy.pass.cpp new file mode 100644 index 000000000000..815a2c732674 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.a() == 10); + assert(p.b() == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_ctor.pass.cpp new file mode 100644 index 000000000000..3f9e29f8d7c5 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 1); + assert(p.b() == 1); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.a() == 10); + assert(p.b() == 1); + } + { + typedef std::weibull_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.a() == 10); + assert(p.b() == 5); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_eq.pass.cpp new file mode 100644 index 000000000000..b94e6c19b474 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::weibull_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::weibull_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_types.pass.cpp new file mode 100644 index 000000000000..102f68d4774e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::weibull_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/set_param.pass.cpp new file mode 100644 index 000000000000..b200e43c5e08 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution; + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::weibull_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/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/types.pass.cpp new file mode 100644 index 000000000000..6f82c70473ea --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class weibull_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::weibull_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::weibull_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp new file mode 100644 index 000000000000..aee3f74f26c8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/assign.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// discrete_distribution& operator=(const discrete_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::discrete_distribution<> D; + double p[] = {2, 4, 1, 8}; + D d1(p, p+4); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp new file mode 100644 index 000000000000..b133ac708da1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// discrete_distribution(const discrete_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::discrete_distribution<> D; + double p[] = {2, 4, 1, 8}; + D d1(p, p+4); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp new file mode 100644 index 000000000000..3c1ed6a186e1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_default.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// discrete_distribution(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp new file mode 100644 index 000000000000..34af69382c18 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_func.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// template<class UnaryOperation> +// discrete_distribution(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return x+1; +} + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d(0, 0, 1, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d(1, 0, 1, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d(2, 0.5, 1.5, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == .4375); + assert(p[1] == .5625); + } + { + typedef std::discrete_distribution<> D; + D d(4, 0, 2, fw); + std::vector<double> p = d.probabilities(); + assert(p.size() == 4); + assert(p[0] == .15625); + assert(p[1] == .21875); + assert(p[2] == .28125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp new file mode 100644 index 000000000000..bc4494b9848e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_init.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// discrete_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + D d = {}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d = {10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + D d = {10, 30}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + D d = {30, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {30, 0, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {0, 30, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + D d = {0, 0, 10}; + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp new file mode 100644 index 000000000000..65e14eeed2a9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_iterator.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// template<class InputIterator> +// discrete_distribution(InputIterator firstW, InputIterator lastW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {1}; + D d(p0, p0); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10}; + D d(p0, p0+1); + std::vector<double> p = d.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10, 30}; + D d(p0, p0+2); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {30, 10}; + D d(p0, p0+2); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {30, 0, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {0, 30, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {0, 0, 10}; + D d(p0, p0+3); + std::vector<double> p = d.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp new file mode 100644 index 000000000000..c12fe45db92b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/ctor_param.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// explicit discrete_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10, 30}; + P pa(p0, p0+2); + D d(pa); + std::vector<double> p = d.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp new file mode 100644 index 000000000000..bad06987b0ca --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eq.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// bool operator=(const discrete_distribution& x, +// const discrete_distribution& y); +// bool operator!(const discrete_distribution& x, +// const discrete_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {1}; + D d1(p0, p0+1); + D d2; + assert(d1 == d2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {10, 30}; + D d1(p0, p0+2); + D d2; + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp new file mode 100644 index 000000000000..55080b252028 --- /dev/null +++ b/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); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp new file mode 100644 index 000000000000..8d8a22424091 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/eval_param.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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, const param_type& parm); + +#include <random> +#include <vector> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d; + double p0[] = {.3, .1, .6}; + P p(p0, p0+3); + const int N = 10000000; + std::vector<D::result_type> u(3); + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(0 <= v && v <= 2); + u[v]++; + } + std::vector<double> prob = p.probabilities(); + for (int i = 0; i <= 2; ++i) + assert(std::abs((double)u[i]/N - prob[i]) / prob[i] < 0.001); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp new file mode 100644 index 000000000000..4970c5aae404 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/get_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {.3, .1, .6}; + P p(p0, p0+3); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp new file mode 100644 index 000000000000..92499501659d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/io.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const discrete_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// discrete_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d1(p0, p0+3); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp new file mode 100644 index 000000000000..b1d1acdab503 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/max.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d(p0, p0+3); + assert(d.max() == 2); + } + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6, .2}; + D d(p0, p0+4); + assert(d.max() == 3); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp new file mode 100644 index 000000000000..ab9383238140 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/min.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + double p0[] = {.3, .1, .6}; + D d(p0, p0+3); + assert(d.min() == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp new file mode 100644 index 000000000000..ea57852b62cd --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double d0[] = {.3, .1, .6}; + param_type p0(d0, d0+3); + param_type p; + p = p0; + assert(p == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp new file mode 100644 index 000000000000..b65ebb0d8c73 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double d0[] = {.3, .1, .6}; + param_type p0(d0, d0+3); + param_type p = p0; + assert(p == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp new file mode 100644 index 000000000000..1071305f4db7 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_default.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// param_type(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {1}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp new file mode 100644 index 000000000000..6d43b2234fc2 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_func.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// template<class UnaryOperation> +// param_type(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return x+1; +} + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(0, 0, 1, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(1, 0, 1, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(2, 0.5, 1.5, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == .4375); + assert(p[1] == .5625); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa(4, 0, 2, fw); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 4); + assert(p[0] == .15625); + assert(p[1] == .21875); + assert(p[2] == .28125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp new file mode 100644 index 000000000000..79d8a0b71a92 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_init.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// param_type(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {10, 30}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {30, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {30, 0, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {0, 30, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + P pa = {0, 0, 10}; + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp new file mode 100644 index 000000000000..7ef646707c14 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_ctor_iterator.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// template<class InputIterator> +// param_type(InputIterator firstW, InputIterator lastW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {1}; + P pa(p0, p0); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10}; + P pa(p0, p0+1); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 1); + assert(p[0] == 1); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {10, 30}; + P pa(p0, p0+2); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.25); + assert(p[1] == 0.75); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {30, 10}; + P pa(p0, p0+2); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 2); + assert(p[0] == 0.75); + assert(p[1] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {30, 0, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0.75); + assert(p[1] == 0); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {0, 30, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0.75); + assert(p[2] == 0.25); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double p0[] = {0, 0, 10}; + P pa(p0, p0+3); + std::vector<double> p = pa.probabilities(); + assert(p.size() == 3); + assert(p[0] == 0); + assert(p[1] == 0); + assert(p[2] == 1); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp new file mode 100644 index 000000000000..6ec2c2aad4b1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_eq.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double p0[] = {30, 10}; + param_type p1(p0, p0+2); + param_type p2(p0, p0+2); + assert(p1 == p2); + } + { + typedef std::discrete_distribution<> D; + typedef D::param_type param_type; + double p0[] = {30, 10}; + param_type p1(p0, p0+2); + param_type p2; + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp new file mode 100644 index 000000000000..086b7600feb0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::discrete_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/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp new file mode 100644 index 000000000000..bc433ec75644 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/set_param.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::param_type P; + double d0[] = {.3, .1, .6}; + P p(d0, d0+3); + D d; + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp new file mode 100644 index 000000000000..af73008ff418 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class IntType = int> +// class discrete_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::discrete_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, int>::value), ""); + } + { + typedef std::discrete_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp new file mode 100644 index 000000000000..e5c994445d44 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/assign.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// piecewise_constant_distribution& operator=(const piecewise_constant_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_constant_distribution<> D; + double p[] = {2, 4, 1, 8}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.pass.cpp new file mode 100644 index 000000000000..a3eb1f4a5038 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// piecewise_constant_distribution(const piecewise_constant_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_constant_distribution<> D; + double p[] = {2, 4, 1, 8}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp new file mode 100644 index 000000000000..d4f339fe7f3b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// piecewise_constant_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_distribution<> D; + D d; + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp new file mode 100644 index 000000000000..74fa23442687 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_func.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// template<class UnaryOperation> +// piecewise_constant_distribution(size_t nw, result_type xmin, +// result_type xmax, UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + D d(0, 0, 1, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + D d(1, 10, 12, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + D d(2, 6, 14, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.1); + assert(dn[1] == 0.15); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp new file mode 100644 index 000000000000..5708e45093cb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_init_func.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// piecewise_constant_distribution(initializer_list<result_type> bl, +// UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_distribution<> D; + D d({}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + D d({12}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + D d({12, 14}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 12); + assert(iv[1] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + D d({5.5, 7.5, 11.5}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 5.5); + assert(iv[1] == 7.5); + assert(iv[2] == 11.5); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.203125); + assert(dn[1] == 0.1484375); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp new file mode 100644 index 000000000000..d994b0a802b1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// template<class InputIterator> +// piecewise_constant_distribution(InputIteratorB firstB, +// InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b+1, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 15}; + double p[] = {12}; + D d(b, b+2, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = d.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1/5.); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 15, 16}; + double p[] = {.25, .75}; + D d(b, b+3, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == .25/5.); + assert(dn[1] == .75); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + D d(b, b+4, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.pass.cpp new file mode 100644 index 000000000000..0ccdba6b964d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/ctor_param.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// explicit piecewise_constant_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P pa(b, b+4, p); + D d(pa); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp new file mode 100644 index 000000000000..2ef9d7b6e0f3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eq.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// bool operator=(const piecewise_constant_distribution& x, +// const piecewise_constant_distribution& y); +// bool operator!(const piecewise_constant_distribution& x, +// const piecewise_constant_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + D d1(b, b+4, p); + D d2(b, b+4, p); + assert(d1 == d2); + } + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + D d1(b, b+4, p); + D d2; + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp new file mode 100644 index 000000000000..5d14b3612b2e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp @@ -0,0 +1,695 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class piecewise_constant_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 0, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 0, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 25, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 0, 1}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {75, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {0, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } + { + typedef std::piecewise_constant_distribution<> D; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14}; + double p[] = {1}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp new file mode 100644 index 000000000000..6850115875bb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class piecewise_constant_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d; + P pa(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, pa); + assert(10 <= v && v < 17); + u.push_back(v); + } + std::vector<double> prob(std::begin(p), std::end(p)); + double s = std::accumulate(prob.begin(), prob.end(), 0.0); + for (int i = 0; i < prob.size(); ++i) + prob[i] /= s; + std::sort(u.begin(), u.end()); + for (int i = 0; i < Np; ++i) + { + typedef std::vector<D::result_type>::iterator I; + I lb = std::lower_bound(u.begin(), u.end(), b[i]); + I ub = std::lower_bound(u.begin(), u.end(), b[i+1]); + const size_t Ni = ub - lb; + if (prob[i] == 0) + assert(Ni == 0); + else + { + assert(std::abs((double)Ni/N - prob[i]) / prob[i] < .01); + double mean = std::accumulate(lb, ub, 0.0) / Ni; + double var = 0; + double skew = 0; + double kurtosis = 0; + for (I j = lb; j != ub; ++j) + { + double d = (*j - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= Ni; + double dev = std::sqrt(var); + skew /= Ni * dev * var; + kurtosis /= Ni * var * var; + kurtosis -= 3; + double x_mean = (b[i+1] + b[i]) / 2; + double x_var = sqr(b[i+1] - b[i]) / 12; + double x_skew = 0; + double x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + } + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/get_param.pass.cpp new file mode 100644 index 000000000000..fdda4e8f0d6b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/get_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P pa(b, b+Np+1, p); + D d(pa); + assert(d.param() == pa); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.pass.cpp new file mode 100644 index 000000000000..9af776d549a6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/io.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const piecewise_constant_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// piecewise_constant_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d1(b, b+Np+1, p); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.pass.cpp new file mode 100644 index 000000000000..772c36ed73e3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/max.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + assert(d.max() == 17); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.pass.cpp new file mode 100644 index 000000000000..66618ba95d73 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/min.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np+1, p); + assert(d.min() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_assign.pass.cpp new file mode 100644 index 000000000000..4d3a503584ee --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np+1, p); + P p1; + p1 = p0; + assert(p1 == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp new file mode 100644 index 000000000000..de63a54edfbe --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np+1, p); + P p1 = p0; + assert(p1 == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.pass.cpp new file mode 100644 index 000000000000..fd84d46713c0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_default.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// param_type(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa; + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp new file mode 100644 index 000000000000..98e3006f3e32 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_func.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// template<class UnaryOperation> +// param_type(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa(0, 0, 1, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa(1, 10, 12, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa(2, 6, 14, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.1); + assert(dn[1] == 0.15); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp new file mode 100644 index 000000000000..fa6530979ed8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_init_func.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// param_type(initializer_list<result_type> bl, UnaryOperation fw); + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({12}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({12, 14}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 12); + assert(iv[1] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 0.5); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + P pa({5.5, 7.5, 11.5}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 5.5); + assert(iv[1] == 7.5); + assert(iv[2] == 11.5); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0.203125); + assert(dn[1] == 0.1484375); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp new file mode 100644 index 000000000000..98d467c07e23 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// template<class InputIterator> +// param_type(InputIteratorB firstB, InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b+1, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15}; + double p[] = {12}; + P pa(b, b+2, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 1); + assert(dn[0] == 1/5.); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15, 16}; + double p[] = {.25, .75}; + P pa(b, b+3, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == .25/5.); + assert(dn[1] == .75); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P pa(b, b+4, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == .0625); + assert(dn[1] == .3125); + assert(dn[2] == .125); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.pass.cpp new file mode 100644 index 000000000000..9cc554e604af --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_eq.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P p1(b, b+4, p); + P p2(b, b+4, p); + assert(p1 == p2); + } + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P p1(b, b+3, p); + P p2(b, b+4, p); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_types.pass.cpp new file mode 100644 index 000000000000..e039df36c98a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_constant_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/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.pass.cpp new file mode 100644 index 000000000000..1a3fedb0940f --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/set_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5}; + P pa(b, b+4, p); + D d; + d.param(pa); + assert(d.param() == pa); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.pass.cpp new file mode 100644 index 000000000000..760325979738 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_constant_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_constant_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::piecewise_constant_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp new file mode 100644 index 000000000000..0ba7dcb59198 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/assign.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// piecewise_linear_distribution& operator=(const piecewise_linear_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_linear_distribution<> D; + double p[] = {2, 4, 1, 8, 3}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp new file mode 100644 index 000000000000..536b139dda61 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// piecewise_linear_distribution(const piecewise_linear_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::piecewise_linear_distribution<> D; + double p[] = {2, 4, 1, 8, 2}; + double b[] = {2, 4, 5, 8, 9}; + D d1(b, b+5, p); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp new file mode 100644 index 000000000000..745bd6b97ec8 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_default.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// piecewise_linear_distribution(initializer_list<double> wl); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_linear_distribution<> D; + D d; + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp new file mode 100644 index 000000000000..3ebaf77f7564 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_func.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// template<class UnaryOperation> +// piecewise_linear_distribution(size_t nw, result_type xmin, +// result_type xmax, UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + D d(0, 0, 1, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0); + assert(dn[1] == 2); + } + { + typedef std::piecewise_linear_distribution<> D; + D d(1, 10, 12, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + D d(2, 6, 14, fw); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp new file mode 100644 index 000000000000..44c76f0cf6cb --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_init_func.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// piecewise_linear_distribution(initializer_list<result_type> bl, +// UnaryOperation fw); + +#include <iostream> + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_linear_distribution<> D; + D d({}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({12}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({10, 12}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + D d({6, 10, 14}, f); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp new file mode 100644 index 000000000000..5fce58bbd978 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// template<class InputIterator> +// piecewise_linear_distribution(InputIteratorB firstB, +// InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10}; + double p[] = {12}; + D d(b, b+1, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 15}; + double p[] = {20, 20}; + D d(b, b+2, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = d.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1/5.); + assert(dn[1] == 1/5.); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 15, 16}; + double p[] = {.25, .75, .25}; + D d(b, b+3, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = d.densities(); + assert(dn.size() == 3); + assert(dn[0] == .25/3); + assert(dn[1] == .75/3); + assert(dn[2] == .25/3); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + D d(b, b+4, p); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 4); + assert(dn[0] == 0); + assert(dn[1] == 1/4.5); + assert(dn[2] == 1/4.5); + assert(dn[3] == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp new file mode 100644 index 000000000000..7dc47b4a3a2e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/ctor_param.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// explicit piecewise_linear_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P pa(b, b+4, p); + D d(pa); + std::vector<double> iv = d.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = d.densities(); + assert(dn.size() == 4); + assert(dn[0] == 25/256.25); + assert(dn[1] == 62.5/256.25); + assert(dn[2] == 12.5/256.25); + assert(dn[3] == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp new file mode 100644 index 000000000000..766989c58899 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eq.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// bool operator=(const piecewise_linear_distribution& x, +// const piecewise_linear_distribution& y); +// bool operator!(const piecewise_linear_distribution& x, +// const piecewise_linear_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + D d1; + D d2; + assert(d1 == d2); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 1}; + D d1(b, b+4, p); + D d2(b, b+4, p); + assert(d1 == d2); + } + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + D d1(b, b+4, p); + D d2; + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp new file mode 100644 index 000000000000..af75fce512e4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp @@ -0,0 +1,343 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class piecewise_linear_distribution + +// template<class _URNG> result_type operator()(_URNG& g); + +#include <iostream> + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +double +f(double x, double a, double m, double b, double c) +{ + return a + m*(sqr(x) - sqr(b))/2 + c*(x-b); +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 0, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {1, 0, 0, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16}; + double p[] = {0, 1, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14}; + double p[] = {1, 1}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.min() <= v && v < d.max()); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp new file mode 100644 index 000000000000..fe704228e788 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class piecewise_linear_distribution + +// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm); + +#include <random> +#include <vector> +#include <iterator> +#include <numeric> +#include <cassert> + +template <class T> +inline +T +sqr(T x) +{ + return x*x; +} + +double +f(double x, double a, double m, double b, double c) +{ + return a + m*(sqr(x) - sqr(b))/2 + c*(x-b); +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + typedef std::mt19937_64 G; + G g; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]) - 1; + D d; + P pa(b, b+Np+1, p); + const int N = 1000000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, pa); + assert(10 <= v && v < 17); + u.push_back(v); + } + std::sort(u.begin(), u.end()); + int kp = -1; + double a; + double m; + double bk; + double c; + std::vector<double> areas(Np); + double S = 0; + for (int i = 0; i < areas.size(); ++i) + { + areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; + S += areas[i]; + } + for (int i = 0; i < areas.size(); ++i) + areas[i] /= S; + for (int i = 0; i < Np+1; ++i) + p[i] /= S; + for (int i = 0; i < N; ++i) + { + int k = std::lower_bound(b, b+Np+1, u[i]) - b - 1; + if (k != kp) + { + a = 0; + for (int j = 0; j < k; ++j) + a += areas[j]; + m = (p[k+1] - p[k]) / (b[k+1] - b[k]); + bk = b[k]; + c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); + kp = k; + } + assert(std::abs(f(u[i], a, m, bk, c) - double(i)/N) < .001); + } + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp new file mode 100644 index 000000000000..57a8ca5589c3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/get_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 10}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P pa(b, b+Np, p); + D d(pa); + assert(d.param() == pa); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp new file mode 100644 index 000000000000..1be2791fa47a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/io.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const piecewise_linear_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// piecewise_linear_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 25}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d1(b, b+Np, p); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp new file mode 100644 index 000000000000..3dc12b692535 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/max.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np, p); + assert(d.max() == 17); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp new file mode 100644 index 000000000000..4d4a7603a018 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/min.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + const size_t Np = sizeof(p) / sizeof(p[0]); + D d(b, b+Np, p); + assert(d.min() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp new file mode 100644 index 000000000000..055b2f58e792 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 2}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np, p); + P p1; + p1 = p0; + assert(p1 == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp new file mode 100644 index 000000000000..87d94940a870 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 5}; + const size_t Np = sizeof(p) / sizeof(p[0]); + P p0(b, b+Np, p); + P p1 = p0; + assert(p1 == p0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp new file mode 100644 index 000000000000..0bdf2c337d27 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// param_type(); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa; + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp new file mode 100644 index 000000000000..27e93ab6171b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_func.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// template<class UnaryOperation> +// param_type(size_t nw, double xmin, double xmax, +// UnaryOperation fw); + +#include <random> +#include <cassert> + +double fw(double x) +{ + return 2*x; +} + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(0, 0, 1, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 0); + assert(dn[1] == 2); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(1, 10, 12, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa(2, 6, 14, fw); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp new file mode 100644 index 000000000000..cfa416434a29 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// param_type(initializer_list<result_type> bl, UnaryOperation fw); + +#include <random> +#include <cassert> + +double f(double x) +{ + return x*2; +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({12}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({10, 12}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 12); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 20./44); + assert(dn[1] == 24./44); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + P pa({6, 10, 14}, f); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 6); + assert(iv[1] == 10); + assert(iv[2] == 14); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == 0.075); + assert(dn[1] == 0.125); + assert(dn[2] == 0.175); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp new file mode 100644 index 000000000000..117a5ef93bb0 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// template<class InputIterator> +// param_type(InputIteratorB firstB, InputIteratorB lastB, +// InputIteratorW firstW); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10}; + double p[] = {12}; + P pa(b, b+1, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 0); + assert(iv[1] == 1); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1); + assert(dn[1] == 1); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15}; + double p[] = {12, 12}; + P pa(b, b+2, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 2); + assert(iv[0] == 10); + assert(iv[1] == 15); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 2); + assert(dn[0] == 1/5.); + assert(dn[1] == 1/5.); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 15, 16}; + double p[] = {.25, .75, .25}; + P pa(b, b+3, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 3); + assert(iv[0] == 10); + assert(iv[1] == 15); + assert(iv[2] == 16); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 3); + assert(dn[0] == .25/3); + assert(dn[1] == .75/3); + assert(dn[2] == .25/3); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {0, 1, 1, 0}; + P pa(b, b+4, p); + std::vector<double> iv = pa.intervals(); + assert(iv.size() == 4); + assert(iv[0] == 10); + assert(iv[1] == 14); + assert(iv[2] == 16); + assert(iv[3] == 17); + std::vector<double> dn = pa.densities(); + assert(dn.size() == 4); + assert(dn[0] == 0); + assert(dn[1] == 1/4.5); + assert(dn[2] == 1/4.5); + assert(dn[3] == 0); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp new file mode 100644 index 000000000000..1adffc8ca868 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_eq.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P p1(b, b+4, p); + P p2(b, b+4, p); + assert(p1 == p2); + } + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P p1(b, b+3, p); + P p2(b, b+4, p); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp new file mode 100644 index 000000000000..cea1e3dffd31 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_linear_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/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp new file mode 100644 index 000000000000..e85a2f0ce4c2 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/set_param.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::param_type P; + double b[] = {10, 14, 16, 17}; + double p[] = {25, 62.5, 12.5, 0}; + P pa(b, b+4, p); + D d; + d.param(pa); + assert(d.param() == pa); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp new file mode 100644 index 000000000000..a34212987878 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/types.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class piecewise_linear_distribution +// { +// typedef bool result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::piecewise_linear_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, double>::value), ""); + } + { + typedef std::piecewise_linear_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/assign.pass.cpp new file mode 100644 index 000000000000..0e04ea455e7e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// uniform_int_distribution& operator=(const uniform_int_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_int_distribution<long> D; + D d1(2, 5); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/copy.pass.cpp new file mode 100644 index 000000000000..c09830c6277a --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// uniform_int_distribution(const uniform_int_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_int_distribution<long> D; + D d1(2, 5); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_int_int.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_int_int.pass.cpp new file mode 100644 index 000000000000..68f2ec0975a9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_int_int.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// explicit uniform_int_distribution(IntType a = 0, +// IntType b = numeric_limits<IntType>::max()); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + D d; + assert(d.a() == 0); + assert(d.b() == std::numeric_limits<int>::max()); + } + { + typedef std::uniform_int_distribution<> D; + D d(-6); + assert(d.a() == -6); + assert(d.b() == std::numeric_limits<int>::max()); + } + { + typedef std::uniform_int_distribution<> D; + D d(-6, 106); + assert(d.a() == -6); + assert(d.b() == 106); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_param.pass.cpp new file mode 100644 index 000000000000..cc3e86a42bd6 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// explicit uniform_int_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(p); + assert(d.a() == 3); + assert(d.b() == 8); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eq.pass.cpp new file mode 100644 index 000000000000..b7a5cffbe564 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// bool operator=(const uniform_int_distribution& x, +// const uniform_int_distribution& y); +// bool operator!(const uniform_int_distribution& x, +// const uniform_int_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + D d1(3, 8); + D d2(3, 8); + assert(d1 == d2); + } + { + typedef std::uniform_int_distribution<> D; + D d1(3, 8); + D d2(3, 9); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp new file mode 100644 index 000000000000..66693a8da55b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp @@ -0,0 +1,455 @@ +//===----------------------------------------------------------------------===// +// +// 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 uniform_int_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::uniform_int_distribution<> D; + typedef std::minstd_rand0 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::minstd_rand G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::mt19937 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::mt19937_64 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::ranlux24_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::ranlux48_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::ranlux24 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::ranlux48 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::knuth_b G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_int_distribution<> D; + typedef std::minstd_rand0 G; + G g; + D d(-6, 106); + for (int i = 0; i < 10000; ++i) + { + int u = d(g); + assert(-6 <= u && u <= 106); + } + } + { + typedef std::uniform_int_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(5, 100); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v <= d.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)d.a() + d.b()) / 2; + double x_var = (sqr((double)d.b() - d.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)d.b() - d.a() + 1) + 1) / + (5. * (sqr((double)d.b() - d.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval_param.pass.cpp new file mode 100644 index 000000000000..d83d48cac1e3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval_param.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_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::uniform_int_distribution<> D; + typedef std::minstd_rand G; + typedef D::param_type P; + G g; + D d(5, 100); + P p(-10, 20); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(p.a() <= v && v <= p.b()); + u.push_back(v); + } + double mean = std::accumulate(u.begin(), u.end(), + double(0)) / u.size(); + double var = 0; + double skew = 0; + double kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + double d = (u[i] - mean); + double d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + double dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + double x_mean = ((double)p.a() + p.b()) / 2; + double x_var = (sqr((double)p.b() - p.a() + 1) - 1) / 12; + double x_skew = 0; + double x_kurtosis = -6. * (sqr((double)p.b() - p.a() + 1) + 1) / + (5. * (sqr((double)p.b() - p.a() + 1) - 1)); + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/get_param.pass.cpp new file mode 100644 index 000000000000..ab8fa6c98363 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/io.pass.cpp new file mode 100644 index 000000000000..0220a5aa9570 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const uniform_int_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// uniform_int_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + D d1(3, 8); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/max.pass.cpp new file mode 100644 index 000000000000..c0a262f8a88c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + D d(3, 8); + assert(d.max() == 8); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/min.pass.cpp new file mode 100644 index 000000000000..3a0d3b2d94be --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + D d(3, 8); + assert(d.min() == 3); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_assign.pass.cpp new file mode 100644 index 000000000000..09c56097142d --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p; + p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_copy.pass.cpp new file mode 100644 index 000000000000..1f01e9858c34 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_ctor.pass.cpp new file mode 100644 index 000000000000..eba933c01911 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 0); + assert(p.b() == std::numeric_limits<long>::max()); + } + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p(5); + assert(p.a() == 5); + assert(p.b() == std::numeric_limits<long>::max()); + } + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p(5, 10); + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_eq.pass.cpp new file mode 100644 index 000000000000..5831f96b6b36 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(5, 10); + assert(p1 == p2); + } + { + typedef std::uniform_int_distribution<long> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(6, 10); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_types.pass.cpp new file mode 100644 index 000000000000..4022cfb6102b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_int_distribution<long> 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/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/set_param.pass.cpp new file mode 100644 index 000000000000..823837ba68e9 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_int_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(6, 7); + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/types.pass.cpp new file mode 100644 index 000000000000..65c01d037885 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class _IntType = int> +// class uniform_int_distribution +// { +// typedef IntType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_int_distribution<long> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, long>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp new file mode 100644 index 000000000000..9651a2f0596b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// uniform_real_distribution& operator=(const uniform_real_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_real_distribution<float> D; + D d1(2, 5); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp new file mode 100644 index 000000000000..073c3a851570 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// uniform_real_distribution(const uniform_real_distribution&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::uniform_real_distribution<float> D; + D d1(2, 5); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp new file mode 100644 index 000000000000..03abc5362108 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_int_int.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// explicit uniform_real_distribution(RealType a = 0, +// RealType b = 1); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d; + assert(d.a() == 0); + assert(d.b() == 1); + } + { + typedef std::uniform_real_distribution<> D; + D d(-6); + assert(d.a() == -6); + assert(d.b() == 1); + } + { + typedef std::uniform_real_distribution<> D; + D d(-6, 106); + assert(d.a() == -6); + assert(d.b() == 106); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp new file mode 100644 index 000000000000..a6f4aff93d81 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// explicit uniform_real_distribution(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3.5, 8); + D d(p); + assert(d.a() == 3.5); + assert(d.b() == 8); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp new file mode 100644 index 000000000000..5fcba4346dc1 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// bool operator=(const uniform_real_distribution& x, +// const uniform_real_distribution& y); +// bool operator!(const uniform_real_distribution& x, +// const uniform_real_distribution& y); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + D d2(3, 8); + assert(d1 == d2); + } + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + D d2(3, 8.1); + assert(d1 != d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp new file mode 100644 index 000000000000..2663b2683bb4 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp @@ -0,0 +1,474 @@ +//===----------------------------------------------------------------------===// +// +// 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 RealType = double> +// class uniform_real_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::uniform_real_distribution<> D; + typedef std::minstd_rand0 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::mt19937 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::mt19937_64 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux24_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.02); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux48_base G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux24 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::ranlux48 G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::knuth_b G; + G g; + D d; + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(-1, 1); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs(mean - x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } + { + typedef std::uniform_real_distribution<> D; + typedef std::minstd_rand G; + G g; + D d(5.5, 25); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g); + assert(d.a() <= v && v < d.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (d.a() + d.b()) / 2; + D::result_type x_var = sqr(d.b() - d.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp new file mode 100644 index 000000000000..b5803f401465 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval_param.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_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::uniform_real_distribution<> D; + typedef std::minstd_rand G; + typedef D::param_type P; + G g; + D d(5.5, 25); + P p(-10, 20); + const int N = 100000; + std::vector<D::result_type> u; + for (int i = 0; i < N; ++i) + { + D::result_type v = d(g, p); + assert(p.a() <= v && v < p.b()); + u.push_back(v); + } + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + D::result_type skew = 0; + D::result_type kurtosis = 0; + for (int i = 0; i < u.size(); ++i) + { + D::result_type d = (u[i] - mean); + D::result_type d2 = sqr(d); + var += d2; + skew += d * d2; + kurtosis += d2 * d2; + } + var /= u.size(); + D::result_type dev = std::sqrt(var); + skew /= u.size() * dev * var; + kurtosis /= u.size() * var * var; + kurtosis -= 3; + D::result_type x_mean = (p.a() + p.b()) / 2; + D::result_type x_var = sqr(p.b() - p.a()) / 12; + D::result_type x_skew = 0; + D::result_type x_kurtosis = -6./5; + assert(std::abs((mean - x_mean) / x_mean) < 0.01); + assert(std::abs((var - x_var) / x_var) < 0.01); + assert(std::abs(skew - x_skew) < 0.01); + assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp new file mode 100644 index 000000000000..0496d853e329 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// param_type param() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp new file mode 100644 index 000000000000..17ff93889308 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// template <class charT, class traits> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const uniform_real_distribution& x); +// +// template <class charT, class traits> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// uniform_real_distribution& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d1(3, 8); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp new file mode 100644 index 000000000000..6baa6d81a83c --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/max.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// result_type max() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d(3, 8); + assert(d.max() == 8); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp new file mode 100644 index 000000000000..3974258c54df --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// result_type min() const; + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + D d(3, 8); + assert(d.min() == 3); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp new file mode 100644 index 000000000000..07497fef5316 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p; + p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp new file mode 100644 index 000000000000..d64df7dacb6b --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p0(5, 10); + param_type p = p0; + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp new file mode 100644 index 000000000000..8f21ebfbdbb3 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p; + assert(p.a() == 0); + assert(p.b() == 1); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p(5); + assert(p.a() == 5); + assert(p.b() == 1); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p(5, 10); + assert(p.a() == 5); + assert(p.b() == 10); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp new file mode 100644 index 000000000000..62df68ca628e --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <limits> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(5, 10); + assert(p1 == p2); + } + { + typedef std::uniform_real_distribution<float> D; + typedef D::param_type param_type; + param_type p1(5, 10); + param_type p2(6, 10); + assert(p1 != p2); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp new file mode 100644 index 000000000000..27c0998be258 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// class param_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_real_distribution<float> 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/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp new file mode 100644 index 000000000000..1ff121def104 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution + +// void param(const param_type& parm); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::uniform_real_distribution<> D; + typedef D::param_type P; + P p(3, 8); + D d(6, 7); + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp new file mode 100644 index 000000000000..b0e792fdd624 --- /dev/null +++ b/test/std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType = double> +// class uniform_real_distribution +// { +// typedef IntType result_type; + +#include <random> +#include <type_traits> + +int main() +{ + { + typedef std::uniform_real_distribution<float> D; + typedef D::result_type result_type; + static_assert((std::is_same<result_type, float>::value), ""); + } +} diff --git a/test/std/numerics/rand/rand.eng/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.eng/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp new file mode 100644 index 000000000000..8c09f4fd0109 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// linear_congruential_engine& operator=(const linear_congruential_engine&); + +#include <random> +#include <cassert> + +template <class T, T a, T c, T m> +void +test1() +{ + typedef std::linear_congruential_engine<T, a, c, m> E; + E e1; + E e2; + assert(e1 == e2); + e1(); + e2 = e1; + assert(e1 == e2); +} + +template <class T> +void +test() +{ + test1<T, 0, 0, 0>(); + test1<T, 0, 1, 2>(); + test1<T, 1, 1, 2>(); + const T M(~0); + test1<T, 0, 0, M>(); + test1<T, 0, M-2, M>(); + test1<T, 0, M-1, M>(); + test1<T, M-2, 0, M>(); + test1<T, M-2, M-2, M>(); + test1<T, M-2, M-1, M>(); + test1<T, M-1, 0, M>(); + test1<T, M-1, M-2, M>(); + test1<T, M-1, M-1, M>(); +} + +int main() +{ + test<unsigned short>(); + test<unsigned int>(); + test<unsigned long>(); + test<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp new file mode 100644 index 000000000000..4b2b20da13ab --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// linear_congruential_engine(const linear_congruential_engine&); + +#include <random> +#include <cassert> + +template <class T, T a, T c, T m> +void +test1() +{ + typedef std::linear_congruential_engine<T, a, c, m> E; + E e1; + E e2 = e1; + assert(e1 == e2); + e1(); + e2(); + assert(e1 == e2); +} + +template <class T> +void +test() +{ + test1<T, 0, 0, 0>(); + test1<T, 0, 1, 2>(); + test1<T, 1, 1, 2>(); + const T M(~0); + test1<T, 0, 0, M>(); + test1<T, 0, M-2, M>(); + test1<T, 0, M-1, M>(); + test1<T, M-2, 0, M>(); + test1<T, M-2, M-2, M>(); + test1<T, M-2, M-1, M>(); + test1<T, M-1, 0, M>(); + test1<T, M-1, M-2, M>(); + test1<T, M-1, M-1, M>(); +} + +int main() +{ + test<unsigned short>(); + test<unsigned int>(); + test<unsigned long>(); + test<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..311b7cd8f9b9 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// explicit linear_congruential_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +template <class T> +void +test1() +{ + // c % m != 0 && s % m != 0 + { + typedef std::linear_congruential_engine<T, 2, 3, 7> E; + E e(5); + std::ostringstream os; + os << e; + assert(os.str() == "5"); + } + { + typedef std::linear_congruential_engine<T, 2, 3, 0> E; + E e(5); + std::ostringstream os; + os << e; + assert(os.str() == "5"); + } + { + typedef std::linear_congruential_engine<T, 2, 3, 4> E; + E e(5); + std::ostringstream os; + os << e; + assert(os.str() == "1"); + } +} + +template <class T> +void +test2() +{ + // c % m != 0 && s % m == 0 + { + typedef std::linear_congruential_engine<T, 2, 3, 7> E; + E e(7); + std::ostringstream os; + os << e; + assert(os.str() == "0"); + } + { + typedef std::linear_congruential_engine<T, 2, 3, 0> E; + E e(0); + std::ostringstream os; + os << e; + assert(os.str() == "0"); + } + { + typedef std::linear_congruential_engine<T, 2, 3, 4> E; + E e(4); + std::ostringstream os; + os << e; + assert(os.str() == "0"); + } +} + +template <class T> +void +test3() +{ + // c % m == 0 && s % m != 0 + { + typedef std::linear_congruential_engine<T, 2, 0, 7> E; + E e(3); + std::ostringstream os; + os << e; + assert(os.str() == "3"); + } + { + typedef std::linear_congruential_engine<T, 2, 0, 0> E; + E e(5); + std::ostringstream os; + os << e; + assert(os.str() == "5"); + } + { + typedef std::linear_congruential_engine<T, 2, 0, 4> E; + E e(7); + std::ostringstream os; + os << e; + assert(os.str() == "3"); + } +} + +template <class T> +void +test4() +{ + // c % m == 0 && s % m == 0 + { + typedef std::linear_congruential_engine<T, 2, 0, 7> E; + E e(7); + std::ostringstream os; + os << e; + assert(os.str() == "1"); + } + { + typedef std::linear_congruential_engine<T, 2, 0, 0> E; + E e(0); + std::ostringstream os; + os << e; + assert(os.str() == "1"); + } + { + typedef std::linear_congruential_engine<T, 2, 0, 4> E; + E e(8); + std::ostringstream os; + os << e; + assert(os.str() == "1"); + } +} + +int main() +{ + test1<unsigned short>(); + test1<unsigned int>(); + test1<unsigned long>(); + test1<unsigned long long>(); + + test2<unsigned short>(); + test2<unsigned int>(); + test2<unsigned long>(); + test2<unsigned long long>(); + + test3<unsigned short>(); + test3<unsigned int>(); + test3<unsigned long>(); + test3<unsigned long long>(); + + test4<unsigned short>(); + test4<unsigned int>(); + test4<unsigned long>(); + test4<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..db7118f4a631 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_sseq.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// template<class Sseq> explicit linear_congruential_engine(Sseq& q); + +#include <random> +#include <cassert> + +int main() +{ + { + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::linear_congruential_engine<unsigned, 5, 7, 11> e1(sseq); + std::linear_congruential_engine<unsigned, 5, 7, 11> e2(4); + assert(e1 == e2); + } +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp new file mode 100644 index 000000000000..6c4a7f434f12 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// linear_congruential_engine(); + +#include <random> +#include <cassert> + +template <class T, T a, T c, T m> +void +test1() +{ + typedef std::linear_congruential_engine<T, a, c, m> LCE; + typedef typename LCE::result_type result_type; + LCE e1; + LCE e2; + e2.seed(); + assert(e1 == e2); +} + +template <class T> +void +test() +{ + test1<T, 0, 0, 0>(); + test1<T, 0, 1, 2>(); + test1<T, 1, 1, 2>(); + const T M(~0); + test1<T, 0, 0, M>(); + test1<T, 0, M-2, M>(); + test1<T, 0, M-1, M>(); + test1<T, M-2, 0, M>(); + test1<T, M-2, M-2, M>(); + test1<T, M-2, M-1, M>(); + test1<T, M-1, 0, M>(); + test1<T, M-1, M-2, M>(); + test1<T, M-1, M-1, M>(); +} + +int main() +{ + test<unsigned short>(); + test<unsigned int>(); + test<unsigned long>(); + test<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/discard.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/discard.pass.cpp new file mode 100644 index 000000000000..9e3372a8c2b4 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/discard.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// void discard(unsigned long long z); + +#include <random> +#include <cassert> + +template <class T> +void +rand0() +{ + typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E; + E e; + e.discard(9999); + assert(e() == 1043618065); +} + +template <class T> +void +rand() +{ + typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E; + E e; + e.discard(9999); + assert(e() == 399268537); +} + +template <class T> +void +other() +{ + typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E; + E e1; + E e2; + assert(e1 == e2); + e1.discard(1); + assert(e1 != e2); + e2(); + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + rand0<unsigned int>(); + rand0<unsigned long>(); + rand0<unsigned long long>(); + + rand<unsigned int>(); + rand<unsigned long>(); + rand<unsigned long long>(); + + other<unsigned int>(); + other<unsigned long>(); + other<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/eval.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/eval.pass.cpp new file mode 100644 index 000000000000..6d0057d598a8 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/eval.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// result_type operator()(); + +#include <random> +#include <cassert> + +template <class T> +void +randu() +{ + typedef std::linear_congruential_engine<T, 65539, 0, 2147483648u> E; + E e(1); + assert(e() == 65539); + assert(e() == 393225); + assert(e() == 1769499); + assert(e() == 7077969); + assert(e() == 26542323); + assert(e() == 95552217); + assert(e() == 334432395); + assert(e() == 1146624417); + assert(e() == 1722371299); + assert(e() == 14608041); + assert(e() == 1766175739); + assert(e() == 1875647473); +} + +template <class T> +void +minstd() +{ + typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E; + E e(1); + assert(e() == 16807); + assert(e() == 282475249); + assert(e() == 1622650073); + assert(e() == 984943658); + assert(e() == 1144108930); + assert(e() == 470211272); + assert(e() == 101027544); + assert(e() == 1457850878); + assert(e() == 1458777923); + assert(e() == 2007237709); + assert(e() == 823564440); + assert(e() == 1115438165); +} + +template <class T> +void +Haldir() +{ + typedef std::linear_congruential_engine<T, 16807, 78125, 2147483647> E; + E e(207560540); + assert(e() == 956631177); + assert(e() == 2037688522); + assert(e() == 1509348670); + assert(e() == 1546336451); + assert(e() == 429714088); + assert(e() == 217250280); +} + +int main() +{ + randu<unsigned int>(); + randu<unsigned long>(); + randu<unsigned long long>(); + + minstd<unsigned int>(); + minstd<unsigned long>(); + minstd<unsigned long long>(); + + Haldir<unsigned int>(); + Haldir<unsigned long>(); + Haldir<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/io.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/io.pass.cpp new file mode 100644 index 000000000000..28ebdf23d0cb --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/io.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// template <class charT, class traits, +// class UIntType, UIntType a, UIntType c, UIntType m> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const linear_congruential_engine<UIntType, a, c, m>& x); +// +// template <class charT, class traits, +// class UIntType, UIntType a, UIntType c, UIntType m> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// linear_congruential_engine<UIntType, a, c, m>& x); + +#include <random> +#include <sstream> +#include <cassert> + +int main() +{ + { + typedef std::linear_congruential_engine<unsigned, 48271, 0, 2147483647> E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); + } +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/result_type.pass.cpp new file mode 100644 index 000000000000..d261f1d93ab1 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/result_type.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine +// { +// public: +// // types +// typedef UIntType result_type; + +#include <random> +#include <type_traits> + +template <class T> +void +test() +{ + static_assert((std::is_same< + typename std::linear_congruential_engine<T, 0, 0, 0>::result_type, + T>::value), ""); +} + +int main() +{ + test<unsigned short>(); + test<unsigned int>(); + test<unsigned long>(); + test<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp new file mode 100644 index 000000000000..1afbe75efa58 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +template <class T> +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::linear_congruential_engine<T, 2, 3, 7> E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1<unsigned short>(); + test1<unsigned int>(); + test1<unsigned long>(); + test1<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp new file mode 100644 index 000000000000..ca2793c7f9a7 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine; + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +int main() +{ + { + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::linear_congruential_engine<unsigned, 5, 7, 11> e1; + std::linear_congruential_engine<unsigned, 5, 7, 11> e2(4); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); + } + { + unsigned a[] = {3, 5, 7, 9, 11}; + std::seed_seq sseq(a, a+5); + typedef std::linear_congruential_engine<unsigned long long, 1, 1, 0x200000001ULL> E; + E e1(4309005589); + E e2(sseq); + assert(e1 == e2); + } +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp new file mode 100644 index 000000000000..857a478a5579 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, UIntType a, UIntType c, UIntType m> +// class linear_congruential_engine +// { +// public: +// engine characteristics +// static constexpr result_type multiplier = a; +// static constexpr result_type increment = c; +// static constexpr result_type modulus = m; +// static constexpr result_type min() { return c == 0u ? 1u: 0u;} +// static constexpr result_type max() { return m - 1u;} +// static constexpr result_type default_seed = 1u; + +#include <random> +#include <type_traits> +#include <cassert> + +template <class _Tp> +void where(const _Tp &) {} + +template <class T, T a, T c, T m> +void +test1() +{ + typedef std::linear_congruential_engine<T, a, c, m> LCE; + typedef typename LCE::result_type result_type; + static_assert((LCE::multiplier == a), ""); + static_assert((LCE::increment == c), ""); + static_assert((LCE::modulus == m), ""); + /*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/); + /*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/); + static_assert((LCE::default_seed == 1), ""); + where(LCE::multiplier); + where(LCE::increment); + where(LCE::modulus); + where(LCE::default_seed); +} + +template <class T> +void +test() +{ + test1<T, 0, 0, 0>(); + test1<T, 0, 1, 2>(); + test1<T, 1, 1, 2>(); + const T M(~0); + test1<T, 0, 0, M>(); + test1<T, 0, M-2, M>(); + test1<T, 0, M-1, M>(); + test1<T, M-2, 0, M>(); + test1<T, M-2, M-2, M>(); + test1<T, M-2, M-1, M>(); + test1<T, M-1, 0, M>(); + test1<T, M-1, M-2, M>(); + test1<T, M-1, M-1, M>(); +} + +int main() +{ + test<unsigned short>(); + test<unsigned int>(); + test<unsigned long>(); + test<unsigned long long>(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/assign.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/assign.pass.cpp new file mode 100644 index 000000000000..fda5b88de26e --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/assign.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// mersenne_twister_engine& operator=(const mersenne_twister_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::mt19937 E; + E e1(2); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::mt19937_64 E; + E e1(3); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp new file mode 100644 index 000000000000..57c015ccce1d --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// mersenne_twister_engine(const mersenne_twister_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::mt19937 E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::mt19937_64 E; + E e1; + e1(); + E e2(e1); + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..6920aaca558c --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp @@ -0,0 +1,245 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// explicit mersenne_twister_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "0 1 1812433255 1900727105 1208447044 2481403966 4042607538 337614300 " + "3232553940 1018809052 3202401494 1775180719 3192392114 594215549 184016991 " + "829906058 610491522 3879932251 3139825610 297902587 4075895579 2943625357 " + "3530655617 1423771745 2135928312 2891506774 1066338622 135451537 933040465 " + "2759011858 2273819758 3545703099 2516396728 1272276355 3172048492 " + "3267256201 2332199830 1975469449 392443598 1132453229 2900699076 " + "1998300999 3847713992 512669506 1227792182 1629110240 112303347 2142631694 " + "3647635483 1715036585 2508091258 1355887243 1884998310 3906360088 " + "952450269 3647883368 3962623343 3077504981 2023096077 3791588343 " + "3937487744 3455116780 1218485897 1374508007 2815569918 1367263917 " + "472908318 2263147545 1461547499 4126813079 2383504810 64750479 2963140275 " + "1709368606 4143643781 835933993 1881494649 674663333 2076403047 858036109 " + "1667579889 1706666497 607785554 1995775149 1941986352 3448871082 " + "2109910019 1474883361 1623095288 1831376534 2612738285 81681830 2204289242 " + "1365038485 251164610 4268495337 1805601714 1262528768 1442526919 " + "1675006593 965627108 646339161 499795587 840887574 380522518 3023789847 " + "1457635507 1947093157 2600365344 2729853143 1550618999 1390905853 " + "3021294812 882647559 838872117 1663880796 4222103589 2754172275 3844026123 " + "3199260319 4176064873 3591027019 2690294242 2978135515 3172796441 " + "3263669796 1451257057 1427035359 4174826006 2171992010 1537002090 " + "3122405306 4162452508 3271954368 3794310005 3240514581 1270412086 " + "3030475836 2281945856 2644171349 3109139423 4253563838 1289926431 " + "1396919653 733220100 2753316645 1196225013 3699575255 3569440056 " + "2675979228 2624079148 3463113149 863430286 623703199 2113837653 2656425919 " + "175981357 4271478366 4238022735 1665483419 86880610 2963435083 1830392943 " + "847801865 3237296945 332143967 3973606945 2671879697 2236330279 2360127810 " + "3283955434 203240344 4048139172 13189264 2263058814 247241371 1566765783 " + "3084408095 3719371299 1958375251 1985924622 1712739232 1861691451 " + "2644502937 2337807839 784993770 2962208780 2190810177 1523122731 " + "714888527 578678761 3698481324 1801168075 534650483 3390213921 3923356461 " + "3586009066 2059432114 52511333 1969897376 3630122061 524661135 3513619765 " + "563070233 501359785 477489274 658768624 938973567 1548584683 1345287459 " + "2488691004 3441144905 3849305094 2430000078 855172178 614463281 2092744749 " + "176381493 1655802051 2273888101 2474494847 3471978030 2138918303 575352373 " + "1658230985 1675972553 2946663114 915579339 284981499 53939948 3022598146 " + "1861218535 3403620774 4203516930 2360471119 3134536268 1383448498 " + "1307602316 3847663247 3027225131 3597251613 3186237127 725127595 " + "1928526954 1843386923 3560410503 54688266 1791983849 2519860352 4256389699 " + "2328812602 486464275 3578698363 301279829 1303654791 4181868765 971794070 " + "1933885487 3996807464 2144053754 4079903755 3775774765 3481760044 " + "1212862354 1067356423 3764189132 1609862325 2209601551 2565747501 " + "161962392 4045451782 2605574664 2520953090 3490240017 1082791980 44474324 " + "101811128 4268650669 4171338684 772375154 3920460306 2319139534 599033750 " + "2950874441 3373922995 1496848525 4095253594 1271943484 1498723121 " + "3097453329 3698082465 281869581 3148270661 3591477288 747441437 2809508504 " + "3896107498 303747862 2368081624 1844217645 886825352 287949781 1444561207 " + "2512101757 2062331723 741720931 1383797313 3876746355 2041045348 " + "2627599118 1124169970 200524822 3484820454 55883666 1135054804 669498692 " + "2677215504 3097911127 1509628615 617580381 2229022193 85601568 3243896546 " + "3715672328 912168347 2359163500 1180347564 4243175048 2092067103 880183327 " + "4000664709 2045044777 3500474644 1515175520 1862207123 186628841 " + "3337252925 708933575 4015964629 3136815297 3314919747 2891909013 " + "3316567785 3944275369 3608506218 2884839110 3054055598 2707439927 " + "1381111877 3275487281 4292456216 2639563270 3327301876 3576924628 " + "721056309 2002808140 748967365 52380958 2200261692 763456477 1708381337 " + "2038446433 2682979402 1526413779 2211263302 3879771969 75966584 3645059271 " + "2985763524 4085690255 82390958 1883631385 1647521260 1598026998 3038041577 " + "2501913134 3279302868 1738888524 805035483 756399074 3863810982 1097797270 " + "1505792529 898904527 583561003 717152376 3333867738 1099456544 1663473545 " + "1242141229 3828627682 1966201676 1713552361 3852160017 1584965284 21695908 " + "1013262144 145341901 3995441263 3462066219 2239637848 1214086163 " + "2428868268 1650037305 1545513388 1621198806 4232947817 1823092073 " + "256414624 1745018809 1357102386 2055139770 3280958307 2482431613 " + "1664870585 859130423 4097751123 3079768369 2470211009 2984880786 " + "2808568948 2877071923 1984903163 302768457 1866396789 869566317 3746415787 " + "4169433075 3025005404 3980733379 3539207278 3953071536 876960847 " + "2548872156 800507464 1865466907 1273317878 3754712872 1757188269 " + "3229950355 3731640200 2283390608 2204990292 411873449 447423849 1852437802 " + "472825525 3044219944 2913114194 1859709265 4053786194 574820536 2104496732 " + "865469814 2438352724 4208743605 4215067542 1364015250 4139974345 " + "3838747005 1818502786 2914274940 1402365828 1751123528 2302578077 " + "2463168652 1968705496 1730700144 3023943273 1139096844 2658667767 " + "2063547264 705791165 1444775274 2415454225 1575664730 921044163 648101324 " + "1212387162 4191962054 1787702169 1888718041 1518218010 3398792842 " + "4079359729 149721439 750400353 2661036076 3802767886 520152586 951852508 " + "2939585975 1375969109 385733137 3523607459 1902438415 4250996086 " + "2712727066 484493674 3932107461 1428488210 1764242548 3424801055 " + "4004904451 2226862072 2393366939 3609584727 3614444319 317349896 " + "3826527525 204023804 981902443 3356042039 3051207045 1869902661 561831895 " + "3706675415 1527687593 1227610446 2596341042 3191717368 3269246891 " + "557877074 4062070629 3052520266 3772487029 400039836 3195205275 4085394797 " + "1655557239 1345770144 2864727192 449281238 73189507 528365765 2727400656 " + "247880434 2408277395 777039183 2210179398 1088433648 2124356402 1555630141 " + "604790219 195012151 3312518356 923728373 3999251660 3313059535 3478133921 " + "3395026960 383464614 3425869222 2446885186 4032184426 157195416 3158909476 " + "1663750443 2046427584 1658453076 1784483001 3146546889 1238739785 " + "2297306523 3472330897 2953326031 2421672215 1221694592 1588568605 " + "2546987845 3375168573 2137961649 3056565164 330165219 235900365 1000384800 " + "2697255904 579122283 3050664825 73426122 1232986102 2940571064 3076486824 " + "1708182873 2796363264 292154131 4280019913 1102652157 1185393592 " + "1494991690 4270076389 2384840717 425785147 2385321880 317514772 3926962743 " + "392176856 3465421709 1878853468 122662664 2958252160 1858961315 2244939588 " + "2361884409 2860936803 683833250 3291277128 1686857206 1112632275 " + "1200680507 3342928196 2677058150 939442136 3407104669 2906783932 " + "3668048733 2030009470 1910839172 1234925283 3575831445 123595418 " + "2362440495 3048484911 1796872496"; + std::mt19937 e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "0 1 6364136223846793007 13885033948157127961 " + "15324573939901584278 12737837167382305846 15195339788985155882 " + "6554113247712070460 17235932740818599105 13007415075556305955 " + "6585479514541334743 8274505865835507625 1718218088692873364 " + "10390651247454232081 12911994993614796389 3986900029987203370 " + "6673827651897561714 4426752746717694792 7419158062930293690 " + "5800047417539173618 15710773105226458059 16164512590413496893 " + "3438015953120274172 3483801391287623267 293704481016263807 " + "11580856846363212652 3489109114147636336 3391036861618673611 " + "8265793309278544843 7557898467821912223 11008748280761875940 " + "15929443707841919885 8545695347411085846 10810459396490399532 " + "12233244910455127352 15556950738631379285 16711543556686614082 " + "12362193084052127890 16520645558585805174 5163125267185202360 " + "405552980610370477 17567412011316060306 18195950784827697319 " + "7893142112162906367 11294475722810961618 7284845498332539581 " + "8406882439401998138 4375387785957411470 9627875716250684710 " + "8860968026642934661 9743109216691708518 152611520104818631 " + "5897430410700879663 5351672954305365323 16325991383734641720 " + "9695181037355459478 15420132328343498044 17772146581546890572 " + "12095930435311226909 3066005052193896110 11579395203346116306 " + "9168946227698330317 18318927644793076250 16096433325093805476 " + "14945900876820434843 16826760579960858105 17664119339058295604 " + "17844797344364136942 1071414400549507565 16688779616725465582 " + "3684635020921274863 12774052823168116810 17270284502989966576 " + "1081012692742984704 4377021575203177546 18341292555997099853 " + "13297939683513494274 15065725504474304333 10796297883750572804 " + "15233335271871291997 8767977593699151062 3360856014170688284 " + "7828232912764786750 15167717223619970150 9622174963375022357 " + "18262792478991268448 1196631425707106493 5368342740538672272 " + "10381091599850241237 12108437846306626340 6150860188928778248 " + "3342980288459577584 12715439159457051276 17996971042887275859 " + "9749679821487730542 17763727344608586331 16024467606290078168 " + "7763401887585513696 4448278918811662063 16947956613780322662 " + "15144807360840708645 3878082612940188435 10709780449699561405 " + "1649555943517500922 3206645931693769562 12562913950237146427 " + "237213339742767727 12987800257476421358 1653669854585203688 " + "3485900643226898485 13961759114404652223 5243794832751327611 " + "10337687908642742498 16946139522050041809 16716562961992396380 " + "4275124606042261542 4055100795824867618 6424268654905981295 " + "3424516503413156556 2670380025813203539 10750762735193959951 " + "8790031149370411970 4021216986392972993 12076090355041998696 " + "14407920322903159838 10653597737935867030 15483225617438352002 " + "2497775263858626604 12295882369431088188 14256043521530136935 " + "2687322778627883798 3419797801078863201 8786888481486602641 " + "445698423634900693 9597067954623467255 7101345576557603992 " + "1498579197046783597 10403325187679734962 2464586980321053562 " + "2022012026329844477 10802281218030350853 6628929099856200904 " + "6828177972863192803 8589868113309334601 5245595233272009016 " + "5335692004673212054 4515133017699498525 15966447436053813932 " + "15199779177078162007 4190689609934804313 13003438276435994683 " + "8406046831313066396 10564320513686955057 12668913223662201488 " + "13130110932487580228 1030848205404711145 17684061609212954769 " + "12942207438298787911 10731611242140874687 5165052527778107352 " + "16323046249518133445 17119162873327029615 5754858052433703070 " + "3864761150247579030 9945988334920003074 11409854727071782565 " + "5000838138362434817 15526574143469400487 18094554078711846524 " + "5576294272011007484 3478525338408894755 11392694223389544658 " + "4692963068671452476 4459301637730340710 9699395817392066460 " + "14644636990626292085 18065377773424192622 5217202490849387226 " + "16175595974171756081 2109372019589047677 1624752883142646445 " + "13462209973053735966 12082930933973802402 1568864426788967895 " + "17047994306870001795 10556833209957537593 955604103878351641 " + "9062985603395234592 9757612676622840969 1767246562613391916 " + "9752598821733361274 7499745701633625047 7824811626141302622 " + "15819064077972391284 5660565551854829485 17645390577243129343 " + "7343780801046581776 2233358068547689666 8716657172695403744 " + "9129027798969787220 334709674395230649 2063182499026924878 " + "13089071159640936832 1765917316143960741 17552378408917656269 " + "3917018959478722819 15626740210483166037 1645962609209923821 " + "12277169606472643961 14545894350924442736 11485249378718653961 " + "9205208816702766530 10967561305613932827 3105992977398681914 " + "2125140299311648264 11619505070220308543 5030167448920096401 " + "4248170446421798953 16184577688118775567 9240607582885304823 " + "11838996733938359277 415426114101983968 14340734742548675134 " + "4124085748228276376 17686494750190224280 9472996569628985376 " + "1207013222233148636 3031046462562068367 45068538181330439 " + "8678647417835301152 10693327126492781235 3058899219097846020 " + "18377730418355022492 10269941972656742364 15986476992758938864 " + "14575856764093007010 14749682846448398393 1042926396621439263 " + "12184905641567868001 3518848236485931862 6718580865438347534 " + "6319395993260741012 2855168874111910691 2482146419106261786 " + "17290238774162848390 8071397865265268054 15873003794708011585 " + "14422764926380465297 14140979091525022882 3573480287238168646 " + "1525896111244666696 7537826952717918371 10482908122538761078 " + "17003233041653857 9473838740924911883 8438240966750123668 " + "10697754962581554225 15048771265786776312 9067877678399943713 " + "3399555692325948067 6150260207049997483 7165140289246675175 " + "14816202987105583988 4753550992948864498 10549400354582510015 " + "13212062554023586370 1585477630313819722 476999696494664205 " + "3208739183359199317 16011681780347380478 8149150693959772807 " + "803412833228911773 2360961455092949929 1517204230639934662 " + "13863717544358808032 16792122738584967930 12742474971940259289 " + "1859755681395355028 1540431035241590810 3883807554140904361 " + "16189061625447625933 12376367376041900879 8006563585771266211 " + "2682617767291542421 8593924529704142157 9070391845133329273 " + "3557484410564396342 9301398051805853085 12632514768298643219 " + "227653509634201118 7247795074312488552 4939136716843120792 " + "6533591052147596041 1308401457054431629 17488144120120152559 " + "14075631579093810083 4015705597302725704 6833920126528811473 " + "5095302940809114298 8312250184258072842 15770605014574863643 " + "14091690436120485477 15763282477731738396 16394237160547425954 " + "5066318118328746621 13140493775100916989 6371148952471982853 " + "15150289760867914983 4931341382074091848 12635920082410445322 " + "8498109357807439006 14836776625250834986"; + std::mt19937_64 e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..45bc493afb58 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp @@ -0,0 +1,309 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// template<class Sseq> explicit mersenne_twister_engine(Sseq& q); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "358595400 4166558815 2016177162 3414480257 " + "4027494649 3722317195 1190532340 3212207148 " + "3537847251 389019999 1098708832 3277907415 " + "1946784350 3608286140 2091419822 2227407035 " + "2229110723 1825348377 1276269279 314337202 " + "3182935337 1313150029 3118776508 3707918501 " + "1900972958 4054820954 3973178248 906260237 " + "1403942218 3139931556 2807126524 3940936448 " + "1316345796 631296613 2268418920 2914000794 " + "3760588399 3226216036 880155129 4183611084 " + "211541083 3755352858 1331383234 3036493096 " + "937478630 2092170412 777784402 93392729 " + "3644029210 1681392086 2427001226 3143870332 " + "3703581502 2017505388 1706274541 1049329728 " + "2452031492 3437261233 2581204087 1700889875 " + "1652573881 2127047692 3778506964 1960741508 " + "2739602360 3395905609 2123355622 3041272975 " + "784200748 3558951522 1002787860 4063320888 " + "1587315560 4042698976 659183308 3082256417 " + "2808969567 2361418535 3468698782 750700970 " + "2991209851 3581521382 962022878 2518967363 " + "1476525873 3865977235 2128790058 2380326689 " + "1396773405 312559410 1370621899 1154499924 " + "2963101919 2182689761 2071851902 1661288848 " + "2411351341 1362764020 1289894483 1951662807 " + "701821506 552267185 2356648449 3949188503 " + "1748307081 87795201 3718396254 4112205936 " + "2819888864 73923733 2800033151 839258139 " + "3801779069 3105962436 2111266436 1772784466 " + "3692264298 4148810953 3147390749 3537518553 " + "1695044978 1430225842 1252346204 3465285434 " + "3970017763 2920658411 2805151132 290569815 " + "3802301355 1493420394 1943029276 1667143611 " + "1049665988 1710824905 220168517 3997946231 " + "1014582791 4244598752 1147604069 2533886627 " + "598679964 761521020 431779255 3745982038 " + "768658283 3598262505 1765664789 279538641 " + "715144305 2371628432 2655860083 1759010423 " + "3568452003 1910107098 2801429529 3924547532 " + "3862672436 3933725740 1764550618 130893617 " + "1460692387 4135312761 2075529299 2880227367 " + "944557368 4166665482 2627749235 3732013815 " + "1595900818 1553312393 3529311831 3531462424 " + "2431328342 4075369692 1609967709 3704537555 " + "2067297464 397140475 920618678 2840795964 " + "4202512837 1286017648 7035910 1057207826 " + "2325188262 191593698 3697383848 3029712831 " + "2073681914 163454681 1329637200 290077398 " + "287239431 4205081522 1233889024 167173087 " + "3267660257 3406068803 2382354609 1680046927 " + "125183503 3559536309 3208900974 2912148541 " + "2882879316 1937001086 2919729069 892928802 " + "4141691387 2507406586 855548593 3418647837 " + "4035646154 2410275591 248715645 3180757482 " + "1880770722 362912336 2964920095 2319904154 " + "1493655850 4240733030 1834485846 1696040454 " + "3329457927 1865824694 847759208 1587231623 " + "3757294772 1161601118 3630323833 3007722125 " + "3726418007 2124238171 1205345 172659797 " + "3040354211 885213338 1857049013 447922412 " + "719906299 1370059380 1922204800 3960090489 " + "1658822644 1529626863 1565927273 3537718771 " + "2733237258 2180221377 921910745 2144937687 " + "1727603895 1315635304 4023867791 2401834107 " + "808854185 2408824497 343935326 185237544 " + "746732759 2641236122 4283215329 743609415 " + "1134726665 3892851319 1302851263 3473445597 " + "1326817414 2702766508 1943179285 4025685468 " + "932896770 199392138 2787362875 3450501893 " + "3351567147 2461286528 2227605848 2993751114 " + "3988215720 1320573368 2866560199 4153194990 " + "3007120042 3260751955 3171763740 2111121243 " + "3962825228 102681859 3368179132 802089147 " + "4029273561 424939445 4178414761 2592125109 " + "1960801088 2967746406 310701990 2364200202 " + "1320507009 3474372480 784693947 2952246664 " + "1891935330 2048385105 3530082191 3238151038 " + "3293189141 1316053288 2087004409 740799958 " + "1187748554 3607767334 1190185990 1408429481 " + "657134359 221834425 3907725865 1068016389 " + "1402423875 2598612116 2046886300 2345022518 " + "1196081924 357783981 4013683598 463491626 " + "3269206482 3332444286 886491955 2257342866 " + "475911113 833576299 2893727564 2866985145 " + "1413365115 2995166393 1486060436 161205225 " + "3181728373 3056027137 2040371876 2182305146 " + "3028448628 2214316977 1266227021 876938740 " + "276477469 752158077 2182179045 1381698878 " + "3424557652 666674427 968327842 2534296575 " + "265105940 961112540 2641188117 2319139814 " + "1750453329 3450138343 678025317 1477566458 " + "3773796420 2933993832 3326042905 4084805260 " + "444182455 255333481 785163068 2321290820 " + "2893603234 3005520266 541104079 1383277090 " + "2770755666 3764627833 583371929 2864949033 " + "1487681116 1811788361 240329486 3094213377 " + "958509875 2564379085 1636995945 2070894127 " + "2139004232 1747850055 3841512327 3325011872 " + "1161622604 639182193 3533652535 4022667522 " + "761048999 3337743670 254221568 2784956233 " + "2990252814 4207922787 275707208 261819597 " + "2071467265 4034945770 1999813410 3038921100 " + "2200194573 1328217451 2440612380 3862293692 " + "2733976812 2750523058 2920082515 3809044908 " + "4285231753 3131963297 3481602724 1396460739 " + "2011767965 2481047764 2958452120 3044188618 " + "2217236658 3448605566 757716104 1818279145 " + "2641228144 1312649639 1194087684 3845229729 " + "1747658356 874418803 1956637337 268670179 " + "2083040240 2577671381 3375334655 2587828868 " + "1383012799 3583445685 2594576715 3282337104 " + "4257972751 3440488071 3129180313 1830891395 " + "1594931092 2680778339 3984026324 1102770400 " + "2315820258 1263467048 1133254110 2400676748 " + "2251795328 1036154092 3313541051 2277356560 " + "1477696003 1417117088 3968537402 1404882202 " + "2011058180 4114080985 1727459502 4100235708 " + "2334509310 2829432554 377936301 1519324520 " + "3252826644 1193335837 1929125820 2165344238 " + "4160556243 223340988 670907625 1485396519 " + "936389509 3813712964 2706450987 3132506320 " + "875886515 557088991 2854916639 2955496008 " + "2881696287 265169077 3239923698 3649366121 " + "4072165960 1233904959 225406526 1767368993 " + "1894882500 2296582180 339255168 83200939 " + "2958376148 4100205346 1991250823 3806183082 " + "2691709980 2642354997 3024056146 1681065839 " + "3438299684 1638853652 362567001 2307868899 " + "988801086 1342833399 2303298376 1500039911 " + "765489391 4080464497 4155444368 980472018 " + "2026981853 3460406995 391970367 667377014 " + "4177754853 2657468948 3560690175 3030464357 " + "2948380657 1208800977 2316451404 4001932203 " + "1977856863 4265848271 3116200050 3037586215 " + "1335232764 930230766 1026089249 2482219415 " + "2613853154 1854543497 2909555107 3862874043 " + "2609355500 907364682 383900687 358164223 " + "232347546 2536276737 3118482806 1254103998 " + "2357334077 1204777304 1996643329 4046232717 " + "2570520290 3173323380 1201411457 2361883023 " + "806087062 2984143714 2355127569 864220085 " + "1787696713 1182652984 4200065581 100722519 " + "2380458669 2429592313 2618338302 1236529564 " + "1747130196 3711661325 1114068102 510380433 " + "93703089 2277774664 3220741441 1577998569 " + "2816701900 4206763045 2495239107 4080390459 " + "1307072677 20360728 1468385549 96049834 " + "3630657447 2809517346 3396111678 3043831060 " + "673178359 4256729562 1755211210 1969834535 " + "498315110 3717726302 1544859987 2239930949 " + "1595372585 294525219 3961637067 3591840665 " + "3324896933 2300077772 721255886 4197934760 " + "1468866696 2184812884 628246683 3385113037 " + "3041166140 3948531843 1176600829 228286131 " + "2447397608 712235937 3332826819 2676980703 " + "4019468871 1952389952 1202638254 3625447051"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::mt19937 e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "17895233847644109640 14665081038668852234 15987230621890949369 " + "13796324649827964148 1670828176732799955 14078505147839608672 " + "15497470967856861790 9566640372296747182 7839811585250789315 " + "1350068003782415071 5639936432479386921 15925388701147119804 " + "17415323390466493342 3892358083553387400 13485903346102334794 " + "16926193162581531132 2711398308226914244 12515538113016451944 " + "13856492368211347055 17968472785843263993 16129117710261673051 " + "13041638543181171650 8985803498136324582 401118717516975186 " + "7221524024767248666 13502820261231663498 8665119664667372350 " + "4506836866186850029 14762924585995667460 7305266389803732087 " + "9135600275824854713 8421320656548229332 14585303533697565624 " + "13062167967956981222 15285580395823625260 17451830328116466708 " + "17363259891080004456 13238190509560321740 10142215382802200927 " + "3224236118694175902 15382517208605932923 10818882444738383326 " + "16604245792882032433 10223425285179753002 1342432445403828765 " + "4958539418185107403 9374581143772158175 7135181273441366910 " + "5853026900476841261 8382327930174454355 2371969498930803266 " + "16961635468480846337 377077518789053577 17661790013255465310 " + "317500018453124832 3604586262706855295 13340007089026272125 " + "7614051306438090372 17819007364113857386 15193526497275633437 " + "6142773218979108210 14883287611587512668 12544132362002344419 " + "1247987855434921372 6414191755211735979 7160327288923375132 " + "7347937017206972868 17171048313531629893 18230412825496997383 " + "10882960195884354661 3270707876715241884 16088870345045208503 " + "15454419782166694763 1200609322828949525 10186066554418904177 " + "7554892242763986291 8203847521335919011 16855803304338943001 " + "16895223408596071476 562183806034700250 17761033068687156643 " + "12370482348384718931 17895691979506634040 16028877286272943475 " + "6671425930002400146 15167515621662197335 17503579548680921174 " + "15910867647138768989 1705705354110203064 12201125760909412022 " + "5523403744441352645 4540673037752294406 822888669354888870 " + "13012517529113958824 702032511346794490 1245872939048413008 " + "18060687614291143943 718002942670251776 14628954120078526945 " + "7215746609592654001 15288092036204733967 12507582747898016110 " + "8319356319569362772 3835100005166188461 10769229288786702843 " + "14682980657311687345 10352054841727718090 13661249361946024317 " + "1558696616315734178 9963912474249467679 18213809676410642730 " + "7284438284457478230 8013656044128665351 6817107912809760616 " + "4989038816564331700 12918068165960947833 9123533477086273623 " + "741568181450204257 3801962339733348259 1923812112542486965 " + "5884360231397942779 17008459141377852544 6569697353326895092 " + "15194386425456240489 9363979514988323850 9212437218544795097 " + "5650610605870621879 10315798944006232463 10345822437227504297 " + "795589193815296350 11344022765750598871 3193778122705907169 " + "16719669104430190089 14918335244853046975 11608293761910939782 " + "17290187430985633813 856382712722415618 14819792788008454203 " + "10571145147196955435 12858063129221173592 5671819431516788648 " + "17837836658827607239 14004823010100183722 9067196699747632668 " + "441015230260308492 3444946658209715644 1825101023084664281 " + "11133092574473850025 12746373758552339264 10154162549097295782 " + "14922316177042921089 12679802872389794491 8797747037480461410 " + "13907752811248535439 5652405835046458389 3181711594575177977 " + "15495242712294857418 6049158560807439366 952771601159099159 " + "4587095466254740009 11160954054611782211 10071795025240457628 " + "1536670498623767300 1990681379653546894 14312739227381277138 " + "9695213786215402291 3580182943401628617 12313607438786545484 " + "12864141705426648443 692371170805382036 13125536612285239925 " + "9372929234002877092 9510419002221032820 3766423210161674061 " + "3230494342413727261 5934351496112072933 2863344864469097044 " + "10884720908958139042 4127946927340597780 9960629658622711061 " + "14818231351611083857 6346099615454582885 12601407558879514692 " + "17544105005554819865 1096648950913019831 9969868157190185788 " + "12908611252828823970 5941129863397152719 16168953427117105234 " + "12304862402025196697 7781571759256122972 13289545261301048078 " + "11013924305579914035 8894422550580466537 7506958826675805512 " + "14280817252893250439 2745266616282182732 17277225453205013047 " + "14335499905842065319 11961295941780577536 18072890757248426766 " + "1124506606842606920 17329960125355005185 13052066741624159010 " + "5704650516221677069 16588425097127709212 11813406583737887980 " + "16359723311775411283 13451679937172566665 5997753207634594468 " + "10656019008205694109 13074690560123889048 14811648124990806194 " + "7809449463531558024 5637787273252434288 16515135932856030468 " + "3755600163640125044 1153929634172103321 11071014283313196016 " + "11114640359080035583 15390782025450330559 14097530518721927499 " + "14776783751481098767 7863618667181998233 11513855295425132436 " + "4736362806980864724 5426549653049482466 10310828122060887518 " + "4450247941008370560 9781171949844602811 6086471549040450051 " + "6033923116291003194 17669843285681524740 17610378273478865070 " + "12152320288002263294 6525449125788834221 5125338396312613396 " + "9300082688721166268 959242243476884691 6379729471368150249 " + "16379772457647614853 13454012201619761707 2392678998182524851 " + "12693758700673471007 1138892516507202079 15673908144065302514 " + "5299581449349386824 7590792025124859454 9863745357571267780 " + "357345312340746112 17610247870912740564 16347431861769737095 " + "11348828299228888092 7220122803951857490 7038822841708464676 " + "9912221445023094105 5767425533670320190 6442622362743049032 " + "17525461567869579503 4211095256108567696 14862334876401617373 " + "2866362449624104511 11413742225973279461 13015745308569358847 " + "5191760666536228849 17188167935010684492 18321678815621002079 " + "13046333455321624690 3995310719038261500 10661051209947341089 " + "7965203671238327266 16590917686161852835 3897101637344795372 " + "1538303624766151695 10893225639252940698 5386335660311332214 " + "5174479122000384061 17378437193516866561 13629320139302700770 " + "10144210341964027265 12816799659000064406 3711797003976467729 " + "5079455890584507977 432599929275804205 10435019529328454317 " + "5310854040535477246 15941464006450157396 2192067269367387270 " + "9782967689631091633 6777452250210540865 18067909703113078220 " + "17525143578810667971 87448662189824165 412530897284614413 " + "12066785122245373863 13073154860645125438 18282514257379582711 " + "8460374908111578570 15967512883067334502 9620430172798103891 " + "1264976185047610409 15426838192579528907 9878758812321441445 " + "18029992505662864846 9383699886128308360 14538949787806484635 " + "16958815135940772668 980481467951972605 3059030058898313960 " + "11497544574740915907 8385450996898478663 15571176518627282350"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::mt19937_64 e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/default.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/default.pass.cpp new file mode 100644 index 000000000000..d92ffd807da0 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/default.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// explicit mersenne_twister_engine(); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + std::mt19937 e1; + std::mt19937 e2(std::mt19937::default_seed); + assert(e1 == e2); + assert(e1() == 3499211612u); +} + +void +test2() +{ + std::mt19937_64 e1; + std::mt19937_64 e2(std::mt19937_64::default_seed); + assert(e1 == e2); + assert(e1() == 14514284786278117030ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/discard.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/discard.pass.cpp new file mode 100644 index 000000000000..d20d661d5891 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/discard.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// void discard(unsigned long long z); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + std::mt19937 e1; + std::mt19937 e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +void +test2() +{ + std::mt19937_64 e1; + std::mt19937_64 e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/eval.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/eval.pass.cpp new file mode 100644 index 000000000000..0b17a8577067 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/eval.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// result_type operator()(); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + std::mt19937 e; + assert(e() == 3499211612u); + assert(e() == 581869302u); + assert(e() == 3890346734u); +} + +void +test2() +{ + std::mt19937_64 e; + assert(e() == 14514284786278117030ull); + assert(e() == 4620546740167642908ull); + assert(e() == 13109570281517897720ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/io.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/io.pass.cpp new file mode 100644 index 000000000000..28e00ec1eb88 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/io.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// template <class charT, class traits, +// class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); +// +// template <class charT, class traits, +// class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// basic_ostream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + typedef std::mt19937 E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +void +test2() +{ + typedef std::mt19937_64 E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/result_type.pass.cpp new file mode 100644 index 000000000000..26f3e1563295 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/result_type.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine +// { +// public: +// // types +// typedef UIntType result_type; + +#include <random> +#include <type_traits> + +void +test1() +{ + static_assert((std::is_same< + std::mt19937::result_type, + std::uint_fast32_t>::value), ""); +} + +void +test2() +{ + static_assert((std::is_same< + std::mt19937_64::result_type, + std::uint_fast64_t>::value), ""); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_result_type.pass.cpp new file mode 100644 index 000000000000..6f93e5beb9b5 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_result_type.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::mt19937 E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +void +test2() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::mt19937_64 E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp new file mode 100644 index 000000000000..33292a041af4 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine; + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +void +test1() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::mt19937 e1; + std::mt19937 e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +void +test2() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::mt19937_64 e1; + std::mt19937_64 e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp new file mode 100644 index 000000000000..331d3c51119f --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template <class UIntType, size_t w, size_t n, size_t m, size_t r, +// UIntType a, size_t u, UIntType d, size_t s, +// UIntType b, size_t t, UIntType c, size_t l, UIntType f> +// class mersenne_twister_engine +// { +// public: +// // types +// typedef UIntType result_type; +// +// // engine characteristics +// static constexpr size_t word_size = w; +// static constexpr size_t state_size = n; +// static constexpr size_t shift_size = m; +// static constexpr size_t mask_bits = r; +// static constexpr result_type xor_mask = a; +// static constexpr size_t tempering_u = u; +// static constexpr result_type tempering_d = d; +// static constexpr size_t tempering_s = s; +// static constexpr result_type tempering_b = b; +// static constexpr size_t tempering_t = t; +// static constexpr result_type tempering_c = c; +// static constexpr size_t tempering_l = l; +// static constexpr result_type initialization_multiplier = f; +// static constexpr result_type min () { return 0; } +// static constexpr result_type max() { return 2^w - 1; } +// static constexpr result_type default_seed = 5489u; + +#include <random> +#include <type_traits> +#include <cassert> + +template <class _Tp> +void where(const _Tp &) {} + +void +test1() +{ + typedef std::mt19937 E; + static_assert((E::word_size == 32), ""); + static_assert((E::state_size == 624), ""); + static_assert((E::shift_size == 397), ""); + static_assert((E::mask_bits == 31), ""); + static_assert((E::xor_mask == 0x9908b0df), ""); + static_assert((E::tempering_u == 11), ""); + static_assert((E::tempering_d == 0xffffffff), ""); + static_assert((E::tempering_s == 7), ""); + static_assert((E::tempering_b == 0x9d2c5680), ""); + static_assert((E::tempering_t == 15), ""); + static_assert((E::tempering_c == 0xefc60000), ""); + static_assert((E::tempering_l == 18), ""); + static_assert((E::initialization_multiplier == 1812433253), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/); + static_assert((E::default_seed == 5489u), ""); + where(E::word_size); + where(E::state_size); + where(E::shift_size); + where(E::mask_bits); + where(E::xor_mask); + where(E::tempering_u); + where(E::tempering_d); + where(E::tempering_s); + where(E::tempering_b); + where(E::tempering_t); + where(E::tempering_c); + where(E::tempering_l); + where(E::initialization_multiplier); + where(E::default_seed); +} + +void +test2() +{ + typedef std::mt19937_64 E; + static_assert((E::word_size == 64), ""); + static_assert((E::state_size == 312), ""); + static_assert((E::shift_size == 156), ""); + static_assert((E::mask_bits == 31), ""); + static_assert((E::xor_mask == 0xb5026f5aa96619e9ull), ""); + static_assert((E::tempering_u == 29), ""); + static_assert((E::tempering_d == 0x5555555555555555ull), ""); + static_assert((E::tempering_s == 17), ""); + static_assert((E::tempering_b == 0x71d67fffeda60000ull), ""); + static_assert((E::tempering_t == 37), ""); + static_assert((E::tempering_c == 0xfff7eee000000000ull), ""); + static_assert((E::tempering_l == 43), ""); + static_assert((E::initialization_multiplier == 6364136223846793005ull), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/); + static_assert((E::default_seed == 5489u), ""); + where(E::word_size); + where(E::state_size); + where(E::shift_size); + where(E::mask_bits); + where(E::xor_mask); + where(E::tempering_u); + where(E::tempering_d); + where(E::tempering_s); + where(E::tempering_b); + where(E::tempering_t); + where(E::tempering_c); + where(E::tempering_l); + where(E::initialization_multiplier); + where(E::default_seed); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/assign.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/assign.pass.cpp new file mode 100644 index 000000000000..305d43ad4a22 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/assign.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// subtract_with_carry_engine& operator=(const subtract_with_carry_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24_base E; + E e1(2); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48_base E; + E e1(3); + e1(); + E e2(5); + e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/copy.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/copy.pass.cpp new file mode 100644 index 000000000000..27f88165bcf5 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/copy.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// subtract_with_carry_engine(const subtract_with_carry_engine&); + +#include <random> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24_base E; + E e1; + e1(); + E e2 = e1; + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48_base E; + E e1; + e1(); + E e2(e1); + assert(e1 == e2); + assert(e1() == e2()); + E::result_type k = e1(); + assert(e1 != e2); + assert(e2() == k); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_result_type.pass.cpp new file mode 100644 index 000000000000..429298dfcd88 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_result_type.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// explicit subtract_with_carry_engine(result_type s = default_seed); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "15136306 8587749 2346244 16479026 15515802 9510553 " + "16090340 14501685 13839944 10789678 11581259 9590790 5840316 5953700 " + "13398366 8134459 16629731 6851902 15583892 1317475 4231148 9092691 " + "5707268 2355175 0"; + std::ranlux24_base e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "10880375256626 126660097854724 33643165434010 " + "78293780235492 179418984296008 96783156950859 238199764491708 " + "34339434557790 155299155394531 29014415493780 209265474179052 " + "263777435457028 0"; + std::ranlux48_base e1(0); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_sseq.pass.cpp new file mode 100644 index 000000000000..893f6dc34a4b --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_sseq.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 " + "3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 " + "14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 " + "889045 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::ranlux24_base e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +void +test2() +{ + const char* a = "241408498702289 172342669275054 191026374555184 " + "61020585639411 231929771458953 142769679250755 198672786411514 " + "183712717244841 227473912549724 62843577252444 68782400568421 " + "159248704678140 0"; + unsigned as[] = {3, 5, 7}; + std::seed_seq sseq(as, as+3); + std::ranlux48_base e1(sseq); + std::ostringstream os; + os << e1; + assert(os.str() == a); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/default.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/default.pass.cpp new file mode 100644 index 000000000000..56e8759d1e60 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/default.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// explicit subtract_with_carry_engine(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24_base e1; + std::ranlux24_base e2(std::ranlux24_base::default_seed); + assert(e1 == e2); + assert(e1() == 15039276); +} + +void +test2() +{ + std::ranlux48_base e1; + std::ranlux48_base e2(std::ranlux48_base::default_seed); + assert(e1 == e2); + assert(e1() == 23459059301164ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/discard.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/discard.pass.cpp new file mode 100644 index 000000000000..4ba93819ee43 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/discard.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// void discard(unsigned long long z); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24_base e1; + std::ranlux24_base e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +void +test2() +{ + std::ranlux48_base e1; + std::ranlux48_base e2 = e1; + assert(e1 == e2); + e1.discard(3); + assert(e1 != e2); + e2(); + e2(); + e2(); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/eval.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/eval.pass.cpp new file mode 100644 index 000000000000..44829944be73 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/eval.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// result_type operator()(); + +#include <random> +#include <cassert> + +void +test1() +{ + std::ranlux24_base e; + assert(e() == 15039276u); + assert(e() == 16323925u); + assert(e() == 14283486u); +} + +void +test2() +{ + std::ranlux48_base e; + assert(e() == 23459059301164ull); + assert(e() == 28639057539807ull); + assert(e() == 276846226770426ull); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/io.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/io.pass.cpp new file mode 100644 index 000000000000..834f5f69c777 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/io.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// template <class charT, class traits, +// class UIntType, size_t w, size_t s, size_t r> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, +// const subtract_with_carry_engine<UIntType, w, s, r>& x); +// +// template <class charT, class traits, +// class UIntType, size_t w, size_t s, size_t r> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, +// subtract_with_carry_engine<UIntType, w, s, r>& x); + +#include <random> +#include <sstream> +#include <cassert> + +void +test1() +{ + typedef std::ranlux24_base E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +void +test2() +{ + typedef std::ranlux48_base E; + E e1; + e1.discard(100); + std::ostringstream os; + os << e1; + std::istringstream is(os.str()); + E e2; + is >> e2; + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/result_type.pass.cpp new file mode 100644 index 000000000000..6af195b49923 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/result_type.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine +// { +// public: +// // types +// typedef UIntType result_type; + +#include <random> +#include <type_traits> + +void +test1() +{ + static_assert((std::is_same< + std::ranlux24_base::result_type, + std::uint_fast32_t>::value), ""); +} + +void +test2() +{ + static_assert((std::is_same< + std::ranlux48_base::result_type, + std::uint_fast64_t>::value), ""); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_result_type.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_result_type.pass.cpp new file mode 100644 index 000000000000..fa6e741da920 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_result_type.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// void seed(result_type s = default_seed); + +#include <random> +#include <cassert> + +void +test1() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::ranlux24_base E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +void +test2() +{ + for (int s = 0; s < 20; ++s) + { + typedef std::ranlux48_base E; + E e1(s); + E e2; + e2.seed(s); + assert(e1 == e2); + } +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_sseq.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_sseq.pass.cpp new file mode 100644 index 000000000000..347077278e61 --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/seed_sseq.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine; + +// template<class Sseq> void seed(Sseq& q); + +#include <random> +#include <cassert> + +void +test1() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::ranlux24_base e1; + std::ranlux24_base e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +void +test2() +{ + unsigned a[] = {3, 5, 7}; + std::seed_seq sseq(a, a+3); + std::ranlux48_base e1; + std::ranlux48_base e2(sseq); + assert(e1 != e2); + e1.seed(sseq); + assert(e1 == e2); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp b/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp new file mode 100644 index 000000000000..75716a43deae --- /dev/null +++ b/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class UIntType, size_t w, size_t s, size_t r> +// class subtract_with_carry_engine +// { +// public: +// // types +// typedef UIntType result_type; +// +// // engine characteristics +// static constexpr size_t word_size = w; +// static constexpr size_t short_lag = s; +// static constexpr size_t long_lag = r; +// static constexpr result_type min() { return 0; } +// static constexpr result_type max() { return m-1; } +// static constexpr result_type default_seed = 19780503u; + +#include <random> +#include <type_traits> +#include <cassert> + +template <class _Tp> +void where(const _Tp &) {} + +void +test1() +{ + typedef std::ranlux24_base E; + static_assert((E::word_size == 24), ""); + static_assert((E::short_lag == 10), ""); + static_assert((E::long_lag == 24), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFF)/*, ""*/); + static_assert((E::default_seed == 19780503u), ""); + where(E::word_size); + where(E::short_lag); + where(E::long_lag); + where(E::default_seed); +} + +void +test2() +{ + typedef std::ranlux48_base E; + static_assert((E::word_size == 48), ""); + static_assert((E::short_lag == 5), ""); + static_assert((E::long_lag == 12), ""); + /*static_*/assert((E::min() == 0)/*, ""*/); + /*static_*/assert((E::max() == 0xFFFFFFFFFFFFull)/*, ""*/); + static_assert((E::default_seed == 19780503u), ""); + where(E::word_size); + where(E::short_lag); + where(E::long_lag); + where(E::default_seed); +} + +int main() +{ + test1(); + test2(); +} diff --git a/test/std/numerics/rand/rand.predef/default_random_engine.pass.cpp b/test/std/numerics/rand/rand.predef/default_random_engine.pass.cpp new file mode 100644 index 000000000000..426586007c1a --- /dev/null +++ b/test/std/numerics/rand/rand.predef/default_random_engine.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef minstd_rand0 default_random_engine; + +#include <random> +#include <cassert> + +int main() +{ + std::default_random_engine e; + e.discard(9999); + assert(e() == 399268537u); +} diff --git a/test/std/numerics/rand/rand.predef/knuth_b.pass.cpp b/test/std/numerics/rand/rand.predef/knuth_b.pass.cpp new file mode 100644 index 000000000000..69627d79e907 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/knuth_b.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; + +#include <random> +#include <cassert> + +int main() +{ + std::knuth_b e; + e.discard(9999); + assert(e() == 1112339016u); +} diff --git a/test/std/numerics/rand/rand.predef/minstd_rand.pass.cpp b/test/std/numerics/rand/rand.predef/minstd_rand.pass.cpp new file mode 100644 index 000000000000..891e5cce6d85 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/minstd_rand.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> +// minstd_rand; + +#include <random> +#include <cassert> + +int main() +{ + std::minstd_rand e; + e.discard(9999); + assert(e() == 399268537u); +} diff --git a/test/std/numerics/rand/rand.predef/minstd_rand0.pass.cpp b/test/std/numerics/rand/rand.predef/minstd_rand0.pass.cpp new file mode 100644 index 000000000000..63848cf95065 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/minstd_rand0.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> +// minstd_rand0; + +#include <random> +#include <cassert> + +int main() +{ + std::minstd_rand0 e; + e.discard(9999); + assert(e() == 1043618065u); +} diff --git a/test/std/numerics/rand/rand.predef/mt19937.pass.cpp b/test/std/numerics/rand/rand.predef/mt19937.pass.cpp new file mode 100644 index 000000000000..e3a79364a1f5 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/mt19937.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, +// 0x9908b0df, +// 11, 0xffffffff, +// 7, 0x9d2c5680, +// 15, 0xefc60000, +// 18, 1812433253> mt19937; + +#include <random> +#include <cassert> + +int main() +{ + std::mt19937 e; + e.discard(9999); + assert(e() == 4123659995u); +} diff --git a/test/std/numerics/rand/rand.predef/mt19937_64.pass.cpp b/test/std/numerics/rand/rand.predef/mt19937_64.pass.cpp new file mode 100644 index 000000000000..67896d2260f4 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/mt19937_64.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, +// 0xb5026f5aa96619e9, +// 29, 0x5555555555555555, +// 17, 0x71d67fffeda60000, +// 37, 0xfff7eee000000000, +// 43, 6364136223846793005> mt19937_64; + +#include <random> +#include <cassert> + +int main() +{ + std::mt19937_64 e; + e.discard(9999); + assert(e() == 9981545732273789042ull); +} diff --git a/test/std/numerics/rand/rand.predef/ranlux24.pass.cpp b/test/std/numerics/rand/rand.predef/ranlux24.pass.cpp new file mode 100644 index 000000000000..529586af9f42 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/ranlux24.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; + +#include <random> +#include <cassert> + +int main() +{ + std::ranlux24 e; + e.discard(9999); + assert(e() == 9901578u); +} diff --git a/test/std/numerics/rand/rand.predef/ranlux24_base.pass.cpp b/test/std/numerics/rand/rand.predef/ranlux24_base.pass.cpp new file mode 100644 index 000000000000..f7311469dcbf --- /dev/null +++ b/test/std/numerics/rand/rand.predef/ranlux24_base.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; + +#include <random> +#include <cassert> + +int main() +{ + std::ranlux24_base e; + e.discard(9999); + assert(e() == 7937952u); +} diff --git a/test/std/numerics/rand/rand.predef/ranlux48.pass.cpp b/test/std/numerics/rand/rand.predef/ranlux48.pass.cpp new file mode 100644 index 000000000000..f15dfd5493e2 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/ranlux48.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; + +#include <random> +#include <cassert> + +int main() +{ + std::ranlux48 e; + e.discard(9999); + assert(e() == 249142670248501ull); +} diff --git a/test/std/numerics/rand/rand.predef/ranlux48_base.pass.cpp b/test/std/numerics/rand/rand.predef/ranlux48_base.pass.cpp new file mode 100644 index 000000000000..4c3df3e1dce8 --- /dev/null +++ b/test/std/numerics/rand/rand.predef/ranlux48_base.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; + +#include <random> +#include <cassert> + +int main() +{ + std::ranlux48_base e; + e.discard(9999); + assert(e() == 61839128582725ull); +} diff --git a/test/std/numerics/rand/rand.req/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.adapt/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.adapt/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.adapt/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.dst/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.dst/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.dst/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.eng/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.eng/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.eng/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.genl/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.genl/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.genl/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.seedseq/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.seedseq/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.seedseq/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.req/rand.req.urng/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.req/rand.req.urng/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.req/rand.req.urng/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.synopsis/version.pass.cpp b/test/std/numerics/rand/rand.synopsis/version.pass.cpp new file mode 100644 index 000000000000..eae6c493e919 --- /dev/null +++ b/test/std/numerics/rand/rand.synopsis/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +#include <random> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.util/nothing_to_do.pass.cpp b/test/std/numerics/rand/rand.util/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/numerics/rand/rand.util/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp new file mode 100644 index 000000000000..7433e28e4935 --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// template<class RealType, size_t bits, class URNG> +// RealType generate_canonical(URNG& g); + +#include <random> +#include <cassert> + +int main() +{ + { + typedef std::minstd_rand0 E; + typedef float F; + E r; + F f = std::generate_canonical<F, 0>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef float F; + E r; + F f = std::generate_canonical<F, 1>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef float F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef float F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef float F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + + { + typedef std::minstd_rand0 E; + typedef double F; + E r; + F f = std::generate_canonical<F, 0>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef double F; + E r; + F f = std::generate_canonical<F, 1>(r); + assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1))); + } + { + typedef std::minstd_rand0 E; + typedef double F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r); + assert(f == + (16807 - E::min() + + (282475249 - E::min()) * (E::max() - E::min() + F(1))) / + ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))); + } + { + typedef std::minstd_rand0 E; + typedef double F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r); + assert(f == + (16807 - E::min() + + (282475249 - E::min()) * (E::max() - E::min() + F(1))) / + ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))); + } + { + typedef std::minstd_rand0 E; + typedef double F; + E r; + F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r); + assert(f == + (16807 - E::min() + + (282475249 - E::min()) * (E::max() - E::min() + F(1))) / + ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))); + } +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/assign.fail.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/assign.fail.cpp new file mode 100644 index 000000000000..6b5d75042d3b --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/assign.fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// seed_seq(); + +#include <random> + +int main() +{ + std::seed_seq s0; + std::seed_seq s; + s = s0; +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/copy.fail.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/copy.fail.cpp new file mode 100644 index 000000000000..cf260fcc01e8 --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/copy.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// seed_seq(); + +#include <random> + +int main() +{ + std::seed_seq s0; + std::seed_seq s(s0); +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/default.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/default.pass.cpp new file mode 100644 index 000000000000..bf4210aa9950 --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/default.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// seed_seq(); + +#include <random> +#include <cassert> + +int main() +{ + std::seed_seq s; + assert(s.size() == 0); +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/generate.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/generate.pass.cpp new file mode 100644 index 000000000000..9712f61d681c --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/generate.pass.cpp @@ -0,0 +1,805 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// template<class RandomAccessIterator> +// void generate(RandomAccessIterator begin, RandomAccessIterator end); + +#include <random> +#include <cassert> + +int main() +{ + { + // These numbers generated from a slightly altered version of dSFMT + // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html + unsigned a[] = + { + 509928861u, + 482551238u, + 141770655u, + 3445468037u, + 1614807826u, + 3110698871u, + 809182926u, + 2644632325u, + 3885131857u, + 1278630374u, + 3648975313u, + 1217833759u, + 1509686260u, + 2817190507u, + 134525747u, + 250267852u, + 2559105345u, + 2416641579u, + 426100435u, + 486929906u, + 241178241u, + 3531539379u, + 704692991u, + 3001633456u, + 3990516671u, + 2619782509u, + 588842726u, + 2871949673u, + 621390331u, + 2304055997u, + 3809702625u, + 2471383485u, + 1630735687u, + 2167939898u, + 2070992669u, + 2826890739u, + 1714346061u, + 1912761420u, + 539780511u, + 716119356u, + 1342493369u, + 1216009367u, + 2864243850u, + 36288867u, + 2981095630u, + 2480586007u, + 1287539180u, + 1804977887u, + 2219960896u, + 297158412u, + 2839013626u, + 1971706101u, + 3588181149u, + 1387242816u, + 3713499635u, + 3408234160u, + 3179393218u, + 1359207226u, + 3119279997u, + 2777679329u, + 125221793u, + 902631799u, + 949389096u, + 3415339313u, + 4117407143u, + 3119227103u, + 1787026946u, + 3917387257u, + 3936044384u, + 2242085379u, + 1140709958u, + 2523265662u, + 3627073995u, + 3604398568u, + 1427913954u, + 2465898599u, + 3825653050u, + 2090876078u, + 232270946u, + 3116274782u, + 1252172657u, + 3197497894u, + 3983224490u, + 1939344836u, + 4158531887u, + 88050086u, + 2343094701u, + 1067025562u, + 3321491106u, + 3772162169u, + 909332669u, + 1671671873u, + 755193996u, + 978524521u, + 2164582730u, + 1757783103u, + 3411415001u, + 850017018u, + 3068762300u, + 555996984u, + 2404040146u, + 3397007611u, + 237680219u, + 245818821u, + 177824968u, + 3220945682u, + 304446762u, + 2267298065u, + 1878973555u, + 3050739800u, + 535731508u, + 1160102565u, + 4109066907u, + 984269821u, + 3681788896u, + 60254699u, + 3890962421u, + 2991673698u, + 3982271427u, + 3514243671u, + 1234870914u, + 2069958363u, + 3867828422u, + 1847469687u, + 503598128u, + 967934988u, + 289386211u, + 393279961u, + 835485527u, + 3708682854u, + 965218590u, + 4020339834u, + 2159101708u, + 2575134771u, + 376656690u, + 3499375240u, + 3105954900u, + 2786692328u, + 3458480699u, + 1207173847u, + 2051152535u, + 2738812911u, + 2954646330u, + 2774866710u, + 2162149150u, + 3993372257u, + 2868120585u, + 3086420190u, + 3791115537u, + 3226697711u, + 1818303409u, + 4206013897u, + 1245186807u, + 1680347447u, + 684800149u, + 2372078492u, + 2566952562u, + 3310947940u, + 3885964747u, + 3270357885u, + 2098965232u, + 609044652u, + 434910954u, + 93043847u, + 805217072u, + 883298424u, + 3850995479u, + 1840717689u, + 124278163u, + 4250050101u, + 2337070911u, + 2576763405u, + 2518189119u, + 3059082421u, + 1532107996u, + 2920167825u, + 2726963926u, + 3951524890u, + 1272835728u, + 1039392592u, + 1237920408u, + 1996153268u, + 647883626u, + 4064365193u, + 355588474u, + 3625797533u, + 1209959194u, + 503163662u, + 530295589u, + 1668578780u, + 969028048u, + 2489337768u, + 841218738u, + 14126306u, + 1854884627u, + 3617055808u, + 202224793u, + 1744552899u, + 1559016256u, + 3455976027u, + 1064269942u, + 2990703287u, + 1169718685u, + 1411804743u, + 290849805u, + 756035681u, + 1505272475u, + 1426658932u, + 16045749u, + 3900455443u, + 108521850u, + 1009491914u, + 3928801938u, + 1022079325u, + 3076867150u, + 4268343543u, + 2886814247u, + 2005055376u, + 1649037732u, + 1954533894u, + 3779223482u, + 1093746989u, + 2376482601u, + 3561720470u, + 1870836501u, + 651953759u, + 1504660027u, + 2097900540u, + 2252668945u, + 2469849023u, + 1986217648u, + 2026387757u, + 131611273u, + 1467981299u, + 3440588252u, + 1916199579u, + 959039804u, + 2895114746u, + 3292235117u, + 649379239u, + 28649189u, + 3121113086u, + 3829761771u, + 1675837301u, + 1636154723u, + 3737794169u, + 4082428060u, + 1904712095u, + 2483810990u, + 979972563u, + 1269082707u, + 370986843u, + 1233170438u, + 3008501783u, + 3905837878u, + 1566704758u, + 2380919351u, + 159980022u, + 1334100319u, + 2492554074u, + 137995234u, + 2318192908u, + 2608964837u, + 1061756617u, + 2760140790u, + 4069446576u, + 1995030350u, + 1037005594u, + 3489306635u, + 1588786838u, + 513304862u, + 3305490303u, + 2264317975u, + 3441620307u, + 4116970950u, + 3121104936u, + 1889858928u, + 2336693483u, + 3906421686u, + 2112501080u, + 2916376262u, + 2244436629u, + 663123276u, + 774309763u, + 258379821u, + 3845948150u, + 3747409682u, + 275936617u, + 563064995u, + 4049677403u, + 2099547498u, + 699768412u, + 1193153383u, + 4289059706u, + 3228950241u, + 1258043728u, + 1334659727u, + 3780523664u, + 1150773584u, + 2509712235u, + 2088544320u, + 1610096547u, + 3486280247u, + 1737969289u, + 1530372860u, + 2563496419u, + 2535243890u, + 998106254u, + 816066803u, + 1138534811u, + 1405672211u, + 2094652173u, + 1516292650u, + 2618233360u, + 3603340340u, + 247950637u, + 119238855u, + 1858201484u, + 3459729922u, + 157759693u, + 8278624u, + 3223944237u, + 3937209237u, + 3820737454u, + 839194830u, + 2385155004u, + 3872251779u, + 1375779033u, + 2333521764u, + 4025446588u, + 3839106064u, + 374878047u, + 1312756310u, + 1661068116u, + 1321601295u, + 4254646350u, + 3813168945u, + 134103711u, + 1535586498u, + 82369644u, + 411323516u, + 761969086u, + 819179215u, + 582595825u, + 3212591411u, + 665647256u, + 2372804634u, + 2378814089u, + 801724318u, + 658137482u, + 2084329677u, + 2512952888u, + 1573871611u, + 570440739u, + 3791634131u, + 1754412850u, + 406040873u, + 2576963615u, + 535767962u, + 1405150444u, + 3050488583u, + 3870648463u, + 2201665400u, + 178518008u, + 1050761986u, + 1635790851u, + 2757604743u, + 1194306620u, + 3895813535u, + 259506203u, + 1836108753u, + 555242075u, + 2574778399u, + 777988603u, + 2306149504u, + 2810362568u, + 402408487u, + 2163697780u, + 1982851065u, + 153191404u, + 1346605886u, + 197579289u, + 3847665347u, + 2437615293u, + 819252195u, + 3379927756u, + 1375088563u, + 2650550959u, + 2949512074u, + 3616578300u, + 1616680753u, + 1943918335u, + 2372676669u, + 599487215u, + 2422499758u, + 3164569986u, + 594265585u, + 667867933u, + 2382753501u, + 1213715652u, + 1470661916u, + 566771851u, + 463440918u, + 3056034602u, + 4101174909u, + 130576467u, + 2390765932u, + 1878895359u, + 2047260663u, + 3236801323u, + 1417182786u, + 2650291174u, + 541535507u, + 2050658788u, + 1497955566u, + 2322165653u, + 2177087336u, + 1286897331u, + 1168276780u, + 2296212785u, + 865258239u, + 1996766009u, + 2012854679u, + 1601388981u, + 2613134235u, + 1657591526u, + 2928355430u, + 3608354462u, + 744304148u, + 4205438799u, + 3436255438u, + 2852837451u, + 3546154475u, + 2198801660u, + 2941229067u, + 1725744406u, + 1576016233u, + 326273484u, + 3350602572u, + 2525026956u, + 529269391u, + 742537386u, + 966948684u, + 4207482684u, + 1647708147u, + 772473614u, + 4100132656u, + 2071821864u, + 1304991378u, + 2104686786u, + 494532571u, + 1596637043u, + 3530310572u, + 3844404338u, + 311529967u, + 2146085784u, + 1023590767u, + 3264294551u, + 1868912500u, + 1616049700u, + 4044971489u, + 226083499u, + 2644402452u, + 671262u, + 3856282165u, + 2788249556u, + 2975877350u, + 3022011519u, + 482463024u, + 3197313892u, + 2458947070u, + 213085732u, + 3423982376u, + 1127434251u, + 3003351323u, + 3859782824u, + 1452447943u, + 1377205388u, + 294467710u, + 4017757977u, + 4176004933u, + 1973840971u, + 1057204069u, + 2631053578u, + 1518315828u, + 1733084351u, + 2897935365u, + 371135589u, + 2166429075u, + 1316999184u, + 917942378u, + 4234919037u, + 3994887147u, + 202839671u, + 2611806597u, + 1763402132u, + 2528354843u, + 2928374144u, + 4287461088u, + 3374274817u, + 2515840515u, + 1174711579u, + 1526125414u, + 1328334421u, + 1467789564u, + 746112865u, + 2522923249u, + 2846786366u, + 785624778u, + 3640382502u, + 699425627u, + 2333340032u, + 879149811u, + 1012137370u, + 3671295088u, + 1115225691u, + 2008076767u, + 3224593008u, + 409074767u, + 3405081375u, + 1732184447u, + 4131742042u, + 2887579728u, + 411122719u, + 49575303u, + 2452487329u, + 132404436u, + 2634269867u, + 628865612u, + 2089064207u, + 3493619675u, + 573570698u, + 2803401952u, + 1846326706u, + 2776480783u, + 3202282367u, + 161406647u, + 555882857u, + 3002347158u, + 3646590134u, + 3970439001u, + 3593229755u, + 589030935u, + 1156189491u, + 4233262968u, + 1884160487u, + 1538393768u, + 2259575756u, + 1419917258u, + 658738179u, + 2762821193u, + 3753817926u, + 760570680u, + 900223123u, + 3199204483u, + 3152387802u, + 3518662321u, + 1138026800u, + 4166103824u, + 4256962887u, + 3860671603u, + 2476911454u, + 336216996u, + 708885235u, + 725397672u, + 1803116762u, + 2785555576u, + 101740015u, + 4078718445u, + 1955237214u, + 9650972u, + 449296169u, + 584729435u, + 3295180521u, + 589654348u, + 4256205129u, + 3872811168u, + 1159848257u, + 3914402308u, + 739056677u, + 2654817235u, + 2975781832u, + 2945335776u, + 2792662538u, + 4124362519u, + 1578034244u, + 347127450u, + 818851140u, + 2127100315u, + 2486499071u, + 4198130806u, + 1869105609u, + 1961961717u, + 1651285423u, + 376774848u, + 2681263019u, + 1185959234u, + 1674813864u, + 32812913u, + 3511671436u, + 3250344299u, + 2961919237u, + 722029715u, + 3677835234u, + 3534013806u, + 2896926420u, + 2405611392u, + 1523923100u, + 538451356u, + 2872548905u, + 3122230170u, + 337087364u, + 2659340735u, + 3849128055u, + 556114376u, + 1997152544u, + 3761450839u, + 3143779940u, + 3256759779u, + 2844565122u, + 228442897u, + 3589092287u, + 786119294u, + 4089515771u, + 3720982051u, + 1236422652u, + 2002271241u, + 98809947u, + 1925281885u, + 3856119646u, + 3522402037u, + 2119723860u, + 3500067577u, + 3688915105u, + 443441159u, + 1795715271u, + 2772968214u, + 921416086u, + 4274010930u, + 3123194886u, + 4156595625u, + 2153773382u, + 1880645824u, + 1783695477u, + 2639075904u, + 2369609874u, + 2020298024u, + 3035677150u, + 20152938u, + 3700162244u, + 2301383878u, + 704787941u, + 1912605772u, + 801557569u, + 3080244537u, + 2116665331u, + 2452111071u, + 3506260614u, + 862540580u, + 1275699972u, + 66210903u, + 106773917u, + 3693457478u, + 2402783622u, + 1239121180u, + 676003037u, + 2603048829u, + 1725001637u, + 1220274379u, + 24507488u, + 903764486u, + 4189545897u, + 1702746631u, + 3218068652u, + 3306659191u, + 790973134u, + 1265526960u, + 3431804268u, + 3325211765u, + 3605213000u, + 2877687268u, + 2252987926u, + 2380945092u, + 858624424u, + 1002964636u, + 1862801950u, + 1624111941u, + 2506763607u, + 760658520u, + 2734479345u, + 3411969548u, + 771362694u, + 3655222003u, + 2713412965u, + 2617767046u, + 1779451182u, + 3696950253u, + 1494085808u, + 1423735456u, + 800705781u, + 3797847307u, + 3518984231u, + 196474988u, + 1813335502u, + 2243046583u, + 2578707704u, + 2592488572u, + 4085007200u, + 3609770110u, + 2731535571u, + 3190540952u, + 1865257805u, + 1804143221u, + 3166875197u, + 1184225570u, + 2013135819u, + 3678444101u, + 2569887572u, + 3559018477u, + 3823772506u, + 1537738480u, + 713705243u, + 792081862u, + 1581340885u, + 3140030205u, + 3435723625u, + 3093218524u, + 3683643763u, + 753869336u, + 590258834u, + 608176704u, + 180732483u, + 31365344u, + 29753898u, + 2899243456u, + 1020423361u, + 152655309u, + 3809554076u, + 2069071231u, + 4000441303u, + 3046501174u, + 1897816893u, + 1610689080u, + 2580357110u, + 255270539u, + 3363490012u, + 3711397066u, + 3983751767u, + 1725231855u, + 172296475u, + 2179003295u, + 660196982u, + 526538193u, + 2137670317u, + 2219075701u, + 1987239722u, + 856404486u, + 2976933454u, + 3678014122u, + 2713682703u, + 3329090001u, + 2248358519u, + 3254616418u, + 1747030903u, + 1620566606u, + 880370315u, + 2337236788u, + 2883145755u + }; + const int n = 768; + unsigned b[n] = {0}; + unsigned v[] = {3, 5, 7}; + const int size = sizeof(v)/sizeof(v[0]); + std::seed_seq s(v, v + size); + s.generate(b, b + n); + for (int i = 0; i < n; ++i) + assert(a[i] == b[i]); + } +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/initializer_list.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/initializer_list.pass.cpp new file mode 100644 index 000000000000..d4ee9c14d528 --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/initializer_list.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// template<class T> +// seed_seq(initializer_list<T> il); + +#include <random> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + std::seed_seq s= {5, 4, 3, 2, 1}; + assert(s.size() == 5); + unsigned b[5] = {0}; + s.param(b); + assert(b[0] == 5); + assert(b[1] == 4); + assert(b[2] == 3); + assert(b[3] == 2); + assert(b[4] == 1); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/iterator.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/iterator.pass.cpp new file mode 100644 index 000000000000..2214dca8aea8 --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/iterator.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq; + +// template<class InputIterator> +// seed_seq(InputIterator begin, InputIterator end); + +#include <random> +#include <cassert> + +int main() +{ + unsigned a[5] = {5, 4, 3, 2, 1}; + std::seed_seq s(a, a+5); + assert(s.size() == 5); + unsigned b[5] = {0}; + s.param(b); + assert(b[0] == 5); + assert(b[1] == 4); + assert(b[2] == 3); + assert(b[3] == 2); + assert(b[4] == 1); +} diff --git a/test/std/numerics/rand/rand.util/rand.util.seedseq/types.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.seedseq/types.pass.cpp new file mode 100644 index 000000000000..430d9b781d2b --- /dev/null +++ b/test/std/numerics/rand/rand.util/rand.util.seedseq/types.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <random> + +// class seed_seq +// { +// public: +// // types +// typedef uint_least32_t result_type; + +#include <random> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::seed_seq::result_type, std::uint_least32_t>::value), ""); +} |