Skip to content

Commit 9e4da93

Browse files
committed
Completed the test and debugging
1 parent c9e7fcd commit 9e4da93

File tree

6 files changed

+626
-27
lines changed

6 files changed

+626
-27
lines changed

IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ public Course(String instructorName, String courseLocation, String timeSlot, int
3535
* @return true if the student is successfully enrolled, false otherwise.
3636
*/
3737
public boolean enrollStudent() {
38-
enrolledStudentCount++;
39-
return false;
38+
if (enrolledStudentCount < enrollmentCapacity) {
39+
enrolledStudentCount++;
40+
return true;
41+
}
42+
else {
43+
return false;
44+
}
4045
}
4146

4247
/**
@@ -45,8 +50,13 @@ public boolean enrollStudent() {
4550
* @return true if the student is successfully dropped, false otherwise.
4651
*/
4752
public boolean dropStudent() {
48-
enrolledStudentCount--;
49-
return false;
53+
if (enrolledStudentCount > 0) {
54+
enrolledStudentCount--;
55+
return true;
56+
}
57+
else {
58+
return false;
59+
}
5060
}
5161

5262

@@ -92,7 +102,7 @@ public void setEnrolledStudentCount(int count) {
92102

93103

94104
public boolean isCourseFull() {
95-
return enrollmentCapacity < enrolledStudentCount;
105+
return enrollmentCapacity <= enrolledStudentCount;
96106
}
97107

98108
@Serial

IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public ResponseEntity<?> retrieveDepartment(@RequestParam(value = "deptCode") St
4343
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
4444

4545
if (!departmentMapping.containsKey(deptCode.toUpperCase())) {
46-
return new ResponseEntity<>("Department Not Found", HttpStatus.OK);
46+
return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
4747
} else {
48-
return new ResponseEntity<>(departmentMapping.get(deptCode.toUpperCase()).toString(),
49-
HttpStatus.NOT_FOUND);
48+
return new ResponseEntity<>(departmentMapping.get(deptCode.toUpperCase()),
49+
HttpStatus.OK);
5050
}
5151

5252
} catch (Exception e) {
@@ -84,8 +84,8 @@ public ResponseEntity<?> retrieveCourse(
8484
if (!coursesMapping.containsKey(Integer.toString(courseCode))) {
8585
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
8686
} else {
87-
return new ResponseEntity<>(coursesMapping.get(Integer.toString(courseCode)).toString(),
88-
HttpStatus.FORBIDDEN);
87+
return new ResponseEntity<>(coursesMapping.get(Integer.toString(courseCode)),
88+
HttpStatus.OK);
8989
}
9090

9191
}
@@ -124,7 +124,12 @@ public ResponseEntity<?> isCourseFull(
124124
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
125125

126126
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
127-
return new ResponseEntity<>(requestedCourse.isCourseFull(), HttpStatus.OK);
127+
128+
HashMap<String, Boolean> jsonResponseConverter = new HashMap<>();
129+
jsonResponseConverter.put("isFull", requestedCourse.isCourseFull());
130+
131+
return new ResponseEntity<>(jsonResponseConverter, HttpStatus.OK);
132+
128133
} else {
129134
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
130135
}
@@ -151,8 +156,10 @@ public ResponseEntity<?> getMajorCtFromDept(@RequestParam(value = "deptCode") St
151156
if (doesDepartmentExists) {
152157
HashMap<String, Department> departmentMapping;
153158
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
154-
return new ResponseEntity<>("There are: " + -departmentMapping.get(deptCode)
155-
.getNumberOfMajors() + " majors in the department", HttpStatus.OK);
159+
160+
return new ResponseEntity<>("{\"majorCt\": " +
161+
departmentMapping.get(deptCode).getNumberOfMajors() + "}",
162+
HttpStatus.OK);
156163
}
157164
return new ResponseEntity<>("Department Not Found", HttpStatus.FORBIDDEN);
158165
} catch (Exception e) {
@@ -177,8 +184,9 @@ public ResponseEntity<?> identifyDeptChair(@RequestParam(value = "deptCode") Str
177184
if (doesDepartmentExists) {
178185
HashMap<String, Department> departmentMapping;
179186
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
180-
return new ResponseEntity<>(departmentMapping.get(deptCode).getDepartmentChair() + " is "
181-
+ "the department chair.", HttpStatus.OK);
187+
return new ResponseEntity<>("{\"departmentChair\": \"" +
188+
departmentMapping.get(deptCode).getDepartmentChair() + "\"}",
189+
HttpStatus.OK);
182190
}
183191
return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
184192
} catch (Exception e) {
@@ -215,8 +223,8 @@ public ResponseEntity<?> findCourseLocation(
215223
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
216224

217225
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
218-
return new ResponseEntity<>(requestedCourse.getCourseLocation() + " is where the course "
219-
+ "is located.", HttpStatus.OK);
226+
return new ResponseEntity<>("{\"location\": \"" + requestedCourse.getCourseLocation() + "\"}",
227+
HttpStatus.OK);
220228
} else {
221229
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
222230
}
@@ -255,8 +263,11 @@ public ResponseEntity<?> findCourseInstructor(
255263
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
256264

257265
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
258-
return new ResponseEntity<>(requestedCourse.getInstructorName() + " is the instructor for"
259-
+ " the course.", HttpStatus.OK);
266+
HashMap<String, String> response = new HashMap<>();
267+
response.put("instructor", requestedCourse.getInstructorName());
268+
269+
return new ResponseEntity<>(response, HttpStatus.OK);
270+
260271
} else {
261272
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
262273
}
@@ -295,8 +306,10 @@ public ResponseEntity<?> findCourseTime(
295306
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
296307

297308
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
298-
return new ResponseEntity<>("The course meets at: " + "some time ",
299-
HttpStatus.OK);
309+
HashMap<String, String> response = new HashMap<>();
310+
response.put("time", requestedCourse.getCourseTimeSlot());
311+
312+
return new ResponseEntity<>(response, HttpStatus.OK);
300313
} else {
301314
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
302315
}

IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public void setEnrolledStudentCountTest() {
8181

8282
@Test
8383
public void enrollStudentTest() {
84-
testCourse.setEnrolledStudentCount(250);
84+
testCourse.setEnrolledStudentCount(249);
8585
testCourse.enrollStudent();
8686
assertEquals(true, testCourse.isCourseFull());
8787
}
8888

8989
@Test
9090
public void dropStudentTest() {
91-
testCourse.setEnrolledStudentCount(251);
91+
testCourse.setEnrolledStudentCount(250);
9292
testCourse.dropStudent();
9393
assertEquals(false, testCourse.isCourseFull());
9494
}

IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ public void setMappingTest() {
5757

5858
@Test
5959
public void toStringTest() {
60-
System.out.println(testMyFileDatabase.toString());
61-
assertEquals(0, 0);
60+
HashMap<String, Department> currentMapping = testMyFileDatabase.getDepartmentMapping();
61+
62+
Course testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
63+
HashMap<String, Course> testCourses = new HashMap<String, Course>();
64+
testCourses.put("4156", testCourse);
65+
66+
Department testDepartment = new Department("COMS", testCourses, "Griffin Newbold", 2700);
67+
HashMap<String, Department> testDepartmentMapping = new HashMap<String, Department>();
68+
testDepartmentMapping.put("COMS", testDepartment);
69+
70+
testMyFileDatabase.setMapping(testDepartmentMapping);
71+
72+
assertEquals("For the COMS department: \nCOMS 4156: \nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55\n", testMyFileDatabase.toString());
73+
74+
testMyFileDatabase.setMapping(currentMapping);
6275
}
6376

6477
@Test

0 commit comments

Comments
 (0)