Skip to content

Commit

Permalink
Merge branch 'shuffled' into hoxnox
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxnox committed May 23, 2016
2 parents 27e44aa + 5a8e903 commit 25bbbeb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shuffled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class iter::impl::ShuffledView {
size_approx(lfsr::get_approx(size)),
in_begin(std::begin(container)), seed(seed),
container(std::forward<Container>(container)) {
if (size > 0)
{
if (size == 1) {
this->seed = 1;
}
else if (size > 1) {
uint64_t mask = 0xFFFFFFFFFFFFFFFFULL;
mask = (mask >> (64-size_approx));
this->seed = seed & mask;
Expand Down
8 changes: 8 additions & 0 deletions test/test_shuffled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,11 @@ TEST_CASE("shuffled: has correct ctor and assign ops", "[shuffled]") {
REQUIRE(itertest::IsMoveConstructibleOnly<ImpT<std::string>>::value);
}

TEST_CASE("shuffled: correct work with 1 and 0 sized container.", "[shuffled]") {
Vec onesz = {7};
for (auto &&i : shuffled(onesz))
REQUIRE(i == 7);
Vec zerosz;
for (auto &&i : shuffled(zerosz))
REQUIRE(false);
}

0 comments on commit 25bbbeb

Please sign in to comment.