-
Notifications
You must be signed in to change notification settings - Fork 0
/
customstring_test.cpp
50 lines (42 loc) · 1.02 KB
/
customstring_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cassert>
#include "customstring.h"
void testDefaultConstructor() {
customstring str;
assert(str.size() == 0);
assert(str.c_str() == nullptr);
}
void testCharConstructor() {
customstring str("Hello");
assert(str.size() == 5);
assert(std::strcmp(str.c_str(), "Hello") == 0);
}
void testCopyConstructor() {
customstring str1("Hello");
customstring str2 = str1;
assert(str2.size() == str1.size());
assert(std::strcmp(str2.c_str(), str1.c_str()) == 0);
}
void testAssignmentOperator() {
customstring str1 = "Hello";
customstring str2;
str2 = str1;
assert(str2 == "Hello");
}
void testLength() {
customstring str = "Hello";
assert(str.size() == 5);
}
void testSubstring() {
customstring str = "Hello";
assert(str.substr(1, 3) == "ell");
}
int main() {
testDefaultConstructor();
testCharConstructor();
testCopyConstructor();
testAssignmentOperator();
testLength();
testSubstring();
std::cout << "All tests passed!\n";
return 0;
}