• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 template <class _Tp>
where(const _Tp &)29 void where(const _Tp &) {}
30 
31 template <class T, T a, T c, T m>
32 void
test1()33 test1()
34 {
35     typedef std::linear_congruential_engine<T, a, c, m> LCE;
36     typedef typename LCE::result_type result_type;
37     static_assert((LCE::multiplier == a), "");
38     static_assert((LCE::increment == c), "");
39     static_assert((LCE::modulus == m), "");
40 #if TEST_STD_VER >= 11
41     static_assert((LCE::min() == (c == 0u ? 1u: 0u)), "");
42 #else
43     assert((LCE::min() == (c == 0u ? 1u: 0u)));
44 #endif
45 
46 #ifdef _MSC_VER
47     #pragma warning(push)
48     #pragma warning(disable: 4310) // cast truncates constant value
49 #endif // _MSC_VER
50 
51 #if TEST_STD_VER >= 11
52     static_assert((LCE::max() == result_type(m - 1u)), "");
53 #else
54     assert((LCE::max() == result_type(m - 1u)));
55 #endif
56 
57 #ifdef _MSC_VER
58     #pragma warning(pop)
59 #endif // _MSC_VER
60 
61     static_assert((LCE::default_seed == 1), "");
62     where(LCE::multiplier);
63     where(LCE::increment);
64     where(LCE::modulus);
65     where(LCE::default_seed);
66 }
67 
68 template <class T>
69 void
test()70 test()
71 {
72     test1<T, 0, 0, 0>();
73     test1<T, 0, 1, 2>();
74     test1<T, 1, 1, 2>();
75     const T M(static_cast<T>(-1));
76     test1<T, 0, 0, M>();
77     test1<T, 0, M-2, M>();
78     test1<T, 0, M-1, M>();
79     test1<T, M-2, 0, M>();
80     test1<T, M-2, M-2, M>();
81     test1<T, M-2, M-1, M>();
82     test1<T, M-1, 0, M>();
83     test1<T, M-1, M-2, M>();
84     test1<T, M-1, M-1, M>();
85 }
86 
main()87 int main()
88 {
89     test<unsigned short>();
90     test<unsigned int>();
91     test<unsigned long>();
92     test<unsigned long long>();
93 }
94