diff options
Diffstat (limited to 'test/std/algorithms/alg.modifying.operations/alg.random.shuffle')
3 files changed, 98 insertions, 0 deletions
diff --git a/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp new file mode 100644 index 0000000000000..a14ccf9e5e6c7 --- /dev/null +++ b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<RandomAccessIterator Iter> +// requires ShuffleIterator<Iter> +// void +// random_shuffle(Iter first, Iter last); + +#include <algorithm> +#include <cassert> + +int main() +{ + int ia[] = {1, 2, 3, 4}; + int ia1[] = {1, 4, 3, 2}; + int ia2[] = {4, 1, 2, 3}; + const unsigned sa = sizeof(ia)/sizeof(ia[0]); + std::random_shuffle(ia, ia+sa); + assert(std::equal(ia, ia+sa, ia1)); + std::random_shuffle(ia, ia+sa); + assert(std::equal(ia, ia+sa, ia2)); +} diff --git a/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp new file mode 100644 index 0000000000000..b944c89e35192 --- /dev/null +++ b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand> +// requires ShuffleIterator<Iter> +// && Convertible<Rand::result_type, Iter::difference_type> +// void +// random_shuffle(Iter first, Iter last, Rand&& rand); + +#include <algorithm> +#include <cassert> + +struct gen +{ + int operator()(int n) + { + return n-1; + } +}; + +int main() +{ + int ia[] = {1, 2, 3, 4}; + int ia1[] = {4, 1, 2, 3}; + const unsigned sa = sizeof(ia)/sizeof(ia[0]); + gen r; + std::random_shuffle(ia, ia+sa, r); + assert(std::equal(ia, ia+sa, ia1)); +} diff --git a/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp new file mode 100644 index 0000000000000..343ae90101ffc --- /dev/null +++ b/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<class RandomAccessIterator, class UniformRandomNumberGenerator> +// void shuffle(RandomAccessIterator first, RandomAccessIterator last, +// UniformRandomNumberGenerator& g); + +#include <algorithm> +#include <random> +#include <cassert> + +int main() +{ + int ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int ia1[] = {2, 7, 1, 4, 3, 6, 5, 10, 9, 8}; + int ia2[] = {1, 8, 3, 4, 6, 9, 5, 7, 2, 10}; + const unsigned sa = sizeof(ia)/sizeof(ia[0]); + std::minstd_rand g; + std::shuffle(ia, ia+sa, g); + assert(std::equal(ia, ia+sa, ia1)); + std::shuffle(ia, ia+sa, g); + assert(std::equal(ia, ia+sa, ia2)); +} |