From 2867f5428e12e1762c32f9145d1b34cb7681196a Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Fri, 2 Jul 2021 21:08:00 +0200 Subject: [PATCH] Fix spurious generation of shorter strings. --- tests/unit/helpers/random_string.cpp | 2 +- tests/unit/test_helpers.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/helpers/random_string.cpp b/tests/unit/helpers/random_string.cpp index d4c8ca5cd..223a70e9e 100644 --- a/tests/unit/helpers/random_string.cpp +++ b/tests/unit/helpers/random_string.cpp @@ -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 - pick(0, std::size(charset) - 1); + pick(0, std::size(charset) - 2); std::string s(length, '\0'); diff --git a/tests/unit/test_helpers.cpp b/tests/unit/test_helpers.cpp index 27d90e6b4..c606931d0 100644 --- a/tests/unit/test_helpers.cpp +++ b/tests/unit/test_helpers.cpp @@ -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); } } } -- GitLab