]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / numerics / rand / rand.eng / rand.eng.mers / ctor_sseq_all_zero.pass.cpp
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, size_t w, size_t n, size_t m, size_t r,
13 //           UIntType a, size_t u, UIntType d, size_t s,
14 //           UIntType b, size_t t,
15 //           UIntType c, size_t l, UIntType f>
16 // class mersenne_twister_engine;
17
18 // template <class Sseq> explicit mersenne_twister_engine(Sseq &q);
19 //
20 //     [ ... ] Finally, if the most significant $w-r$ bits of $X_{-n}$ are zero,
21 //     and if each of the other resulting $X_i$ is $0$, changes $X_{-n}$ to
22 //     $ 2^{w-1} $.
23
24 #include <random>
25
26 #include <algorithm>
27 #include <cassert>
28 #include <cstddef>
29 #if TEST_STD_VER >= 11
30 #include <initializer_list>
31 #endif
32
33 struct all_zero_seed_seq {
34   typedef unsigned int result_type;
35
36   all_zero_seed_seq() {}
37
38   template <typename InputIterator>
39   all_zero_seed_seq(InputIterator, InputIterator) {}
40 #if TEST_STD_VER >= 11
41   all_zero_seed_seq(std::initializer_list<result_type>) {}
42 #endif
43
44   template <typename RandomAccessIterator>
45   void generate(RandomAccessIterator rb, RandomAccessIterator re) {
46     std::fill(rb, re, 0u);
47   }
48
49   std::size_t size() const { return 0u; }
50   template <typename OutputIterator> void param(OutputIterator) const {}
51 };
52
53 template <typename result_type, std::size_t word_size>
54 void test(void) {
55   const std::size_t state_size = 1u;
56   const std::size_t shift_size = 1u;
57   const std::size_t tempering_l = word_size;
58
59   all_zero_seed_seq q;
60   std::mersenne_twister_engine<result_type, word_size, state_size,
61                                shift_size,
62                                0u,
63                                0x0,
64                                0u, 0x0, 0u, 0x0, 0u, 0x0,
65                                tempering_l,
66                                0u>
67       e(q);
68
69   const result_type Xneg1 = result_type(1) << (word_size - 1);
70   const result_type Y = Xneg1;
71   const result_type X0 = Xneg1 ^ (Y >> 1);
72   assert(e() == X0);
73 }
74
75 int main() {
76   // Test for k == 1: word_size <= 32.
77   test<unsigned short, 3u>();
78
79   // Test for k == 2: (32 < word_size <= 64).
80   test<unsigned long long, 33u>();
81 }