]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/random/randint.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / random / randint.cc
1 // { dg-do run { target c++14 } }
2 // { dg-require-effective-target tls_runtime }
3 // { dg-add-options tls }
4
5 // Copyright (C) 2015-2016 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.
12
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.
17
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/>.
21
22 #include <experimental/random>
23 #include <testsuite_hooks.h>
24
25 void
26 test01()
27 {
28 for (int i = 0; i < 100; ++i)
29 {
30 const int n = std::experimental::randint(-10, i);
31 VERIFY( -10 <= n && n <= i );
32 }
33
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)
41 };
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)
49 };
50 for (int i = 0; i < 5; ++i)
51 VERIFY( n1[i] == n2[i] );
52
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)
58 };
59 VERIFY( !(n3[0] == n1[0] && n3[1] == n1[1] && n3[2] == n1[2]) );
60 }
61
62 void
63 test02()
64 {
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);
70 };
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 );
79 }
80
81 int main()
82 {
83 test01();
84 test02();
85 }