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

Function test_split

dlib/test/string.cpp:190–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189
190 void test_split()
191 {
192 std::vector<string> v;
193
194 string str;
195 string delim = " , ";
196
197 v = split(string("one, two,three four")," ,");
198 DLIB_TEST(v.size() == 4);
199 DLIB_TEST(v[0] == "one");
200 DLIB_TEST(v[1] == "two");
201 DLIB_TEST(v[2] == "three");
202 DLIB_TEST(v[3] == "four");
203
204 v = split(string("one, two,three four"),delim);
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(""));
212 DLIB_TEST(v.size() == 0);
213
214 v = split(string(" "));
215 DLIB_TEST(v.size() == 0);
216
217 v = split(string(" one two "));
218 DLIB_TEST(v.size() == 2);
219 DLIB_TEST(v[0] == "one");
220 DLIB_TEST(v[1] == "two");
221
222 v = split(string(" one "));
223 DLIB_TEST(v.size() == 1);
224 DLIB_TEST(v[0] == "one");
225
226 v = split(string("one"));
227 DLIB_TEST(v.size() == 1);
228 DLIB_TEST(v[0] == "one");
229
230 v = split(string("o"));
231 DLIB_TEST(v.size() == 1);
232 DLIB_TEST(v[0] == "o");
233
234
235 std::vector<wstring> wv;
236 wstring wstr = L"test string";
237 wv = split(wstr);
238 DLIB_TEST(wv.size() == 2);
239 DLIB_TEST(wv[0] == L"test");
240 DLIB_TEST(wv[1] == L"string");
241 wv = split(wstr,L" ");
242 DLIB_TEST(wv.size() == 2);
243 DLIB_TEST(wv[0] == L"test");
244 DLIB_TEST(wv[1] == L"string");
245
246 wstr = L"Über alle Maßen\u00A0Öttingenstraße";
247 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