Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / numerics / rand / rand.eng / rand.eng.lcong / values.pass.cpp
blobd9d47c5d8db46ca67e2b43327cb0ccc7ab106d8e
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 //===----------------------------------------------------------------------===//
9 // <random>
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;
23 #include <random>
24 #include <type_traits>
25 #include <cassert>
27 #include "test_macros.h"
29 template <class T>
30 void where(const T &) {}
32 template <class T, T a, T c, T m>
33 void
34 test1()
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
47 TEST_DIAGNOSTIC_PUSH
48 TEST_MSVC_DIAGNOSTIC_IGNORED(4310) // cast truncates constant value
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
56 TEST_DIAGNOSTIC_POP
58 static_assert((LCE::default_seed == 1), "");
59 where(LCE::multiplier);
60 where(LCE::increment);
61 where(LCE::modulus);
62 where(LCE::default_seed);
65 template <class T>
66 void
67 test()
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>();
84 int main(int, char**)
86 test<unsigned short>();
87 test<unsigned int>();
88 test<unsigned long>();
89 test<unsigned long long>();
91 return 0;