-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicArrayClassTest.cpp
More file actions
140 lines (104 loc) · 4.04 KB
/
Copy pathDynamicArrayClassTest.cpp
File metadata and controls
140 lines (104 loc) · 4.04 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "clsDynamicArray.h"
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout << "==================================================\n";
cout << " TESTING CLSDYNAMICARRAY IMPLEMENTATION \n";
cout << "==================================================\n\n";
// 1. Creation & Initial Setup
cout << "[1] Creating Dynamic Array with size 5...\n";
clsDynamicArray<int> MyArray(5);
cout << "Is Empty? " << (MyArray.IsEmpty() ? "Yes" : "No") << "\n";
cout << "Current Size: " << MyArray.Size() << "\n";
// Filling Array with SetItem
for (size_t i = 0; i < MyArray.Size(); i++)
{
MyArray.SetItem(i, (i + 1) * 10);
}
cout << "Array Items: ";
cout << "\n"; MyArray.PrintList();
cout << "\n--------------------------------------------------\n";
// 2. Testing Accessors (GetItem, Find)
cout << "[2] Testing GetItem & Find...\n";
cout << "Item at index 2: " << MyArray.GetItem(2) << "\n";
cout << "Item at out-of-bounds index 10: " << MyArray.GetItem(10) << " (Returns default value T())\n";
int searchVal = 30;
int index = MyArray.Find(searchVal);
if (index != -1)
cout << "Value " << searchVal << " found at index: " << index << "\n";
else
cout << "Value " << searchVal << " not found!\n";
cout << "\n--------------------------------------------------\n";
// 3. Testing Insert Methods
cout << "[3] Testing Insertion Methods...\n";
MyArray.InsertAtBeginning(5);
cout << "After InsertAtBeginning(5): ";
cout << "\n";
cout << "\n"; MyArray.PrintList();
MyArray.InsertAtEnd(60);
cout << "After InsertAtEnd(60): ";
cout << "\n"; MyArray.PrintList();
MyArray.InsertAt(3, 25);
cout << "After InsertAt(index 3, value 25): ";
cout << "\n"; MyArray.PrintList();
MyArray.InsertBefore(2, 15);
cout << "After InsertBefore(index 2, value 15): ";
cout << "\n"; MyArray.PrintList();
MyArray.InsertAfter(4, 35);
cout << "After InsertAfter(index 4, value 35): ";
cout << "\n"; MyArray.PrintList();
cout << "Current Size: " << MyArray.Size() << "\n";
cout << "\n--------------------------------------------------\n";
// 4. Testing Reverse
cout << "[4] Testing Reverse...\n";
MyArray.Reverse();
cout << "Array after Reverse(): ";
cout << "\n"; MyArray.PrintList();
cout << "\n--------------------------------------------------\n";
// 5. Testing Delete Methods
cout << "[5] Testing Deletion Methods...\n";
MyArray.DeleteFirstItem();
cout << "After DeleteFirstItem(): ";
cout << "\n"; MyArray.PrintList();
MyArray.DeleteLastItem();
cout << "After DeleteLastItem(): ";
cout << "\n"; MyArray.PrintList();
MyArray.DeleteItemAt(2);
cout << "After DeleteItemAt(index 2): ";
cout << "\n"; MyArray.PrintList();
MyArray.DeleteItem(25);
cout << "After DeleteItem(value 25): ";
cout << "\n"; MyArray.PrintList();
cout << "Current Size: " << MyArray.Size() << "\n";
cout << "\n--------------------------------------------------\n";
// 6. Testing Resize
cout << "[6] Testing Resize...\n";
MyArray.Resize(10);
cout << "After Resize(10): ";
cout << "\n"; MyArray.PrintList();
cout << "New Size: " << MyArray.Size() << "\n";
MyArray.Resize(3);
cout << "After Resize(3) [Truncating]: ";
cout << "\n"; MyArray.PrintList();
cout << "New Size: " << MyArray.Size() << "\n";
cout << "\n--------------------------------------------------\n";
// 7. Testing Clear & Edge Cases
cout << "[7] Testing Clear & Edge Cases...\n";
MyArray.Clear();
cout << "After Clear():\n";
cout << "Is Empty? " << (MyArray.IsEmpty() ? "Yes" : "No") << "\n";
cout << "Size: " << MyArray.Size() << "\n";
// Trying operations on empty array
cout << "Trying to DeleteItem from empty array: " << (MyArray.DeleteItem(10) ? "Success" : "Failed (Safe)") << "\n";
// Re-inserting into cleared array
MyArray.InsertAtEnd(100);
cout << "After InsertAtEnd(100) on cleared array: ";
cout << "\n"; MyArray.PrintList();
cout << "\n==================================================\n";
cout << " ALL TESTS COMPLETED SUCCESSFULLY \n";
cout << "==================================================\n";
system("pause>0");
return 0;
}