40# include <gtest/gtest.h>
53using namespace testing;
77 if (
delim.find(c) == string::npos)
79 else if (
not token.empty())
85 if (
not token.empty())
104 for (
size_t i = 0; i <
expected.size(); ++i)
121 for (
size_t i = 0; i <
expected.size(); ++i)
137 vector<int> v = {1, 2, 3};
157 string s =
"\t abc \n";
163 string s =
"\t abc \n";
186 auto s =
to_str(1.0 / 3.0);
205 s.push_back(
static_cast<char>(0xFF));
262 string s =
"prefix_value";
293 auto v =
split(
"a,b,,c",
',');
434 const string text =
"one two three four five";
528 std::ostringstream
out;
609 const string text =
"one two three four five";
621 const auto max_st = std::numeric_limits<size_t>::max();
625 const auto max_l = std::numeric_limits<long>::max();
626 const auto min_l = std::numeric_limits<long>::min();
634 const char *v = std::getenv(
"ALEPH_STRESS");
635 if (v ==
nullptr or *v ==
'\0')
639 const long m = std::strtol(v, &end, 10);
640 if (end == v
or *end !=
'\0')
654 std::uniform_int_distribution<int>
byte_dist(0, 255);
657 for (
size_t i = 0; i < len; ++i)
665 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
666 std::uniform_int_distribution<int> pick(0,
int(
sizeof(
alphabet) - 2));
669 for (
size_t i = 0; i < len; ++i)
676 std::mt19937
rng(12345);
680 for (
size_t pos = 0; pos <= s.size(); ++pos)
691 std::mt19937
rng(54321);
695 const size_t n = 1 + (size_t(
iter) % std::min<size_t>(16, s.size()));
702 const size_t base = s.size() / n;
703 for (
size_t i = 0; i + 1 < n; ++i)
710 std::mt19937
rng(999);
711 static const string delims =
" _-";
715 const size_t tokens = 1 + (size_t(
iter) % 12);
716 for (
size_t i = 0; i <
tokens; ++i)
725 out.for_each([&](
const string &t)
736 std::mt19937
rng(1337);
737 static const string delim_pool =
" ,;|/_-\t\n";
739 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
745 std::bernoulli_distribution
use_delim(0.30);
751 for (
int i = 0; i <
dsz; ++i)
756 text.reserve(
size_t(len));
757 for (
int i = 0; i < len; ++i)
774 std::mt19937
rng(2024);
787 std::mt19937
rng(77);
788 std::uniform_int_distribution<int> dist(-100000, 100000);
792 const int a = dist(
rng);
793 const int b = dist(
rng);
794 const int c = dist(
rng);
797 const auto expected = ::std::to_string(a) +
", " + ::std::to_string(b) +
", " + ::std::to_string(c);
String manipulation utilities.
static string random_ascii_token(std::mt19937 &rng, size_t len)
static string random_string(std::mt19937 &rng, size_t len)
static DynList< string > reference_split_string(const string &s, const string &delim)
Splits a string into non-empty tokens using a set of delimiter characters.
static void expect_tokens_eq(const DynList< string > &expected, const DynList< string > &got)
Asserts that two DynList<string> contain the same tokens in the same order.
static int stress_multiplier()
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Dynamic singly linked list with functional programming support.
T & append(const T &item)
size_t size() const noexcept
Count the number of elements of the list.
Type & nth(const size_t n)
Return the n-th item of the container.
Key * append(const Key &key)
Alias for insert() (copy version).
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
bool is_prefix(const std::string &str, const std::string &prefix)
Check whether prefix is a prefix of str.
std::string remove_symbols(const std::string &str, const std::string &symbols)
Remove any character appearing in symbols.
std::string to_upper(const std::string &str)
Convert a std::string to upper-case (byte-wise).
DynList< std::string > split_text_into_lines(const std::string &text)
Split a text into lines by "\n".
std::string justify_line_except_first(const std::string &text, const size_t width, const size_t left_margin=0)
Justify all lines except the first one.
DynList< std::string > split_text_into_words(const std::string &text)
Split a text into whitespace-separated words.
Array< std::string > split_to_array(const std::string &s, const std::string &delim)
Split a std::string into an Aleph::Array<std::string>.
std::pair< std::string, std::string > split_pos(const std::string &str, const size_t pos)
Split a std::string at a fixed position.
std::string remove_prefix(std::string &str, const std::string &prefix)
Remove prefix from str if present.
std::string & trim_in_place(std::string &s)
Trim a std::string in-place (leading + trailing whitespace removed).
std::string align_text_to_left(const std::string &text, const size_t page_width, const size_t left_margin=0)
Align text to the left by wrapping lines at page_width.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
bool contains(const std::string_view &str, const std::string_view &substr)
Check if substr appears inside str.
std::string to_Pascalcase(const std::string &str)
Convert an identifier-like std::string to PascalCase.
DynList< DynList< std::string > > format_string_csv(const DynList< DynList< std::string > > &mat)
Produce a CSV-like matrix (commas added to all but last element in each row).
bool is_long(const std::string &str)
Check whether a std::string fully parses as a long.
DynList< std::string > split_n(const std::string &str, const size_t n)
Split a std::string into n parts.
std::string to_name(const std::string &str)
Uppercase the first character of str and return the resulting copy.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
bool is_float(const std::string &str)
Check whether a std::string fully parses as a finite float.
bool is_size_t(const std::string &str)
Check whether a std::string fully parses as a non-negative size_t.
std::string trim(const std::string &s)
Return a trimmed copy of a std::string (leading + trailing whitespace removed).
DynList< std::string > split_camel_case(const char *const str)
Split a camelCase / PascalCase std::string into tokens.
void build_pars_list(std::string &unused)
Base case for build_pars_list(std::string&, ...).
std::string remove_spaces(const std::string &str)
Remove all whitespace characters from a std::string.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
std::string to_str(const double d)
Convert double to a std::string with maximum round-trip precision.
std::string justify_text(const std::string &text, const size_t width, const size_t left_margin=0)
Justify a text to a target width.
bool is_double(const std::string &str)
Check whether a std::string fully parses as a finite double.
DynList< std::string > split_to_list(const std::string &s, const std::string &delim)
Split a std::string into an Aleph::DynList<std::string>.
std::string shift_lines_to_left(const std::string &str, const size_t n)
Indent every line in a multi-line std::string by n spaces.
std::string concat(const Args &... args)
Concatenate multiple arguments into a single std::string.
DynList< DynList< T > > complete_rows(DynList< DynList< T > > &m)
Pad all rows of a matrix to the maximum row length.
std::string align_text_to_left_except_first(const std::string &text, const size_t width, const size_t left_margin=0)
Align all lines except the first one.
std::string toupper(const char *str)
Convert a C std::string to upper-case.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
std::vector< std::string > & split(const std::string &s, const char delim, std::vector< std::string > &elems)
Split a std::string by a single delimiter character.
DynList< DynList< std::string > > format_string(const DynList< size_t > &lens, const DynList< DynList< std::string > > &mat)
double safe_atof(const std::string &s)
Convert a std::string to double and throw on parse errors.
std::string to_lower(const std::string &str)
Convert a std::string to lower-case (byte-wise).
void fill_string(std::string &str, char sym)
Fill all the content of std::string with a defined char.
std::string & mutable_tolower(std::string &str)
Convert a std::string to lower-case in-place.
std::string & mutable_toupper(std::string &str)
Convert a std::string to upper-case in-place.
std::string only_alpha(const std::string &str)
Extract alphanumeric ASCII characters and normalize letters to lower-case.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)