32 TEST ( numberconversions, int2string ) {
33 std::string y = ucam::util::toString<unsigned> ( 3 );
38 TEST ( numberconversions, string2int ) {
40 unsigned t = toNumber<unsigned> (
"35" );
43 t = toNumber<unsigned> (
"35ab" );
47 t = toNumber<unsigned> (
"ab" );
53 TEST ( stringutil, countneedles ) {
55 std::string y =
"3_5_7";
61 std::string y4 =
"__3__";
68 std::string input =
" a b c d";
69 std::string reference =
"a b c d";
72 EXPECT_EQ ( output, reference );
77 EXPECT_EQ ( output, reference );
83 std::string input1 =
" a b c d";
84 std::string input2 =
" 1 2 3 4";
85 std::string input3 =
"";
86 std::string input4 =
"1 2 3 4";
87 std::string input5 =
"567";
99 std::vector<float> v1;
100 std::vector<float> v2;
109 v2.push_back ( 1000 );
114 TEST ( stringutil, parseparamstring ) {
116 std::string rule =
"X 35 26 35.2 43.7 86.3";
117 std::vector<float> v = ParseParamString<float> ( rule, 8 );
118 ASSERT_EQ ( v.size(), 3 );
119 EXPECT_EQ ( v[0], 35.2f );
120 EXPECT_EQ ( v[1], 43.7f );
121 EXPECT_EQ ( v[2], 86.3f );
122 std::string rule2 =
"X 35_47 43_55_58 0.45";
123 std::vector<float> v2 = ParseParamString<float> ( rule2, 17 );
124 ASSERT_EQ ( v2.size(), 1 );
125 EXPECT_EQ ( v2[0], 0.45f );
131 std::string f =
"0.370000";
133 EXPECT_EQ (f,
"0.37");
134 std::string f2 =
"30";
136 EXPECT_EQ (f2,
"30");
137 std::string f3 =
"30.00";
139 EXPECT_EQ (f3,
"30");
144 std::string s1 =
"data/rules/trivial.grammar";
146 std::string s3 =
"silly.gz";
147 std::string s4 =
"silly.gz.jopas";
148 EXPECT_EQ (
ends_with (s1,
".gz"),
false);
149 EXPECT_EQ (
ends_with (s2,
".gz"),
false);
151 EXPECT_EQ (
ends_with (s4,
".gz"),
false);
161 int main (
int argc,
char **argv ) {
162 ::testing::InitGoogleTest ( &argc, argv );
163 return RUN_ALL_TESTS();
void trim_spaces(const std::string &input, std::string *output)
Trims spaces at the edges (no spaces) and also between words (only one space)
std::vector< T > ParseParamString(const std::string &stringparams, size_t pos=0)
Function to parse string of parameters, e.g. separated by commas.
void trim_trailing_zeros(std::string &snumber)
Static variables for logger. Include only once from main file.
Convenience functions to parse parameters from a string.
uint count_needles(const std::string &haystack, const char needle, std::size_t start, std::size_t end)
Convenience function that counts the number of times a needle appears.
float dotproduct(std::vector< float > &v1, std::vector< float > &v2)
Implements dot product.
T toNumber(const std::string &x)
Converts a string to an arbitrary number Converts strings to a number. Quits execution if conversion ...
int main(int argc, char **argv)
main function. If compiled individualy, will kickoff any tests in this file.
TEST(numberconversions, int2string)
Test toString<unsigned>
bool ends_with(std::string const &haystack, std::string const &needle)
Unit testing: google testing common header.
Static variable for custom_assert. Include only once from main file.
bool validate_source_sentence(const std::string &s)
Checks whether the sentence is in format ^\d+( \d+)*$.