/** Test of remove method, of class Course. */ @Test public void testRemove_String() { System.out.println("remove"); String id = ""; Course instance = new Course(); instance.remove(id); }
/** Test of add method, of class Course. */ @Test public void testAdd() { System.out.println("add"); Student student = null; Course instance = new Course(); instance.add(student); }
/** Test of remove method, of class Course. */ @Test public void testRemove_Student() { System.out.println("remove"); Student student = null; Course instance = new Course(); instance.remove(student); }
/** Test of getAll method, of class Course. */ @Test public void testGetAll() { System.out.println("getAll"); Course instance = new Course(); List<Student> expResult = null; List<Student> result = instance.getAll(); assertEquals(expResult, result); }
/** Test of getGradeMap method, of class Course. */ @Test public void testGetGradeMap() { System.out.println("getGradeMap"); Course instance = new Course(); Map<String, Set<Student>> expResult = null; Map<String, Set<Student>> result = instance.getGradeMap(); assertEquals(expResult, result); }
@Test public void testEqualsWithCourseObjectShouldReturnTrue() { System.out.println("testEqualsWithCourseObjectShouldReturnTrue"); Object obj = new Course(); Course instance = new Course(); boolean expResult = true; boolean result = instance.equals(obj); assertEquals(expResult, result); }
@Test public void testGetAllWithZeroArgConstructWithAddingValueShouldReturnList() { System.out.println("testGetAllWithZeroArgConstructWithAddingValueShouldReturnList"); List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course instance = new Course(students); String expResult = "[" + students.get(0).toString() + "]"; String result = instance.getAll().toString(); assertEquals(expResult, result); }
@Test public void testEqualsWithCourseObjectWithDifferentListShouldReturnTrue() { System.out.println("testEqualsWithCourseObjectWithDifferentListShouldReturnTrue"); List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course c = new Course(students); Course instance = new Course(); boolean expResult = false; boolean result = instance.equals(c); assertEquals(expResult, result); }
/** Test of get method, of class Course. */ @Test public void testGet_int() { System.out.println("get"); int position = 0; List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course instance = new Course(students); String expResult = "{\"name\":\"sahil\",\"id\":\"c0657966\",\"gender\":\"Male\",\"grade\":80.3}"; String result = instance.get(position).toString(); assertEquals(expResult, result); }
/** Test of insert method, of class Course. */ @Test public void testInsert() { System.out.println("insert"); List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course instance = new Course(students); Student stu = new Student("Toshif", "c0657050", "Male", 60.4); instance.insert(stu, 1); String expResult = "[" + instance.get(0).toString() + ", " + instance.get(1).toString() + "]"; String result = instance.getAll().toString(); assertEquals(expResult, result); }
/** Test of getAllByGender method, of class Course. */ @Test public void testGetAllByGender() { System.out.println("getAllByGender"); String gender = "Male"; List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course instance = new Course(students); Student stu = new Student("Simar", "c0657050", "Female", 60.3); instance.insert(stu, 1); String expResult = "[{\"name\":\"sahil\",\"id\":\"c0657966\",\"gender\":\"Male\",\"grade\":80.3}]"; String result = instance.getAllByGender(gender).toString(); assertEquals(expResult, result); }
@Test public void testGetShouldReturnNullPointer() { try { System.out.println("testGetShouldReturnNullPointer"); List<Student> students = new ArrayList<Student>(); students.add(new Student("sahil", "c0657966", "Male", 80.3)); Course instance = new Course(students); String expResult = null; String result = instance.get("c065796").toString(); assertEquals(expResult, result); } catch (NullPointerException e) { } }
@Test public void testGetAllWithStudentShouldReturnList() { System.out.println("testGetAllWithStudentShouldReturnList"); Course instance = new Course(); Student students = new Student("sahil", "c0657966", "Male", 80.3); Student stu = new Student("Toshif", "c0657050", "Male", 60.4); instance.add(students); instance.add(stu); instance.remove(stu); String expResult = "[" + instance.get(0).toString() + "]"; String result = instance.getAll().toString(); assertEquals(expResult, result); }
@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); }