* testsuite/experimental/random/randint.cc: Add dg-add-options tls.
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / random / randint.cc
blob71ab67f4fbd9108d5c20dbc08dff16bc9aee47d4
1 // { dg-options "-std=gnu++14" }
2 // { dg-require-effective-target tls_runtime }
3 // { dg-add-options tls }
5 // Copyright (C) 2015 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a moved_to of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include <experimental/random>
23 #include <testsuite_hooks.h>
25 void
26 test01()
28 for (int i = 0; i < 100; ++i)
30 const int n = std::experimental::randint(-10, i);
31 VERIFY( -10 <= n && n <= i );
34 std::experimental::reseed(99u);
35 const long n1[] = {
36 std::experimental::randint(0, 100),
37 std::experimental::randint(0, 100),
38 std::experimental::randint(0, 100),
39 std::experimental::randint(0, 100),
40 std::experimental::randint(0, 100)
42 std::experimental::reseed(99u);
43 const long n2[] = {
44 std::experimental::randint(0, 100),
45 std::experimental::randint(0, 100),
46 std::experimental::randint(0, 100),
47 std::experimental::randint(0, 100),
48 std::experimental::randint(0, 100)
50 for (int i = 0; i < 5; ++i)
51 VERIFY( n1[i] == n2[i] );
53 std::experimental::reseed();
54 const long n3[] = {
55 std::experimental::randint(0, 100),
56 std::experimental::randint(0, 100),
57 std::experimental::randint(0, 100)
59 VERIFY( !(n3[0] == n1[0] && n3[1] == n1[1] && n3[2] == n1[2]) );
62 void
63 test02()
65 auto check = [](auto v) {
66 auto n = std::experimental::randint(decltype(v)(0), v);
67 static_assert(std::is_same<decltype(n), decltype(v)>::value,
68 "return type is correct");
69 VERIFY(0 <= n && n <= v);
71 check( (short)10 );
72 check( 100 );
73 check( 1000L );
74 check( 10000LL );
75 check( (unsigned short)10 );
76 check( 100U );
77 check( 1000UL );
78 check( 10000ULL );
81 int main()
83 test01();
84 test02();