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

Function test_updates

scripts/test_stringzilla.cpp:2219–2241  ·  view source on GitHub ↗

* @brief Tests the correctness of the string class update methods, such as `push_back` and `erase`. */

Source from the content-addressed store, hash-verified

2217 * @brief Tests the correctness of the string class update methods, such as `push_back` and `erase`.
2218 */
2219void test_updates(std::size_t repetitions = 1024) {
2220 // Compare STL and StringZilla strings append functionality.
2221 char const alphabet_chars[] = "abcdefghijklmnopqrstuvwxyz";
2222 for (std::size_t repetition = 0; repetition != repetitions; ++repetition) {
2223 std::string stl_string;
2224 sz::string sz_string;
2225 for (std::size_t length = 1; length != 200; ++length) {
2226 char c = alphabet_chars[std::rand() % 26];
2227 stl_string.push_back(c);
2228 sz_string.push_back(c);
2229 assert(sz::string_view(stl_string) == sz::string_view(sz_string));
2230 }
2231
2232 // Compare STL and StringZilla strings erase functionality.
2233 while (stl_string.length()) {
2234 std::size_t offset_to_erase = std::rand() % stl_string.length();
2235 std::size_t chars_to_erase = std::rand() % (stl_string.length() - offset_to_erase) + 1;
2236 stl_string.erase(offset_to_erase, chars_to_erase);
2237 sz_string.erase(offset_to_erase, chars_to_erase);
2238 assert(sz::string_view(stl_string) == sz::string_view(sz_string));
2239 }
2240 }
2241}
2242
2243/**
2244 * @brief Tests the correctness of the string class comparison methods, such as `compare` and `operator==`.

Callers 1

mainFunction · 0.85

Calls 3

push_backMethod · 0.80
eraseMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…