Browse Source

Merge branch 'fdai7921' into 'master'

Fdai7921

See merge request fdai7600/PWN_Alpha_Dogs!7
remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
6b38e3a275
  1. 44
      src/main/java/org/example/Administration.java
  2. 69
      src/test/java/org/example/AdministrationTest.java

44
src/main/java/org/example/Administration.java

@ -11,6 +11,7 @@ public class Administration {
private List<Professor> professors;
private List<Admin> admins;
private List<Student> students;
private List<Course> courses;
Scanner scanner = new Scanner(System.in);
/**
@ -21,9 +22,50 @@ public class Administration {
this.professors = new ArrayList<>();
this.admins = new ArrayList<>();
this.students = new ArrayList<>();
this.courses = new ArrayList<>();
}
/**
* Adds a course to the list of courses.
*
* @param course The course to be added.
*/
public void addCourse(Course course){
courses.add(course);
}
/**
* Deletes a course from the list of courses based on its course ID.
*
* @param courseID The course ID of the course to be deleted.
* @return true if the course is successfully deleted, false otherwise.
*/
public boolean deleteCourse(String courseID){
for(Course course : courses){
if(course.getCourseCode().equals(courseID)){
courses.remove(course);
return true;
}
}
return false;
}
/**
* Finds a course in the list of courses based on its course ID.
*
* @param courseID The course ID of the course to be found.
* @return The course with the specified course ID, or null if not found.
*/
public Course findCourseByID(String courseID){
for(Course course : courses){
if(course.getCourseCode().equals(courseID)){
return course;
}
}
return null;
}
/**
*
* @param professorID the id of the professor you want to be deleted from the system
@ -70,8 +112,6 @@ public class Administration {
}
/**
*
* @param adminID the id of the admin you want to be deleted from the system

69
src/test/java/org/example/AdministrationTest.java

@ -6,15 +6,17 @@ import static org.junit.jupiter.api.Assertions.*;
class AdministrationTest {
Administration admin = new Administration();
private static final Course sampleCourse = new Course("Math", "M101", 4);
// Test the findProfessorById Method
@Test
void findProfessorById() {
Administration administration = new Administration();
Professor prof1 = new Professor("P1001", "Aaron", "Professor");
administration.addProfessor(prof1);
admin.addProfessor(prof1);
Professor foundProf1 = administration.findProfessorById("P1001");
Professor foundProf1 = admin.findProfessorById("P1001");
assertEquals(prof1, foundProf1);
@ -24,7 +26,6 @@ class AdministrationTest {
@Test
void isNumber() {
Administration administration = new Administration();
String full01 = "S1002"; //Supposed student id
// String str1 = full01.substring(1); //String without the Letter
String full02 = "S100Z"; //Supposed student id
@ -33,9 +34,9 @@ class AdministrationTest {
// String str3 = full03.substring(1); //String without the Letter
//checks if the substrings contain only digits
boolean test01 = administration.isNumber(full01);
boolean test02 = administration.isNumber(full02);
boolean test03 = administration.isNumber(full03);
boolean test01 = admin.isNumber(full01);
boolean test02 = admin.isNumber(full02);
boolean test03 = admin.isNumber(full03);
assertEquals(true, test01); //only digits besides the first letter
assertEquals(false, test02); // false, because the Z at the end
@ -45,16 +46,15 @@ class AdministrationTest {
@Test
void rightPrefix() {
Administration administration = new Administration();
String full01 = "S1002"; //Supposed Student id
String full02 = "s100Z"; //Supposed Student id
String full03 = "X1004"; // Supposed Professor id
boolean test01 = administration.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test02 = administration.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test03 = administration.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id
boolean test01 = admin.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test02 = admin.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test03 = admin.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id
assertEquals(true, test01);
assertEquals(false, test02);
@ -63,13 +63,54 @@ class AdministrationTest {
@org.junit.jupiter.api.Test
void findStudentById(){
Administration administration = new Administration();
Student student = new Student("Mark", "S1001", "Student");
administration.addStudents(student);
admin.addStudents(student);
Student student2 = administration.findStudentById("S1001");
Student student2 = admin.findStudentById("S1001");
assertEquals(student, student2);
}
/**
* Test case for the addCourse method.
* Adds a course to the Administration instance and checks if it can be found by its ID.
*/
@Test
void addCourse() {
Course course = sampleCourse;
admin.addCourse(course);
assertEquals(course, admin.findCourseByID("M101"));
}
/**
* Test case for the deleteCourse method.
* Adds a course, deletes it, and checks if it's no longer found.
*/
@Test
public void testDeleteCourse() {
// Adding a course
Course course = sampleCourse;
admin.addCourse(course);
// Deleting the course
assertTrue(admin.deleteCourse("M101"));
// Checking if the course is no longer found
assertNull(admin.findCourseByID("M101"));
}
/**
* Test case for the findCourseByID method.
* Adds a course and checks if it can be found by its ID.
*/
@Test
public void testFindCourseByID() {
// Adding a course
Course course = sampleCourse;
admin.addCourse(course);
// Finding the added course
assertEquals(course, admin.findCourseByID("M101"));
}
}
Loading…
Cancel
Save