29 return static_cast<char>(32 +
Rand() % 95);
35 return static_cast<char>(33 +
Rand() % 94);
37 return ws_delim[
Rand() % 4];
46 std::vector<std::string> str_vec;
54 for (
int j = 0;
j < 100;
j++) {
55 std::vector<std::string> str_vec;
58 for (
int i = 0;
i < sz-1;
i++) {
63 bool omit_empty_strings = (
Rand() %2 == 0)?
true :
false;
66 for (
size_t i = 0;
i < str_vec.size();
i++) {
68 new_full.append(str_vec[
i]);
69 if (i < str_vec.size() -1) new_full.append(delim);
71 std::string new_full2;
73 if (omit_empty_strings) {
74 size_t start = full.find_first_not_of(delim),
75 end = full.find_last_not_of(delim);
76 if (start == std::string::npos) {
79 std::string full_test;
81 for (
size_t i = start;
i <= end;
i++) {
82 if (full[
i] != last || last != *delim.c_str())
83 full_test.push_back(full[
i]);
91 }
else if (!full.empty()) {
100 std::vector<int32> v;
102 && v.size() == 3 && v[0] == -1 && v[1] == 2 && v[2] == 4);
105 && v.size() == 3 && v[0] == -1 && v[1] == 2 && v[2] == 4);
107 && v.size() == 3 && v[0] == -1 && v[1] == 2 && v[2] == 4);
115 std::vector<uint32> v;
125 std::vector<float> v;
127 && v.size() == 3 && v[0] == -1 && v[1] == 2.5 && v[2] == 4);
130 && v.size() == 3 && v[0] == -1 && v[1] == 2 && v[2] == 4);
132 && v.size() == 3 && v[0] == -1 && v[1] == 2.5 && v[2] == 4);
140 std::vector<double> v;
245 d > 0 && d - d != 0);
247 d < 0 && d - d != 0);
332 str =
"a-b xx=yyy foo=bar baz=123 ba=1:2";
337 std::string str_value;
348 std::vector<int32> int_values;
352 KALDI_ASSERT(int_values.size() == 1 && int_values[0] == 123);
354 KALDI_ASSERT(int_values.size() == 2 && int_values[0] == 1 && int_values[1] == 2);
360 str =
"a-b baz=x y z pp = qq ab =cd ac= bd";
365 str =
"a-b baz=x y z pp = qq ab=cd ac=bd";
375 str =
"foo-bar a=b c d f=g";
378 cfl.
GetValue(
"a", &value) && value ==
"b c d" &&
379 cfl.
GetValue(
"f", &value) && value ==
"g" &&
390 str =
"xxx a=b baz ";
400 str =
"xxx baz='x y z' pp=qq ab=cd ac=bd";
402 std::string str_value;
419 str =
"x baz= pp = qq flag=t ";
424 str =
" x baz= pp=qq flag=t ";
427 std::string str_value;
437 bool bool_value =
false;
444 str =
"xx _baz=a -pp=qq";
449 str =
"xx 0baz=a pp=qq";
454 str =
"xx -baz=a pp=qq";
459 str =
"xx _baz'=a pp=qq";
471 str =
"xx _baz1=a pp=qq";
474 std::string str_value;
480 std::string str =
"a-b alpha=aa beta=\"b b\"# String test\n" 481 "a-b beta2='b c' beta3=bd # \n" 482 "a-b gamma=1:2:3:4 # Int Vector test\n" 483 " a-b de1ta=f # Bool + Integer in key Comment test delta=t \n" 484 "a-b _epsilon=-1 # Int Vector test _epsilon=1 \n" 485 "a-b zet-_a=0.15 theta=1.1# Float, -, _ test\n" 486 "a-b quoted='a b c' # quoted string\n" 487 "a-b quoted2=\"d e 'a b=c' f\" # string quoted with double quotes";
489 std::istringstream is(str);
490 std::vector<std::string> lines;
495 for (
size_t i = 0;
i < lines.size();
i++) {
496 KALDI_ASSERT(cfl.ParseLine(lines[
i]) && cfl.FirstToken() ==
"a-b");
498 KALDI_ASSERT(cfl.GetValue(
"beta2", &str) && str ==
"b c");
501 KALDI_ASSERT(cfl.GetValue(
"_epsilon", &str) && str ==
"-1");
508 KALDI_ASSERT(cfl.GetValue(
"quoted", &str) && str ==
"a b c");
511 KALDI_ASSERT(cfl.GetValue(
"quoted2", &str) && str ==
"d e 'a b=c' f");
519 using namespace kaldi;
524 TestConvertStringToReal<float>();
525 TestConvertStringToReal<double>();
537 std::cout <<
"Test OK\n";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
const std::string & FirstToken() const
void UnitTestConfigLineParse()
void TestConvertStringToInteger()
bool ParseLine(const std::string &line)
bool SplitStringToFloats(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< F > *out)
bool IsLine(const std::string &line)
Returns true if "line" is free of characters and unprintable characters, and does not contain leadi...
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
void JoinVectorToString(const std::vector< std::string > &vec_in, const char *delim, bool omit_empty_strings, std::string *str_out)
Joins the elements of a vector of strings into a single string using "delim" as the delimiter...
void TestStringsApproxEqual()
void TestSplitStringToIntegers()
void TestSplitStringOnFirstSpace()
bool IsToken(const std::string &token)
Returns true if "token" is nonempty, and all characters are printable and whitespace-free.
void TestSplitStringToFloats()
std::string UnusedValues() const
returns e.g.
bool StringsApproxEqual(const std::string &a, const std::string &b, int32 decimal_places_tolerance)
This function returns true when two text strings are approximately equal, and false when they are not...
void SplitStringOnFirstSpace(const std::string &str, std::string *first, std::string *rest)
Removes leading and trailing white space from the string, then splits on the first section of whitesp...
void TestConvertStringToReal()
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
void UnitTestReadConfig()
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
void ReadConfigLines(std::istream &is, std::vector< std::string > *lines)
This function reads in a config file and *appends* its contents to a vector of lines; it is responsib...
void Trim(std::string *str)
Removes the beginning and trailing whitespaces from a string.
int Rand(struct RandomState *state)
void TestSplitStringToVector()
This class is responsible for parsing input like hi-there xx=yyy a=b c empty= f-oo=Append(bar, sss) ba_z=123 bing='a b c' baz="a b c d='a b' e" and giving you access to the fields, in this case.
#define KALDI_ASSERT(cond)
bool HasUnusedValues() const
bool GetValue(const std::string &key, std::string *value)
std::string TrimTmp(std::string s)
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).