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     /*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/);
41     /*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/);
42     static_assert((LCE::default_seed == 1), "");
43     where(LCE::multiplier);
44     where(LCE::increment);
45     where(LCE::modulus);
46     where(LCE::default_seed);
47 }
48 
49 template <class T>
50 void
test()51 test()
52 {
53     test1<T, 0, 0, 0>();
54     test1<T, 0, 1, 2>();
55     test1<T, 1, 1, 2>();
56     const T M(~0);
57     test1<T, 0, 0, M>();
58     test1<T, 0, M-2, M>();
59     test1<T, 0, M-1, M>();
60     test1<T, M-2, 0, M>();
61     test1<T, M-2, M-2, M>();
62     test1<T, M-2, M-1, M>();
63     test1<T, M-1, 0, M>();
64     test1<T, M-1, M-2, M>();
65     test1<T, M-1, M-1, M>();
66 }
67 
main()68 int main()
69 {
70     test<unsigned short>();
71     test<unsigned int>();
72     test<unsigned long>();
73     test<unsigned long long>();
74 }
75