Skip to content

Commit 2631d13

Browse files
Update README.md
1 parent ec39ea0 commit 2631d13

1 file changed

Lines changed: 106 additions & 9 deletions

File tree

README.md

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,114 @@ friend bool my_strstr(const String&, const String&);
112112

113113
📌 Note: `'a' += s1` is invalid due to immutability of literals.
114114

115-
## 🧪 Sample Test Cases
115+
## 🧪 Performed Test Cases
116116

117117
Demonstrated in `main.cpp`:
118-
119-
* Construction, copy, move semantics
120-
* String mutation using `[]` operator
121-
* All concatenation variations
122-
* Comparison logic
123-
* Stream input/output
124-
* Iterator usage
125-
* length synchronization across all instances
118+
```cpp
119+
/*** main.cpp ***/
120+
int main() {
121+
122+
String s1("vector india");
123+
s1[0] = 's';
124+
cout << "s1 = ";
125+
s1.getstr();
126+
127+
cout<<"-------------------------------------------"<<endl;
128+
String s2 = "bangalore";
129+
cout<<"s2 = "<<s2<<endl;
130+
cout << "Length of s2 = " << s2.len() << endl;
131+
132+
// Concatenation: Case 1
133+
cout<<"-------------------------------------------"<<endl;
134+
String s3;
135+
s3 = s1 + s2;
136+
cout<<"s1 = "<<s1<<", s2 = "<<s2<<endl;
137+
cout << "s3 = s1+s2 => ";
138+
s3.getstr();
139+
140+
// Case 2
141+
cout<<"-------------------------------------------"<<endl;
142+
cout<<"s3 = "<<s3<<", s1 = "<<s1<<endl;
143+
s3 += s1;
144+
cout << "s3 += s1 => " << s3 << endl;
145+
146+
// Case 3
147+
cout<<"-------------------------------------------"<<endl;
148+
cout << "s1 = " << s1 << endl;
149+
s3 = s1 + "vector";
150+
cout<<" s3 = s1 + \"vector\" => "<<s3<<endl;
151+
152+
// Case 4:
153+
cout<<"-------------------------------------------"<<endl;
154+
cout<<"s1 = "<<s1<<endl;
155+
s3 = "vector" + s1;
156+
cout << "s3 = \"vector\" + s1 => " << s3 << endl;
157+
158+
// Case 5
159+
cout<<"-------------------------------------------"<<endl;
160+
cout<<"s3 = "<<s3<<endl;
161+
cout << "s3 += \"Vector\" => ";
162+
s3 += "Vector";
163+
cout <<s3 << endl;
164+
165+
// Case 6
166+
cout<<"-------------------------------------------"<<endl;
167+
cout<<"s1 = "<<s1<<endl;
168+
s3 = s1 + 'x';
169+
cout << "s3 = s1 + 'x' => " << s3 << endl;
170+
171+
// Case 7
172+
cout<<"-------------------------------------------"<<endl;
173+
cout<<"s1 = "<<s1<<endl;
174+
s3 = 'x' + s1;
175+
cout << "'x' + s1 = " << s3 << endl;
176+
177+
// Case 8
178+
cout<<"-------------------------------------------"<<endl;
179+
cout<<"s3 = "<<s3<<endl;
180+
s3 += 'x';
181+
cout << "s3 += 'x' = " << s3 << endl;
182+
cout << "Length of s3 = " << s3.len() << endl;
183+
184+
// [] and << overload
185+
cout<<"-------------------------------------------"<<endl;
186+
cout << "Characters of s3: ";
187+
for (int i = 0; i < s3.len(); i++) {
188+
cout << s3[i] << " ";
189+
}
190+
cout << endl;
191+
192+
// >> overload and chaining support
193+
cout<<"-------------------------------------------"<<endl;
194+
String s4, s5;
195+
cout << "Enter two strings (s4 and s5): ";
196+
cin >> s4 >> s5;
197+
198+
cout << "S4: " << s4 << endl;
199+
cout << "Length of s4 = " << s4.len() << endl;
200+
201+
cout<<"-------------------------------------------"<<endl;
202+
cout << "s5 = ";
203+
s5.getstr();
204+
cout << "Length of s5 = " << s5.len() << endl;
205+
cout<<"--------------------------------------------"<<endl;
206+
207+
// comparison operator
208+
cout<<"*********** String Comparision *************"<<endl;
209+
cout<<"--------------------------------------------"<<endl;
210+
cout<<"s4 = "<<s4<<endl;
211+
cout<<"s5 = "<<s5<<endl;
212+
cout<<"s4 > s5 => "<< (s4>s5) << endl;
213+
cout<<"s4 >= s5 => "<< (s4>=s5) << endl;
214+
cout<<"s4 < s5 => "<< (s4<s5) << endl;
215+
cout<<"s4 <= s5 => "<< (s4<=s5) << endl;
216+
cout<<"s4 == s5 => "<< (s4==s5) << endl;
217+
cout<<"s4 != s5 => "<< (s4!=s5) << endl;
218+
cout<<"--------------------------------------------"<<endl;
219+
220+
return 0;
221+
}
222+
```
126223

127224
## 🛠️ Technologies Used
128225

0 commit comments

Comments
 (0)