Differential D91292 Diff 304732 libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/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, UIntType a, UIntType c, UIntType m> | // template <class UIntType, UIntType a, UIntType c, UIntType m> | ||||
// class linear_congruential_engine; | // class linear_congruential_engine; | ||||
// explicit linear_congruential_engine(result_type s = default_seed); | // explicit linear_congruential_engine(result_type s = default_seed); // before C++20 | ||||
// linear_congruential_engine() : linear_congruential_engine(default_seed) {} // C++20 | |||||
// explicit linear_congruential_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" | ||||
template <class T> | template <class T> | ||||
std::string | |||||
to_string(T const &e) | |||||
{ | |||||
std::ostringstream os; | |||||
os << e; | |||||
return os.str(); | |||||
} | |||||
template <class T> | |||||
void | void | ||||
test1() | test1() | ||||
{ | { | ||||
// c % m != 0 && s % m != 0 | // c % m != 0 && s % m != 0 | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 7> E; | typedef std::linear_congruential_engine<T, 2, 3, 7> E; | ||||
E e(5); | E e(5); | ||||
std::ostringstream os; | assert(to_string(e) == "5"); | ||||
os << e; | |||||
assert(os.str() == "5"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 0> E; | typedef std::linear_congruential_engine<T, 2, 3, 0> E; | ||||
E e(5); | E e(5); | ||||
std::ostringstream os; | assert(to_string(e) == "5"); | ||||
os << e; | |||||
assert(os.str() == "5"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 4> E; | typedef std::linear_congruential_engine<T, 2, 3, 4> E; | ||||
E e(5); | E e(5); | ||||
std::ostringstream os; | assert(to_string(e) == "1"); | ||||
os << e; | |||||
assert(os.str() == "1"); | |||||
} | } | ||||
} | } | ||||
template <class T> | template <class T> | ||||
void | void | ||||
test2() | test2() | ||||
{ | { | ||||
// c % m != 0 && s % m == 0 | // c % m != 0 && s % m == 0 | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 7> E; | typedef std::linear_congruential_engine<T, 2, 3, 7> E; | ||||
E e(7); | E e(7); | ||||
std::ostringstream os; | assert(to_string(e) == "0"); | ||||
os << e; | |||||
assert(os.str() == "0"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 0> E; | typedef std::linear_congruential_engine<T, 2, 3, 0> E; | ||||
E e(0); | E e(0); | ||||
std::ostringstream os; | assert(to_string(e) == "0"); | ||||
os << e; | |||||
assert(os.str() == "0"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 3, 4> E; | typedef std::linear_congruential_engine<T, 2, 3, 4> E; | ||||
E e(4); | E e(4); | ||||
std::ostringstream os; | assert(to_string(e) == "0"); | ||||
os << e; | |||||
assert(os.str() == "0"); | |||||
} | } | ||||
} | } | ||||
template <class T> | template <class T> | ||||
void | void | ||||
test3() | test3() | ||||
{ | { | ||||
// c % m == 0 && s % m != 0 | // c % m == 0 && s % m != 0 | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 7> E; | typedef std::linear_congruential_engine<T, 2, 0, 7> E; | ||||
E e(3); | E e(3); | ||||
std::ostringstream os; | assert(to_string(e) == "3"); | ||||
os << e; | |||||
assert(os.str() == "3"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 0> E; | typedef std::linear_congruential_engine<T, 2, 0, 0> E; | ||||
E e(5); | E e(5); | ||||
std::ostringstream os; | assert(to_string(e) == "5"); | ||||
os << e; | |||||
assert(os.str() == "5"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 4> E; | typedef std::linear_congruential_engine<T, 2, 0, 4> E; | ||||
E e(7); | E e(7); | ||||
std::ostringstream os; | assert(to_string(e) == "3"); | ||||
os << e; | |||||
assert(os.str() == "3"); | |||||
} | } | ||||
} | } | ||||
template <class T> | template <class T> | ||||
void | void | ||||
test4() | test4() | ||||
{ | { | ||||
// c % m == 0 && s % m == 0 | // c % m == 0 && s % m == 0 | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 7> E; | typedef std::linear_congruential_engine<T, 2, 0, 7> E; | ||||
E e(7); | E e(7); | ||||
std::ostringstream os; | assert(to_string(e) == "1"); | ||||
os << e; | |||||
assert(os.str() == "1"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 0> E; | typedef std::linear_congruential_engine<T, 2, 0, 0> E; | ||||
E e(0); | E e(0); | ||||
std::ostringstream os; | assert(to_string(e) == "1"); | ||||
os << e; | |||||
assert(os.str() == "1"); | |||||
} | } | ||||
{ | { | ||||
typedef std::linear_congruential_engine<T, 2, 0, 4> E; | typedef std::linear_congruential_engine<T, 2, 0, 4> E; | ||||
E e(8); | E e(8); | ||||
std::ostringstream os; | assert(to_string(e) == "1"); | ||||
os << e; | |||||
assert(os.str() == "1"); | |||||
} | } | ||||
} | } | ||||
#if TEST_STD_VER > 17 | |||||
template <class T, class... Args> | |||||
T | |||||
make_implicit(Args &&... args) | |||||
{ | |||||
return {forward<Args>(args)...}; | |||||
} | |||||
template <class T> | |||||
void | |||||
test5() | |||||
{ | |||||
typedef std::linear_congruential_engine<T, 2, 0, 7> E; | |||||
auto e_default = make_implicit<E>(); | |||||
auto e_1 = E(1); | |||||
assert(to_string(e_default) == to_string(e_1)); | |||||
assert(to_string(e_default) == "1"); | |||||
} | |||||
#endif | |||||
int main(int, char**) | int main(int, char**) | ||||
{ | { | ||||
test1<unsigned short>(); | test1<unsigned short>(); | ||||
test1<unsigned int>(); | test1<unsigned int>(); | ||||
test1<unsigned long>(); | test1<unsigned long>(); | ||||
test1<unsigned long long>(); | test1<unsigned long long>(); | ||||
test2<unsigned short>(); | test2<unsigned short>(); | ||||
test2<unsigned int>(); | test2<unsigned int>(); | ||||
test2<unsigned long>(); | test2<unsigned long>(); | ||||
test2<unsigned long long>(); | test2<unsigned long long>(); | ||||
test3<unsigned short>(); | test3<unsigned short>(); | ||||
test3<unsigned int>(); | test3<unsigned int>(); | ||||
test3<unsigned long>(); | test3<unsigned long>(); | ||||
test3<unsigned long long>(); | test3<unsigned long long>(); | ||||
test4<unsigned short>(); | test4<unsigned short>(); | ||||
test4<unsigned int>(); | test4<unsigned int>(); | ||||
test4<unsigned long>(); | test4<unsigned long>(); | ||||
test4<unsigned long long>(); | test4<unsigned long long>(); | ||||
#if TEST_STD_VER > 17 | |||||
test5<unsigned short>(); | |||||
test5<unsigned int>(); | |||||
test5<unsigned long>(); | |||||
test5<unsigned long long>(); | |||||
#endif | |||||
return 0; | return 0; | ||||
} | } |