-
Notifications
You must be signed in to change notification settings - Fork 0
/
DegreeTest.java
164 lines (139 loc) · 6.95 KB
/
DegreeTest.java
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
164
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
import org.junit.*;
/**
* @author Aarsh Patel
*/
public class DegreeTest {
// Test the constructor
@Test
public void testAdminDegreeConstructor() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertTrue(degree.getSubject().equals("Computer Science") &&
degree.getDegreeType().equals("Bachelor of Science") &&
degree.getTotalCreditRequired() == 120 &&
degree.getMajorCourses() != null &&
degree.getElectiveList() != null &&
degree.getID() != null);
}
@Test
public void testJSONReadDegreeConstructor() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Degree degree2 = new Degree(degree.getID(), "Bachelor of Science", "Computer Science", 120, null, null);
assertTrue(degree.equals(degree2));
}
// Test the addMajorCourse method
@Test
public void testaddMajorCourseNull() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.addMajorCourse(null, 3));
}
@Test
public void testaddMajorCourseNegativeSemester() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.addMajorCourse(new Course("Vector Calculus", "MATH", "241", "", 3, null, null), -1));
}
@Test
public void testaddMajorCourseZeroSemester() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.addMajorCourse(new Course("Vector Calculus", "MATH", "241", "", 3, null, null), 0));
}
@Test
public void testaddMajorCourseGreaterThanEightSemester() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.addMajorCourse(new Course("Vector Calculus", "MATH", "241", "", 3, null, null), 9));
}
@Test
public void testaddMajorCourseInBoundsSemester() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertTrue(degree.addMajorCourse(new Course("Vector Calculus", "MATH", "241", "", 3, null, null), 3));
}
// Test the removeMajorCourse method
@Test
public void testremoveMajorCourseNull() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.removeMajorCourse(null));
}
@Test
public void testremoveMajorCourseNotInDegree() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree.removeMajorCourse(new Course("Vector Calculus", "MATH", "241", "", 3, null, null)));
}
@Test
public void testremoveMajorCourseInDegree() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Course course = new Course("Vector Calculus", "MATH", "241", "", 3, null, null);
degree.addMajorCourse(course, 3);
assertTrue(degree.removeMajorCourse(course));
}
@Test
public void testremoveMajorCourseInDegreeMultiple() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Course course1 = new Course("Vector Calculus", "MATH", "241", "", 3, null, null);
Course course2 = new Course("Linear Algebra", "MATH", "242", "", 3, null, null);
degree.addMajorCourse(course1, 3);
degree.addMajorCourse(course2, 3);
assertTrue(degree.removeMajorCourse(course1));
}
@Test
public void testremoveMajorCourseInEmptyDegree() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Course course = new Course("Vector Calculus", "MATH", "241", "", 3, null, null);
assertFalse(degree.removeMajorCourse(course));
}
// Test the equals method
@Test
public void testEqualsSameObject() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertTrue(degree.equals(degree));
}
@Test
public void testEqualsDifferentObjectEquals() {
Degree degree1 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Degree degree2 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertTrue(degree1.equals(degree2));
}
@Test
public void testEqualsDifferentObjectNotEquals() {
Degree degree1 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
Degree degree2 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
degree2.setTotalCreditRequired(121);
assertFalse(degree1.equals(degree2));
}
@Test
public void testEqualsDifferentObjectNull() {
Degree degree1 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree1.equals(null));
}
@Test
public void testEqualsDifferentObjectDifferentType() {
Degree degree1 = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
assertFalse(degree1.equals("Degree"));
}
// Test the toString method
@Test
public void testToStringAllInfoAndEmptyMajorCoursesAndElectiveList() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, new HashMap<Course,Integer>(), new ArrayList<ElectiveCategory>());
String expected = "Degree: Bachelor of Science in Computer Science\nTotal Credit Required: 120\nMajor Courses\n";
assertTrue(degree.toString().contains(expected));
}
@Test
public void testToStringAllInfoAndNullMajorCoursesAndElectiveList() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, null, null);
String expected = "Degree: Bachelor of Science in Computer Science\nTotal Credit Required: 120\nMajor Courses\n";
assertTrue(degree.toString().contains(expected));
}
@Test
public void testToStringAllInfoAndMajorCoursesAndElectiveList() {
Degree degree = new Degree("Bachelor of Science", "Computer Science", 120, new HashMap<Course,Integer>(), new ArrayList<ElectiveCategory>());
Course course = new Course("Vector Calculus", "MATH", "241", "", 3, null, null);
degree.addMajorCourse(course, 3);
ArrayList<ElectiveCategory> electiveList = new ArrayList<ElectiveCategory>();
electiveList.add(new ElectiveCategory("Math Elective", 3, new HashMap<Course, Integer>()));
degree.setElectiveList(electiveList);
String expected = "Degree: Bachelor of Science in Computer Science\nTotal Credit Required: 120\nMajor Courses\n" + course.toString() + "\nElective List\n" + electiveList.get(0).toString() + "\n";
assertTrue(degree.toString().contains(expected));
}
}