1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <random> 10 11 // template <class UIntType, UIntType a, UIntType c, UIntType m> 12 // class linear_congruential_engine 13 // { 14 // public: 15 // engine characteristics 16 // static constexpr result_type multiplier = a; 17 // static constexpr result_type increment = c; 18 // static constexpr result_type modulus = m; 19 // static constexpr result_type min() { return c == 0u ? 1u: 0u;} 20 // static constexpr result_type max() { return m - 1u;} 21 // static constexpr result_type default_seed = 1u; 22 23 #include <random> 24 #include <type_traits> 25 #include <cassert> 26 27 #include "test_macros.h" 28 29 template <class T> 30 void where(const T &) {} 31 32 template <class T, T a, T c, T m> 33 void 34 test1() 35 { 36 typedef std::linear_congruential_engine<T, a, c, m> LCE; 37 typedef typename LCE::result_type result_type; 38 static_assert((LCE::multiplier == a), ""); 39 static_assert((LCE::increment == c), ""); 40 static_assert((LCE::modulus == m), ""); 41 #if TEST_STD_VER >= 11 42 static_assert((LCE::min() == (c == 0u ? 1u: 0u)), ""); 43 #else 44 assert((LCE::min() == (c == 0u ? 1u: 0u))); 45 #endif 46 47 TEST_DIAGNOSTIC_PUSH 48 TEST_MSVC_DIAGNOSTIC_IGNORED(4310) // cast truncates constant value 49 50 #if TEST_STD_VER >= 11 51 static_assert((LCE::max() == result_type(m - 1u)), ""); 52 #else 53 assert((LCE::max() == result_type(m - 1u))); 54 #endif 55 56 TEST_DIAGNOSTIC_POP 57 58 static_assert((LCE::default_seed == 1), ""); 59 where(LCE::multiplier); 60 where(LCE::increment); 61 where(LCE::modulus); 62 where(LCE::default_seed); 63 } 64 65 template <class T> 66 void 67 test() 68 { 69 test1<T, 0, 0, 0>(); 70 test1<T, 0, 1, 2>(); 71 test1<T, 1, 1, 2>(); 72 const T M(static_cast<T>(-1)); 73 test1<T, 0, 0, M>(); 74 test1<T, 0, M-2, M>(); 75 test1<T, 0, M-1, M>(); 76 test1<T, M-2, 0, M>(); 77 test1<T, M-2, M-2, M>(); 78 test1<T, M-2, M-1, M>(); 79 test1<T, M-1, 0, M>(); 80 test1<T, M-1, M-2, M>(); 81 test1<T, M-1, M-1, M>(); 82 } 83 84 int main(int, char**) 85 { 86 test<unsigned short>(); 87 test<unsigned int>(); 88 test<unsigned long>(); 89 test<unsigned long long>(); 90 91 return 0; 92 } 93