Differential D91292 Diff 308912 libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// <random> | // <random> | ||||
// template <class UIntType, size_t w, size_t n, size_t m, size_t r, | // 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 a, size_t u, UIntType d, size_t s, | ||||
// UIntType b, size_t t, UIntType c, size_t l, UIntType f> | // UIntType b, size_t t, UIntType c, size_t l, UIntType f> | ||||
// class mersenne_twister_engine; | // class mersenne_twister_engine; | ||||
// explicit mersenne_twister_engine(result_type s = default_seed); | // explicit mersenne_twister_engine(result_type s = default_seed); // before C++20 | ||||
// mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} // C++20 | |||||
// explicit mersenne_twister_engine(result_type s); // C++20 | |||||
// Serializing/deserializing the state of the RNG requires iostreams | // Serializing/deserializing the state of the RNG requires iostreams | ||||
// UNSUPPORTED: libcpp-has-no-localization | // UNSUPPORTED: libcpp-has-no-localization | ||||
#include <random> | #include <random> | ||||
#include <sstream> | #include <sstream> | ||||
#include <cassert> | #include <cassert> | ||||
#include "test_macros.h" | #include "test_macros.h" | ||||
#if TEST_STD_VER >= 11 | |||||
#include "make_implicit.h" | |||||
#include "test_convertible.h" | |||||
#endif | |||||
template <class T> | |||||
std::string | |||||
to_string(T const &e) | |||||
{ | |||||
std::ostringstream os; | |||||
os << e; | |||||
return os.str(); | |||||
} | |||||
void | void | ||||
test1() | test1() | ||||
{ | { | ||||
const char* a = "0 1 1812433255 1900727105 1208447044 2481403966 4042607538 337614300 " | const char* a = "0 1 1812433255 1900727105 1208447044 2481403966 4042607538 337614300 " | ||||
"3232553940 1018809052 3202401494 1775180719 3192392114 594215549 184016991 " | "3232553940 1018809052 3202401494 1775180719 3192392114 594215549 184016991 " | ||||
"829906058 610491522 3879932251 3139825610 297902587 4075895579 2943625357 " | "829906058 610491522 3879932251 3139825610 297902587 4075895579 2943625357 " | ||||
"3530655617 1423771745 2135928312 2891506774 1066338622 135451537 933040465 " | "3530655617 1423771745 2135928312 2891506774 1066338622 135451537 933040465 " | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | test1() | ||||
"1708182873 2796363264 292154131 4280019913 1102652157 1185393592 " | "1708182873 2796363264 292154131 4280019913 1102652157 1185393592 " | ||||
"1494991690 4270076389 2384840717 425785147 2385321880 317514772 3926962743 " | "1494991690 4270076389 2384840717 425785147 2385321880 317514772 3926962743 " | ||||
"392176856 3465421709 1878853468 122662664 2958252160 1858961315 2244939588 " | "392176856 3465421709 1878853468 122662664 2958252160 1858961315 2244939588 " | ||||
"2361884409 2860936803 683833250 3291277128 1686857206 1112632275 " | "2361884409 2860936803 683833250 3291277128 1686857206 1112632275 " | ||||
"1200680507 3342928196 2677058150 939442136 3407104669 2906783932 " | "1200680507 3342928196 2677058150 939442136 3407104669 2906783932 " | ||||
"3668048733 2030009470 1910839172 1234925283 3575831445 123595418 " | "3668048733 2030009470 1910839172 1234925283 3575831445 123595418 " | ||||
"2362440495 3048484911 1796872496"; | "2362440495 3048484911 1796872496"; | ||||
std::mt19937 e1(0); | std::mt19937 e1(0); | ||||
std::ostringstream os; | assert(to_string(e1) == a); | ||||
os << e1; | |||||
assert(os.str() == a); | |||||
} | } | ||||
void | void | ||||
test2() | test2() | ||||
{ | { | ||||
const char* a = "0 1 6364136223846793007 13885033948157127961 " | const char* a = "0 1 6364136223846793007 13885033948157127961 " | ||||
"15324573939901584278 12737837167382305846 15195339788985155882 " | "15324573939901584278 12737837167382305846 15195339788985155882 " | ||||
"6554113247712070460 17235932740818599105 13007415075556305955 " | "6554113247712070460 17235932740818599105 13007415075556305955 " | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | test2() | ||||
"6533591052147596041 1308401457054431629 17488144120120152559 " | "6533591052147596041 1308401457054431629 17488144120120152559 " | ||||
"14075631579093810083 4015705597302725704 6833920126528811473 " | "14075631579093810083 4015705597302725704 6833920126528811473 " | ||||
"5095302940809114298 8312250184258072842 15770605014574863643 " | "5095302940809114298 8312250184258072842 15770605014574863643 " | ||||
"14091690436120485477 15763282477731738396 16394237160547425954 " | "14091690436120485477 15763282477731738396 16394237160547425954 " | ||||
"5066318118328746621 13140493775100916989 6371148952471982853 " | "5066318118328746621 13140493775100916989 6371148952471982853 " | ||||
"15150289760867914983 4931341382074091848 12635920082410445322 " | "15150289760867914983 4931341382074091848 12635920082410445322 " | ||||
"8498109357807439006 14836776625250834986"; | "8498109357807439006 14836776625250834986"; | ||||
std::mt19937_64 e1(0); | std::mt19937_64 e1(0); | ||||
std::ostringstream os; | assert(to_string(e1) == a); | ||||
os << e1; | } | ||||
assert(os.str() == a); | |||||
template <class E, typename Arg> | |||||
void test_implicit() { | |||||
#if TEST_STD_VER >= 11 | |||||
#if TEST_STD_VER > 17 | |||||
static_assert(test_convertible<E>(), ""); | |||||
assert(E(E::default_seed) == make_implicit<E>()); | |||||
#else | |||||
static_assert(!test_convertible<E>(), ""); | |||||
#endif | |||||
static_assert(!test_convertible<E, Arg>(), ""); | |||||
#endif | |||||
} | } | ||||
int main(int, char**) | int main(int, char**) | ||||
{ | { | ||||
test1(); | test1(); | ||||
test2(); | test2(); | ||||
test_implicit<std::mt19937, uint_fast32_t>(); | |||||
test_implicit<std::mt19937_64, uint_fast64_t>(); | |||||
return 0; | return 0; | ||||
} | } |