MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / fuzzString

Function fuzzString

src/Storages/StorageFuzzJSON.cpp:258–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258String fuzzString(UInt64 min_length, UInt64 max_length, pcg64 & rnd, const String & source, std::function<char(pcg64 &)> charGen)
259{
260 String result;
261 result.reserve(max_length);
262
263 using FA = FuzzAction;
264 auto get_action = [&]() -> FuzzAction
265 {
266 static constexpr std::array<FuzzAction, 4> actions{FA::Skip, FA::Edit, FA::Add, FA::Delete};
267 return actions[uniform(0, 3)(rnd)];
268 };
269
270 size_t i = 0;
271 while (i < source.size() && result.size() < max_length)
272 {
273 auto action = get_action();
274 switch (action)
275 {
276 case FA::Skip: {
277 result.push_back(source[i++]);
278 }
279 break;
280 case FA::Edit: {
281 result.push_back(charGen(rnd));
282 ++i;
283 }
284 break;
285 case FA::Add: {
286 result.push_back(charGen(rnd));
287 }
288 break;
289 default:
290 ++i;
291 }
292 }
293
294 while (result.size() < min_length)
295 result.push_back(charGen(rnd));
296
297 return result;
298}
299
300String fuzzJSONKey(const StorageFuzzJSON::Configuration & config, pcg64 & rnd, const String & key)
301{

Callers 2

fuzzJSONKeyFunction · 0.85
fuzzJSONStructureFunction · 0.85

Calls 3

reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected