* @brief Tests the correctness of the string class update methods, such as `push_back` and `erase`. */
| 2217 | * @brief Tests the correctness of the string class update methods, such as `push_back` and `erase`. |
| 2218 | */ |
| 2219 | void 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==`. |