Verified Commit 2867f542 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Fix spurious generation of shorter strings.

parent c87514a1
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ random_string(std::size_t length) {

    thread_local static std::mt19937 rng{std::random_device{}()};
    thread_local static std::uniform_int_distribution<std::string::size_type>
            pick(0, std::size(charset) - 1);
            pick(0, std::size(charset) - 2);

    std::string s(length, '\0');

+3 −2
Original line number Diff line number Diff line
@@ -45,10 +45,11 @@ SCENARIO("random strings can be generated", "[test_helpers][random_string]") {

        WHEN("Length is a positive integer") {

            const auto s = helpers::random_string(6);
            const std::size_t n = GENERATE(range(1, 5432));
            const auto s = helpers::random_string(n);

            THEN(" The generated string is empty ") {
                REQUIRE(s.length() == 6);
                REQUIRE(s.length() == n);
            }
        }
    }