-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
163 lines (139 loc) · 4.16 KB
/
Copy pathtests.cpp
File metadata and controls
163 lines (139 loc) · 4.16 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "main.cpp"
#include <iostream>
#include <cassert> // For simple test assertions
#include <sstream>
using namespace std;
// Helper Functions for Output
void print_separator()
{
cout << "--------------------------" << endl;
}
// Test Functions
void test_add_student()
{
university_main uni;
cout << "Testing: add_student()" << endl;
uni.add_student();
uni.add_student(); // Should not add duplicate
uni.display_student_details();
print_separator();
}
void test_delete_student()
{
university_main uni;
cout << "Testing: delete_student()" << endl;
uni.add_student();
uni.delete_student();
uni.display_student_details(); // Should print "Not Found"
print_separator();
}
void test_courses_bst()
{
university_main uni;
cout << "Testing: BST add/drop and display()" << endl;
uni.addcourse();
uni.addcourse();
uni.Removecourse(); // Drop Math 101
uni.search_course(102); // Should find Physics 101
uni.search_course(101); // Should print "Course Not Found!"
print_separator();
}
void test_course_add_DLL()
{
university_main uni;
cout << "Testing: Course Enrollment (DLL)" << endl;
uni.add_student();
uni.addcourse();
uni.enroll_course(); // Enroll Alice in Math 101
uni.display_enrollments(); // Should display Math 101
print_separator();
}
void test_sort_students()
{
university_main uni;
cout << "Testing: Sort Students (Linked List)" << endl;
uni.add_student();
uni.add_student();
uni.add_student();
uni.sort_linked_list_by_id(); // Sort students by ID
uni.display_student_details(); // First student should be Alice
print_separator();
}
void test_balance_courses()
{
university_main uni;
cout << "Testing: Balance Courses (BST)" << endl;
uni.addcourse();
uni.addcourse();
uni.addcourse();
uni.balance_courses_bts(); // Balance the BST
print_separator();
}
void test_search_with_hashing()
{
university_main uni;
cout << "Testing: Hash Search" << endl;
uni.addcourse();
uni.searchWithHashing(); // Should find the course
uni.searchWithHashing(); // Should print "Not Found"
print_separator();
}
void test_waitlist()
{
cout << "Testing: Waitlist Operations" << endl;
Course course(301, "Waitlist Test", 3, "Dr. Test", 1, 1); // Limit is 1, already full
Student student(1, "Test Student", "test@student.com");
Course_Waitlist waitlist;
waitlist.enqueue_to_waitlist(&student); // Add to waitlist
waitlist.displayWaitlist(); // Should display the student
waitlist.dequeue_from_waitlist(); // Should remove the student
waitlist.displayWaitlist(); // Should be empty
print_separator();
}
void test_view_enrollment_History()
{
// Create a student and enroll in courses
Student student(1, "Test Student", "test@student.com");
Course course1(1, "Course 1", 3, "Instructor 1", 30, 0);
Course course2(2, "Course 2", 3, "Instructor 2", 30, 0);
Course_enrollment_Node node1(&course1);
Course_enrollment_Node node2(&course2);
student.enrollmentHistory->head = &node1;
node1.next = &node2;
node2.prev = &node1;
// Redirect cout to a stringstream to capture the output
stringstream buffer;
streambuf *old = cout.rdbuf(buffer.rdbuf());
// Call the function
student.enrollmentHistory->view_enrollment_History();
// Restore cout
cout.rdbuf(old);
// Check the output
string expected_output = "Enrollment History:\n- Course 1\n- Course 2\n";
string actual_output = buffer.str();
if (actual_output == expected_output)
{
cout << "Test passed!" << endl;
}
else
{
cout << "Test failed!" << endl;
cout << "Expected output:\n" << expected_output;
cout << "Actual output:\n" << actual_output;
}
}
int main()
{
// test_add_student();
// test_delete_student();
// test_courses_bst();
// test_course_add_DLL();
// test_sort_students();
// test_balance_courses();
// test_search_with_hashing();
// test_waitlist();
//test_view_enrollment_History();
//test_validatePrerequisites();
//test_enroll_course()
return 0;
}