]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
Add experimental::sample and experimental::shuffle from N4531
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / algorithm / shuffle.cc
CommitLineData
37cb7887
JW
1// { dg-do run { target c++14 } }
2
3// Derived from: 2010-03-19 Paolo Carlini <paolo.carlini@oracle.com>
4
5// Copyright (C) 2010-2018 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 copy 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/algorithm>
23#include <vector>
24#include <testsuite_hooks.h>
25
26void test01()
27{
28 for (unsigned size = 0; size < 50; ++size)
29 {
30 std::vector<int> vref(size);
31 std::iota(vref.begin(), vref.end(), 0);
32 std::vector<int> v1(vref), v2(vref);
33
34 std::experimental::shuffle(v1.begin(), v1.end());
35 std::experimental::shuffle(v2.begin(), v2.end());
36
37 if (size >= 10)
38 {
39 VERIFY( !std::equal(v1.begin(), v1.end(), vref.begin()) );
40 VERIFY( !std::equal(v2.begin(), v2.end(), vref.begin()) );
41 VERIFY( !std::equal(v1.begin(), v1.end(), v2.begin()) );
42 }
43
44 for (unsigned ind = 0; ind < size; ++ind)
45 {
46 auto it1 = std::find(v1.begin(), v1.end(), vref[ind]);
47 auto it2 = std::find(v2.begin(), v2.end(), vref[ind]);
48 VERIFY( it1 != v1.end() );
49 VERIFY( it2 != v2.end() );
50 v1.erase(it1);
51 v2.erase(it2);
52 }
53 VERIFY( v1.empty() );
54 VERIFY( v2.empty() );
55 }
56}
57
58int main()
59{
60 test01();
61}