@Test public void testAddMajor() { assertTrue(controller.addStudent("testAddMajor")); Iterator i = controller.getStudents().iterator(); Student s = null; while (i.hasNext()) s = (Student) i.next(); assertNotNull(s); assertTrue(controller.setMajor(s, new Major())); assertTrue(s.getMajor().getId() == 0); }
@Test public void test() throws Exception { // Create Course instances and add to ArrayList Course c1 = new Course(UUID.randomUUID(), "Chemistry", 4, eMajor.CHEM); Course c2 = new Course(UUID.randomUUID(), "Math", 4, eMajor.BUSINESS); Course c3 = new Course(UUID.randomUUID(), "Computer Science", 4, eMajor.COMPSI); ArrayList<Course> courses = new ArrayList<Course>(); courses.add(c1); courses.add(c2); courses.add(c3); // Create Semester instances and add to ArrayList Semester fall = new Semester(UUID.randomUUID(), new Date(), new Date()); Semester spring = new Semester(UUID.randomUUID(), new Date(), new Date()); ArrayList<Semester> semesters = new ArrayList<Semester>(); semesters.add(fall); semesters.add(spring); // Create Section instances and add to ArrayList UUID secID1 = UUID.randomUUID(); UUID secID2 = UUID.randomUUID(); UUID secID3 = UUID.randomUUID(); UUID secID4 = UUID.randomUUID(); UUID secID5 = UUID.randomUUID(); UUID secID6 = UUID.randomUUID(); Section falls1 = new Section(c1.getCourseID(), fall.getSemesterID(), secID1, 200); Section falls2 = new Section(c2.getCourseID(), fall.getSemesterID(), secID2, 200); Section falls3 = new Section(c3.getCourseID(), fall.getSemesterID(), secID3, 200); Section spring1 = new Section(c1.getCourseID(), spring.getSemesterID(), secID4, 200); Section spring2 = new Section(c2.getCourseID(), spring.getSemesterID(), secID5, 200); Section spring3 = new Section(c3.getCourseID(), spring.getSemesterID(), secID6, 200); ArrayList<Section> sections = new ArrayList<Section>(); sections.add(falls1); sections.add(falls2); sections.add(falls3); sections.add(spring1); sections.add(spring2); sections.add(spring3); // Create Student instances and add to ArrayList Student s1 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s2 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s3 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s4 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s5 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s6 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s7 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s8 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s9 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); Student s10 = new Student( "Bob", "Ex", "Example", new Date(), eMajor.BUSINESS, "10 Example Street", "(302)-444-5555", "*****@*****.**", UUID.randomUUID()); ArrayList<Student> students = new ArrayList<Student>(); students.add(s1); students.add(s2); students.add(s3); students.add(s4); students.add(s5); students.add(s6); students.add(s7); students.add(s8); students.add(s9); students.add(s10); // Create ArrayList for Enrollment instances ArrayList<Enrollment> enrollments = new ArrayList<Enrollment>(); // Create the 60 instances of Enrollment for (Student stu : students) { for (Section sec : sections) { enrollments.add(new Enrollment(stu.getStudentID(), sec.getSectionID())); } } // Set all the grades for (Enrollment en : enrollments) { en.setGrade(4); } // Calculate GPAs double gpa1 = 0; double gpa2 = 0; double gpa3 = 0; double gpa4 = 0; double gpa5 = 0; double gpa6 = 0; double gpa7 = 0; double gpa8 = 0; double gpa9 = 0; double gpa10 = 0; double sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s1.getStudentID()) { sum += en.getGrade(); } gpa1 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s2.getStudentID()) { sum += en.getGrade(); } gpa2 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s3.getStudentID()) { sum += en.getGrade(); } gpa3 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s4.getStudentID()) { sum += en.getGrade(); } gpa4 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s5.getStudentID()) { sum += en.getGrade(); } gpa5 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s6.getStudentID()) { sum += en.getGrade(); } gpa6 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s7.getStudentID()) { sum += en.getGrade(); } gpa7 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s8.getStudentID()) { sum += en.getGrade(); } gpa8 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s9.getStudentID()) { sum += en.getGrade(); } gpa9 = sum / 6; } sum = 0; for (Enrollment en : enrollments) { if (en.getStudentID() == s10.getStudentID()) { sum += en.getGrade(); } gpa10 = sum / 6; } // Test if the GPAs were correctly calculated assertTrue(gpa1 == 4); assertTrue(gpa2 == 4); assertTrue(gpa3 == 4); assertTrue(gpa4 == 4); assertTrue(gpa5 == 4); assertTrue(gpa6 == 4); assertTrue(gpa7 == 4); assertTrue(gpa8 == 4); assertTrue(gpa9 == 4); assertTrue(gpa10 == 4); // Calculate average course grades double ave1 = 0; double ave2 = 0; double ave3 = 0; sum = 0; for (Enrollment en : enrollments) { if (en.getSectionID() == secID1 || en.getStudentID() == secID4) { sum += en.getGrade(); } ave1 = sum / 10; } sum = 0; for (Enrollment en : enrollments) { if (en.getSectionID() == secID2 || en.getStudentID() == secID5) { sum += en.getGrade(); } ave2 = sum / 10; } sum = 0; for (Enrollment en : enrollments) { if (en.getSectionID() == secID3 || en.getStudentID() == secID6) { sum += en.getGrade(); } ave3 = sum / 10; } // Test if course averages were correctly calculated assertTrue(ave1 == 4); assertTrue(ave2 == 4); assertTrue(ave3 == 4); // Attempt to change a student's major s1.setMajor(eMajor.CHEM); assertTrue(s1.getMajor() == eMajor.CHEM); }