Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test algo cpp 11 #4210

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
40 changes: 40 additions & 0 deletions tests/src/unit-algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a different value than used to initialize the container initially?

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'}));
}
}


}
Loading