diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index d51479eab..ca2d905bc 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -362,4 +362,44 @@ TEST_CASE("algorithms") } } + + SECTION("fill") + { + SECTION("fill zeros") + { + json dest_arr = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + + std::fill(dest_arr.begin(), dest_arr.end(), 0); + + CHECK(dest_arr == json({0, 0, 0, 0, 0, 0, 0, 0, 0})); + } + SECTION("fill char value") + { + json dest_arr = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + const char val = '1'; + std::fill(dest_arr.begin(), dest_arr.end(), val); + + CHECK(dest_arr == json({val, val, val, val, val, val, val, val, val})); + } + SECTION("fill n zeros") + { + json dest_arr = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + const size_t n = 5; + + std::fill_n(dest_arr.begin(), n, 0); + + CHECK(dest_arr == json({0, 0, 0, 0, 0, 1, 1, 1, 1})); + } + SECTION("fill n chars") + { + json dest_arr = {1, 2, 3, 4, 5, 6, 7, '8', '9'}; + const size_t n = 2; + + std::fill_n(dest_arr.begin(), n, '1'); + + CHECK(dest_arr == json({'1', '1', 3, 4, 5, 6, 7, '8', '9'})); + } + } + + }