[TableGen] Split DAGISelMatcherOpt FactorNodes into 2 functions. NFC (#125330)
[llvm-project.git] / libcxx / test / std / numerics / rand / rand.eng / rand.eng.lcong / copy.pass.cpp
blobad473bdc58371c4eb11a70b87b5d883d6654bf8d
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;
14 // linear_congruential_engine(const linear_congruential_engine&);
16 #include <random>
17 #include <cassert>
18 #include <climits>
20 #include "test_macros.h"
22 template <class T, T a, T c, T m>
23 void
24 test1()
26 typedef std::linear_congruential_engine<T, a, c, m> E;
27 E e1;
28 E e2 = e1;
29 assert(e1 == e2);
30 (void)e1();
31 (void)e2();
32 assert(e1 == e2);
35 template <class T>
36 void
37 test()
39 const int W = sizeof(T) * CHAR_BIT;
40 const T M(static_cast<T>(-1));
41 const T A(static_cast<T>((static_cast<T>(1) << (W / 2)) - 1));
43 // Cases where m = 0
44 test1<T, 0, 0, 0>();
45 test1<T, A, 0, 0>();
46 test1<T, 0, 1, 0>();
47 test1<T, A, 1, 0>();
49 // Cases where m = 2^n for n < w
50 test1<T, 0, 0, 256>();
51 test1<T, 5, 0, 256>();
52 test1<T, 0, 1, 256>();
53 test1<T, 5, 1, 256>();
55 // Cases where m is odd and a = 0
56 test1<T, 0, 0, M>();
57 test1<T, 0, M - 2, M>();
58 test1<T, 0, M - 1, M>();
60 // Cases where m is odd and m % a <= m / a (Schrage)
61 test1<T, A, 0, M>();
62 test1<T, A, M - 2, M>();
63 test1<T, A, M - 1, M>();
66 template <class T>
67 void test_ext() {
68 const T M(static_cast<T>(-1));
70 // Cases where m is odd and m % a > m / a
71 test1<T, M - 2, 0, M>();
72 test1<T, M - 2, M - 2, M>();
73 test1<T, M - 2, M - 1, M>();
74 test1<T, M - 1, 0, M>();
75 test1<T, M - 1, M - 2, M>();
76 test1<T, M - 1, M - 1, M>();
79 int main(int, char**)
81 test<unsigned short>();
82 test_ext<unsigned short>();
83 test<unsigned int>();
84 test_ext<unsigned int>();
85 test<unsigned long>();
86 // This isn't implemented on platforms without __int128
87 #ifndef TEST_HAS_NO_INT128
88 test_ext<unsigned long>();
89 #endif
90 test<unsigned long long>();
91 // This isn't implemented on platforms without __int128
92 #ifndef TEST_HAS_NO_INT128
93 test_ext<unsigned long long>();
94 #endif
96 return 0;