blob: 4b9980f59cea26f3ae52f60a89e7f09f022a0c74 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
28template <class T, T a, T c, T m>
29void
30test1()
31{
32 typedef std::linear_congruential_engine<T, a, c, m> LCE;
33 typedef typename LCE::result_type result_type;
34 static_assert((LCE::multiplier == a), "");
35 static_assert((LCE::increment == c), "");
36 static_assert((LCE::modulus == m), "");
37 /*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/);
38 /*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/);
39 static_assert((LCE::default_seed == 1), "");
40}
41
42template <class T>
43void
44test()
45{
46 test1<T, 0, 0, 0>();
47 test1<T, 0, 1, 2>();
48 test1<T, 1, 1, 2>();
49 const T M(~0);
50 test1<T, 0, 0, M>();
51 test1<T, 0, M-2, M>();
52 test1<T, 0, M-1, M>();
53 test1<T, M-2, 0, M>();
54 test1<T, M-2, M-2, M>();
55 test1<T, M-2, M-1, M>();
56 test1<T, M-1, 0, M>();
57 test1<T, M-1, M-2, M>();
58 test1<T, M-1, M-1, M>();
59}
60
61int main()
62{
63 test<unsigned short>();
64 test<unsigned int>();
65 test<unsigned long>();
66 test<unsigned long long>();
67}