1 /*******************************************************
2 * Unit test for the String class
4 * test basic string operations
5 ******************************************************
14 // Default contructor: empty string
17 std::cout << "The default contructor makes an empty string: \"" << s0 << "\"\n";
20 // The length of a string with the ~ operator
24 // check boolean opareations that check for empty strings
28 std::cout << "\"" << s0 << "\" is not empty.\n";
32 std::cout << "\"" << s0 << "\" is empty.\n";
36 std::cout << "\"" << s0 << "\" is empty.\n";
40 std::cout << "\"" << s0 << "\" is not empty.\n";
45 std::cout << "\"" << s1 << "\" is not empty.\n";
49 std::cout << "\"" << s1 << "\" is empty.\n";
53 std::cout << "\"" << s1 << "\" is empty.\n";
57 std::cout << "\"" << s1 << "\" is not empty.\n";
61 std::cout << "The length of \"" << s1 << "\" is " << length << "\n";
64 // test character access, also outside boundaries (e.g. -1, 666)
68 std::cout << "First character of " << s1 << " '" << c << "'\n";
71 std::cout << "Fourth character of " << s1 << " '" << c << "'\n";
78 std::cout << "Seventh character of " << s1 << " char(" << (int)c << ")\n";
80 catch (StringException se)
82 std::cout << "String exception: " << se.what() << "\n";
87 std::cout << "After \"abcde\"[2] = 'Z' : " << s1 << "\n";
88 assert(s1 == "abZde");
94 catch (StringException se)
96 std::cout << "String exception: " << se.what() << "\n";
98 std::cout << "After \"abcde\"[5] = 'X' : " << s1 << "\n";
99 assert(s1 == "abZde");