Move test functions implementation to cpp.

GitOrigin-RevId: eec1d208f410a3f546dfe230d1780ecdac02d3b4
This commit is contained in:
levlam 2020-09-27 20:38:23 +03:00
parent a9a3acf135
commit 9322bf68cd
2 changed files with 28 additions and 23 deletions

View File

@ -12,6 +12,7 @@
#include "td/utils/PathView.h"
#include "td/utils/port/path.h"
#include "td/utils/port/Stat.h"
#include "td/utils/Random.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/Time.h"
@ -20,10 +21,35 @@
namespace td {
string rand_string(int from, int to, size_t len) {
string res(len, '\0');
for (auto &c : res) {
c = static_cast<char>(Random::fast(from, to));
}
return res;
}
vector<string> rand_split(Slice str) {
vector<string> res;
size_t pos = 0;
while (pos < str.size()) {
size_t len;
if (Random::fast(0, 1) == 1) {
len = Random::fast(1, 10);
} else {
len = Random::fast(100, 200);
}
res.push_back(str.substr(pos, len).str());
pos += len;
}
return res;
}
struct TestInfo {
string name;
string result_hash; // base64
};
StringBuilder &operator<<(StringBuilder &sb, const TestInfo &info) {
// should I use JSON?
CHECK(!info.name.empty());

View File

@ -11,7 +11,6 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/port/thread.h"
#include "td/utils/Random.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
@ -146,29 +145,9 @@ class Stage {
std::atomic<uint64> value_{0};
};
inline string rand_string(int from, int to, size_t len) {
string res(len, '\0');
for (auto &c : res) {
c = static_cast<char>(Random::fast(from, to));
}
return res;
}
string rand_string(int from, int to, size_t len);
inline vector<string> rand_split(Slice str) {
vector<string> res;
size_t pos = 0;
while (pos < str.size()) {
size_t len;
if (Random::fast(0, 1) == 1) {
len = Random::fast(1, 10);
} else {
len = Random::fast(100, 200);
}
res.push_back(str.substr(pos, len).str());
pos += len;
}
return res;
}
vector<string> rand_split(Slice str);
template <class T1, class T2>
void assert_eq_impl(const T1 &expected, const T2 &got, const char *file, int line) {