blob: e2f329cb30984299ee98280e439644bf0295e2f2 [file] [log] [blame]
// Copyright (C) 2020-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do run { target c++2a } }
// { dg-require-cstdint "" }
#include <algorithm>
#include <random>
#include <vector>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
using __gnu_test::test_container;
using __gnu_test::test_range;
using __gnu_test::random_access_iterator_wrapper;
namespace ranges = std::ranges;
// This test is adapted from 25_algorithms/shuffle/1.cc.
void
test01()
{
for (unsigned size = 0; size < 50; ++size)
{
std::vector<int> vref(size);
std::iota(vref.begin(), vref.end(), 0);
std::vector<int> v1(vref), v2(vref);
test_container<int, random_access_iterator_wrapper> c
= {v1.data(), v1.data() + size};
test_range<int, random_access_iterator_wrapper> r
= {v2.data(), v2.data() + size};
std::ranlux48_base g1(size), g2(size + 1);
VERIFY( ranges::shuffle(c, g1) == c.end() );
VERIFY( ranges::shuffle(ranges::begin(r), ranges::end(r), g2)
== ranges::end(r) );
if (size >= 10)
{
VERIFY( !ranges::equal(c, vref) );
VERIFY( !ranges::equal(r, vref) );
VERIFY( !ranges::equal(c, r) );
}
VERIFY( ranges::is_permutation(c, vref) );
VERIFY( ranges::is_permutation(r, vref) );
}
}
int
main()
{
test01();
}