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