From 8b763bedafb3919040af6ce95906c4f6d80f2655 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 2 Jan 2023 14:29:03 +0300 Subject: [PATCH] Move random_shuffle to tests.h. --- tdutils/td/utils/Random.h | 12 ------------ tdutils/td/utils/tests.h | 10 ++++++++++ tdutils/test/ChainScheduler.cpp | 2 +- tdutils/test/hashset_benchmark.cpp | 2 +- tdutils/test/heap.cpp | 2 +- test/online.cpp | 3 ++- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tdutils/td/utils/Random.h b/tdutils/td/utils/Random.h index 749e3f3fe..ee0d159ae 100644 --- a/tdutils/td/utils/Random.h +++ b/tdutils/td/utils/Random.h @@ -8,9 +8,6 @@ #include "td/utils/common.h" #include "td/utils/Slice.h" -#include "td/utils/Span.h" - -#include namespace td { @@ -57,13 +54,4 @@ class Random { }; }; -template -void random_shuffle(MutableSpan v, R &rnd) { - for (size_t i = 1; i < v.size(); i++) { - auto pos = static_cast(rnd()) % (i + 1); - using std::swap; - swap(v[i], v[pos]); - } -} - } // namespace td diff --git a/tdutils/td/utils/tests.h b/tdutils/td/utils/tests.h index 781571e78..8e2e518ee 100644 --- a/tdutils/td/utils/tests.h +++ b/tdutils/td/utils/tests.h @@ -12,6 +12,7 @@ #include "td/utils/logging.h" #include "td/utils/port/sleep.h" #include "td/utils/Slice.h" +#include "td/utils/Span.h" #include "td/utils/Status.h" #include @@ -165,6 +166,15 @@ string rand_string(int from, int to, size_t len); vector rand_split(Slice str); +template +void rand_shuffle(MutableSpan v, R &rnd) { + for (size_t i = 1; i < v.size(); i++) { + auto pos = static_cast(rnd()) % (i + 1); + using std::swap; + swap(v[i], v[pos]); + } +} + template void assert_eq_impl(const T1 &expected, const T2 &got, const char *file, int line) { LOG_CHECK(expected == got) << tag("expected", expected) << tag("got", got) << " in " << file << " at line " << line; diff --git a/tdutils/test/ChainScheduler.cpp b/tdutils/test/ChainScheduler.cpp index 3b04d73a1..029a4ff36 100644 --- a/tdutils/test/ChainScheduler.cpp +++ b/tdutils/test/ChainScheduler.cpp @@ -139,7 +139,7 @@ TEST(ChainScheduler, Stress) { int chain_n = rnd.fast(1, ChainsN); td::vector chain_ids(ChainsN); std::iota(chain_ids.begin(), chain_ids.end(), 0); - td::random_shuffle(td::as_mutable_span(chain_ids), rnd); + td::rand_shuffle(td::as_mutable_span(chain_ids), rnd); chain_ids.resize(chain_n); for (auto chain_id : chain_ids) { chains[td::narrow_cast(chain_id)].push_back(query); diff --git a/tdutils/test/hashset_benchmark.cpp b/tdutils/test/hashset_benchmark.cpp index a1df84465..026211d12 100644 --- a/tdutils/test/hashset_benchmark.cpp +++ b/tdutils/test/hashset_benchmark.cpp @@ -204,7 +204,7 @@ static void BM_Get(benchmark::State &state) { } std::size_t key_i = 0; - td::random_shuffle(td::as_mutable_span(keys), rnd); + td::rand_shuffle(td::as_mutable_span(keys), rnd); auto next_key = [&] { key_i++; if (key_i == data.size()) { diff --git a/tdutils/test/heap.cpp b/tdutils/test/heap.cpp index e78cc4d5e..bc317152d 100644 --- a/tdutils/test/heap.cpp +++ b/tdutils/test/heap.cpp @@ -23,7 +23,7 @@ TEST(Heap, sort_random_perm) { v[i] = i; } td::Random::Xorshift128plus rnd(123); - td::random_shuffle(td::as_mutable_span(v), rnd); + td::rand_shuffle(td::as_mutable_span(v), rnd); td::vector nodes(n); td::KHeap kheap; for (int i = 0; i < n; i++) { diff --git a/test/online.cpp b/test/online.cpp index 7f6210c89..1ffc5523f 100644 --- a/test/online.cpp +++ b/test/online.cpp @@ -23,6 +23,7 @@ #include "td/utils/port/signals.h" #include "td/utils/Promise.h" #include "td/utils/Random.h" +#include "td/utils/tests.h" #include #include @@ -437,7 +438,7 @@ class TestDownloadFile : public Task { begin = end; } - random_shuffle(as_mutable_span(ranges_), rnd); + rand_shuffle(as_mutable_span(ranges_), rnd); start_chunk(); }