MCPcopy Create free account
hub / github.com/davisking/dlib / test_split

Function test_split

dlib/test/string.cpp:197–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197 void test_split()
198 {
199 std::vector<string> v;
200
201 string str;
202 string delim = " , ";
203
204 v = split(string("one, two,three four")," ,");
205 DLIB_TEST(v.size() == 4);
206 DLIB_TEST(v[0] == "one");
207 DLIB_TEST(v[1] == "two");
208 DLIB_TEST(v[2] == "three");
209 DLIB_TEST(v[3] == "four");
210
211 v = split(string("one, two,three four"),delim);
212 DLIB_TEST(v.size() == 4);
213 DLIB_TEST(v[0] == "one");
214 DLIB_TEST(v[1] == "two");
215 DLIB_TEST(v[2] == "three");
216 DLIB_TEST(v[3] == "four");
217
218 v = split(string(""));
219 DLIB_TEST(v.size() == 0);
220
221 v = split(string(" "));
222 DLIB_TEST(v.size() == 0);
223
224 v = split(string(" one two "));
225 DLIB_TEST(v.size() == 2);
226 DLIB_TEST(v[0] == "one");
227 DLIB_TEST(v[1] == "two");
228
229 v = split(string(" one "));
230 DLIB_TEST(v.size() == 1);
231 DLIB_TEST(v[0] == "one");
232
233 v = split(string("one"));
234 DLIB_TEST(v.size() == 1);
235 DLIB_TEST(v[0] == "one");
236
237 v = split(string("o"));
238 DLIB_TEST(v.size() == 1);
239 DLIB_TEST(v[0] == "o");
240
241
242 std::vector<wstring> wv;
243 wstring wstr = L"test string";
244 wv = split(wstr);
245 DLIB_TEST(wv.size() == 2);
246 DLIB_TEST(wv[0] == L"test");
247 DLIB_TEST(wv[1] == L"string");
248 wv = split(wstr,L" ");
249 DLIB_TEST(wv.size() == 2);
250 DLIB_TEST(wv[0] == L"test");
251 DLIB_TEST(wv[1] == L"string");
252
253 wstr = L"Über alle Maßen\u00A0Öttingenstraße";
254 wv = split(wstr, L" \u00A0\n\r\t");

Callers 1

perform_testMethod · 0.85

Calls 4

split_on_firstFunction · 0.85
split_on_lastFunction · 0.85
splitFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected