1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <random>
11
12 // template <class UIntType, UIntType a, UIntType c, UIntType m>
13 // class linear_congruential_engine
14 // {
15 // public:
16 // engine characteristics
17 // static constexpr result_type multiplier = a;
18 // static constexpr result_type increment = c;
19 // static constexpr result_type modulus = m;
20 // static constexpr result_type min() { return c == 0u ? 1u: 0u;}
21 // static constexpr result_type max() { return m - 1u;}
22 // static constexpr result_type default_seed = 1u;
23
24 #include <random>
25 #include <type_traits>
26 #include <cassert>
27
28 #include "test_macros.h"
29
30 template <class T>
where(const T &)31 void where(const T &) {}
32
33 template <class T, T a, T c, T m>
34 void
test1()35 test1()
36 {
37 typedef std::linear_congruential_engine<T, a, c, m> LCE;
38 typedef typename LCE::result_type result_type;
39 static_assert((LCE::multiplier == a), "");
40 static_assert((LCE::increment == c), "");
41 static_assert((LCE::modulus == m), "");
42 #if TEST_STD_VER >= 11
43 static_assert((LCE::min() == (c == 0u ? 1u: 0u)), "");
44 #else
45 assert((LCE::min() == (c == 0u ? 1u: 0u)));
46 #endif
47
48 #ifdef TEST_COMPILER_C1XX
49 #pragma warning(push)
50 #pragma warning(disable: 4310) // cast truncates constant value
51 #endif // TEST_COMPILER_C1XX
52
53 #if TEST_STD_VER >= 11
54 static_assert((LCE::max() == result_type(m - 1u)), "");
55 #else
56 assert((LCE::max() == result_type(m - 1u)));
57 #endif
58
59 #ifdef TEST_COMPILER_C1XX
60 #pragma warning(pop)
61 #endif // TEST_COMPILER_C1XX
62
63 static_assert((LCE::default_seed == 1), "");
64 where(LCE::multiplier);
65 where(LCE::increment);
66 where(LCE::modulus);
67 where(LCE::default_seed);
68 }
69
70 template <class T>
71 void
test()72 test()
73 {
74 test1<T, 0, 0, 0>();
75 test1<T, 0, 1, 2>();
76 test1<T, 1, 1, 2>();
77 const T M(static_cast<T>(-1));
78 test1<T, 0, 0, M>();
79 test1<T, 0, M-2, M>();
80 test1<T, 0, M-1, M>();
81 test1<T, M-2, 0, M>();
82 test1<T, M-2, M-2, M>();
83 test1<T, M-2, M-1, M>();
84 test1<T, M-1, 0, M>();
85 test1<T, M-1, M-2, M>();
86 test1<T, M-1, M-1, M>();
87 }
88
main()89 int main()
90 {
91 test<unsigned short>();
92 test<unsigned int>();
93 test<unsigned long>();
94 test<unsigned long long>();
95 }
96