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

Function string_test

dlib/test/string.cpp:22–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22 void string_test (
23 )
24 /*!
25 ensures
26 - runs tests on string functions for compliance with the specs
27 !*/
28 {
29
30 print_spinner();
31
32 string a = " davis ";
33 string A = " DAVIS ";
34 string empty = " ";
35
36 dlog << LTRACE << 1;
37
38 double dval;
39 int ival;
40 bool bval;
41
42 DLIB_TEST_MSG(string_cast<int>("5") == 5,string_cast<int>("5"));
43 DLIB_TEST_MSG(string_cast<int>("0x5") == 5,string_cast<int>("0x5"));
44 DLIB_TEST_MSG(string_cast<int>("0xA") == 10,string_cast<int>("0xA"));
45 DLIB_TEST(string_cast<float>("0.5") == 0.5);
46 DLIB_TEST((dval = sa ="0.5") == 0.5);
47 DLIB_TEST(string_cast<std::string>("0.5 !") == "0.5 !");
48 DLIB_TEST(string_cast<bool>("true") == true);
49 DLIB_TEST((bval = sa = "true") == true);
50 DLIB_TEST(string_cast<bool>("false") == false);
51 DLIB_TEST(string_cast<bool>("TRUE") == true);
52 DLIB_TEST(string_cast<bool>("FALSE") == false);
53 DLIB_TEST((bval = sa = "FALSE") == false);
54
55 dlog << LTRACE << 2;
56
57 DLIB_TEST_MSG(string_cast<int>(L"5") == 5,string_cast<int>("5"));
58 DLIB_TEST_MSG((ival = sa = L"5") == 5,string_cast<int>("5"));
59 dlog << LTRACE << 2.1;
60 DLIB_TEST_MSG(string_cast<int>(L"0x5") == 5,string_cast<int>("0x5"));
61 DLIB_TEST_MSG(string_cast<int>(L"0xA") == 10,string_cast<int>("0xA"));
62 DLIB_TEST(string_cast<float>(L"0.5") == 0.5);
63 DLIB_TEST(string_cast<std::string>(L"0.5 !") == "0.5 !");
64 DLIB_TEST(string_cast<bool>(L"true") == true);
65 DLIB_TEST(string_cast<bool>(L"false") == false);
66 DLIB_TEST(string_cast<bool>(L"TRUE") == true);
67 DLIB_TEST((bval = sa = L"TRUE") == true);
68 DLIB_TEST(string_cast<bool>(L"FALSE") == false);
69
70 dlog << LTRACE << 3;
71
72 DLIB_TEST(cast_to_string(5) == "5");
73 DLIB_TEST(cast_to_string(5.5) == "5.5");
74
75 dlog << LTRACE << 4;
76 DLIB_TEST(cast_to_wstring(5) == L"5");
77 DLIB_TEST(cast_to_wstring(5.5) == L"5.5");
78 dlog << LTRACE << 5;
79 DLIB_TEST(toupper(a) == A);

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
cast_to_stringFunction · 0.85
cast_to_wstringFunction · 0.85
toupperFunction · 0.85
tolowerFunction · 0.85
trimFunction · 0.85
ltrimFunction · 0.85
rtrimFunction · 0.85
lpadFunction · 0.85
rpadFunction · 0.85
padFunction · 0.85
left_substrFunction · 0.85

Tested by

no test coverage detected