forked from tcbrindle/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fill.cpp
82 lines (59 loc) · 1.56 KB
/
test_fill.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2022 Tristan Brindle (tcbrindle at gmail dot com)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <array>
#include "test_utils.hpp"
namespace {
constexpr bool test_fill()
{
// Basic fill()
{
std::array<int, 5> arr{};
flux::fill(arr, 1);
STATIC_CHECK(check_equal(arr, {1, 1, 1, 1, 1}));
}
// fill and adapted sequence
{
std::array<int, 5> arr{};
flux::take(flux::mut_ref(arr), 3).fill(1);
STATIC_CHECK(check_equal(arr, {1, 1, 1, 0, 0}));
}
// single-pass sequences can be filled
{
std::array<int, 5> arr{};
single_pass_only(flux::mut_ref(arr)).fill(1);
STATIC_CHECK(check_equal(arr, {1, 1, 1, 1, 1}));
}
// empty sequences can be "filled"
{
auto e = flux::empty<int>;
flux::fill(e, 99);
}
// single sequences can be filled
{
auto s = flux::single(0);
flux::fill(s, short{1});
STATIC_CHECK(s.value() == 1);
}
// string fill with char
{
std::array<std::uint8_t, 5> arr{};
std::uint8_t c = 5;
flux::fill(arr, c);
STATIC_CHECK(check_equal(arr, {5, 5, 5, 5, 5}));
}
// fill empty sequence with char
{
std::array<std::uint8_t, 0> arr{};
std::uint8_t c = 5;
flux::fill(arr, c);
}
return true;
}
static_assert(test_fill());
}
TEST_CASE("fill")
{
bool result = test_fill();
REQUIRE(result);
}