MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_replacements

Function test_replacements

scripts/test_stringzilla.cpp:4234–4257  ·  view source on GitHub ↗

* Evaluates the correctness of look-up table transforms using random lookup tables. * * @param lookup_tables_to_try The number of random lookup tables to try. * @param slices_per_table The number of random inputs to test per lookup table. */

Source from the content-addressed store, hash-verified

4232 * @param slices_per_table The number of random inputs to test per lookup table.
4233 */
4234void test_replacements(std::size_t lookup_tables_to_try = 32, std::size_t slices_per_table = 16) {
4235
4236 std::string body, transformed;
4237 body.resize(1024 * 1024); // 1MB
4238 transformed.resize(1024 * 1024);
4239 std::generate(body.begin(), body.end(), []() { return (char)(std::rand() % 256); });
4240
4241 for (std::size_t lookup_table_variation = 0; lookup_table_variation != lookup_tables_to_try;
4242 ++lookup_table_variation) {
4243 sz::look_up_table lut;
4244 for (std::size_t i = 0; i < 256; ++i) lut[(char)i] = (char)(std::rand() % 256);
4245
4246 for (std::size_t slice_idx = 0; slice_idx != slices_per_table; ++slice_idx) {
4247 std::size_t slice_offset = std::rand() % (body.length());
4248 std::size_t slice_length = std::rand() % (body.length() - slice_offset);
4249
4250 sz::lookup<char>(sz::string_view(body.data() + slice_offset, slice_length), lut,
4251 const_cast<char *>(transformed.data()) + slice_offset);
4252 for (std::size_t i = 0; i != slice_length; ++i) {
4253 assert(transformed[slice_offset + i] == lut[body[slice_offset + i]]);
4254 }
4255 }
4256 }
4257}
4258
4259/**
4260 * @brief Tests array sorting functionality, such as `argsort`, `sort`, and `sorted`.

Callers 1

mainFunction · 0.85

Calls 5

resizeMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…