From a2856f331721fe752be377b849b77a718e40f468 Mon Sep 17 00:00:00 2001 From: heck Date: Sun, 17 Oct 2021 23:13:18 +0200 Subject: [PATCH] Tests: test_rand.cc --- test/test_rand.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/test_rand.cc b/test/test_rand.cc index f4b33a8..ab0e2ed 100644 --- a/test/test_rand.cc +++ b/test/test_rand.cc @@ -6,10 +6,27 @@ using namespace pEp; + +int test_random_string_fast() +{ + pEpLog("Test test_random_string_fast() correct length, min & max"); + for (int i = 0; i < 1000; i++) { + uint len = Utils::random_fast(5000); + std::string res = Utils::random_string_fast(0, 255, len); + PITYASSERT( + res.length() == len, + "random_string_fast: wrong length: " + + std::to_string(res.length()) + " is not " + std::to_string(len)); + } + return 0; +} + int main() { pEp::Adapter::pEpLog::set_enabled(true); + test_random_string_fast(); + pEpLog("Random functions benchmark"); int nr_mb = 10; int nr_bytes = 1024 * 1024 * nr_mb; @@ -33,7 +50,7 @@ int main() pEpLog("Utils::Fastrand()"); auto time_start = std::chrono::steady_clock::now(); for (int i = 0; i < nr_bytes; i++) { - Utils::fastrand(255); + Utils::random_fast(255); } auto time_end = std::chrono::steady_clock::now(); double duration_ms = (double)std::chrono::duration_cast(