File: sample.cpp

package info (click to toggle)
range-v3 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,652 kB
  • sloc: cpp: 76,839; xml: 226; sh: 89; python: 34; makefile: 19; perl: 15
file content (42 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <range/v3/view/sample.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <numeric>
#include <vector>
#include <random>
#include "../simple_test.hpp"
#include "../test_utils.hpp"

using namespace ranges;

int main ()
{
    std::mt19937 engine;

    std::vector<int> pop(100);
    std::iota(std::begin(pop), std::end(pop), 0);
    {
        constexpr int N = 32;
        std::array<int, N> tmp;
        auto rng = pop | views::sample(N, engine);
        using Rng = decltype(rng);
        CPP_assert(input_range<Rng> && view_<Rng>);
        CPP_assert(!forward_range<Rng>);
        ranges::copy(rng, tmp.begin());
        rng = pop | views::sample(N, engine);
        CHECK(!ranges::equal(rng, tmp));
        engine = decltype(engine){};
        rng = pop | views::sample(N, engine);
        CHECK(ranges::equal(rng, tmp));
    }

    {
        int const some_ints[] = {0,1,2,3,4,5,6,7,8};
        auto rng = debug_input_view<int const>{some_ints} | views::sample(4, engine);
        using Rng = decltype(rng);
        CPP_assert(input_range<Rng> && view_<Rng>);
        CPP_assert(!forward_range<Rng>);
        CHECK(ranges::distance(rng) == 4);
    }

    return ::test_result();
}