]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/shuffle/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / shuffle / 1.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-cstdint "" }
3
4 // 2010-03-19 Paolo Carlini <paolo.carlini@oracle.com>
5
6 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
13
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
22
23 #include <algorithm>
24 #include <random>
25 #include <vector>
26 #include <testsuite_hooks.h>
27
28 void test01()
29 {
30 for (unsigned size = 0; size < 50; ++size)
31 {
32 std::vector<int> vref(size);
33 std::iota(vref.begin(), vref.end(), 0);
34 std::vector<int> v1(vref), v2(vref);
35
36 std::ranlux48_base g1(size), g2(size + 1);
37 std::shuffle(v1.begin(), v1.end(), g1);
38 std::shuffle(v2.begin(), v2.end(), g2);
39
40 if (size >= 10)
41 {
42 VERIFY( !std::equal(v1.begin(), v1.end(), vref.begin()) );
43 VERIFY( !std::equal(v2.begin(), v2.end(), vref.begin()) );
44 VERIFY( !std::equal(v1.begin(), v1.end(), v2.begin()) );
45 }
46
47 for (unsigned ind = 0; ind < size; ++ind)
48 {
49 auto it1 = std::find(v1.begin(), v1.end(), vref[ind]);
50 auto it2 = std::find(v2.begin(), v2.end(), vref[ind]);
51 VERIFY( it1 != v1.end() );
52 VERIFY( it2 != v2.end() );
53 v1.erase(it1);
54 v2.erase(it2);
55 }
56 VERIFY( v1.empty() );
57 VERIFY( v2.empty() );
58 }
59 }
60
61 int main()
62 {
63 test01();
64 return 0;
65 }