Commit 1ab10fd8 authored by 9731050's avatar 9731050

2th

parent 9b541e20
......@@ -43,6 +43,7 @@ private ArrayList<Student>students;
}
public void enrollStudent(Student student){
if(student.getDepartment().getName().compareTo(getDepartment().getName())==0)
students.add(student);
}
......
......@@ -7,6 +7,7 @@ public class Department {
private ArrayList<Student>students;
private ArrayList<Course>courses;
private ArrayList<Professor>professors;
public Department(String name) {
this.name=name;
students=new ArrayList<Student>();
......@@ -18,6 +19,7 @@ public class Department {
}
public void addStudent(Student student){
if(getName().compareTo(student.getDepartment().getName())==0)
students.add(student);
}
......@@ -26,10 +28,12 @@ public class Department {
}
public void removeStudent(Student student){
if(student.getDepartment().getName().compareTo(getName())==0)
students.remove(student);
}
public void addCourse(Course course){
if(getName().compareTo(course.getDepartment().getName())==0)
courses.add(course);
}
......@@ -38,10 +42,12 @@ public class Department {
}
public void removeCourse(Course course){
if(getName().compareTo(course.getDepartment().getName())==0)
courses.remove(course);
}
public void addProfessor(Professor professor){
if(getName().compareTo(professor.getDepartment().getName())==0)
professors.add(professor);
}
......@@ -50,6 +56,7 @@ public class Department {
}
public void removeProfessor(Professor professor){
if(getName().compareTo(professor.getDepartment().getName())==0)
professors.remove(professor);
}
......
......@@ -7,28 +7,38 @@ import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CourseTest {
static Department department;
static Student student;
static Student student,s2;
static Course course;
static Professor professor;
static ArrayList<Student>students;
@BeforeAll
public static void creatStudent()
{
students=new ArrayList<>();
department=new Department("abc");
professor=new Professor(department,"kz");
course=new Course("123","math",department,professor,3);
student=new Student("ali","1234","abc",department);
s2=new Student("mohammad","1235","b",new Department("abd"));
course.enrollStudent(s2);
course.enrollStudent(student);
for(int i=0;i<course.getStudents().size();i++)
students.add(course.getStudents().get(i));
}
@Test
public void Test(){
assertEquals("math",course.getName());
assertEquals("123",course.getID());
assertEquals(department,course.getDepartment());
assertEquals(professor,course.getProfessor());
assertEquals(3,course.getCredit());
assertEquals(students,course.getStudents());
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DepartmentTest {
static Department department;
static Student student;
static Course course;
static Professor professor;
@BeforeAll
public static void creatStudent()
{
department=new Department("abc");
professor=new Professor(department,"kz");
course=new Course("123","math",department,professor,3);
student=new Student("ali","1234","abc",department);
department.addCourse(course);
department.addProfessor(professor);
department.addStudent(student);
}
@Test
public void Test(){
assertEquals("abc",department.getName());
assertEquals(professor,department.getProfessors().get(0));
assertEquals(course,department.getCourses().get(0));
assertEquals(student,department.getStudents().get(0));
department.removeCourse(course);
department.removeProfessor(professor);
department.removeStudent(student);
assertEquals(0,department.getProfessors().get(0));
assertEquals(0,department.getCourses().get(0));
assertEquals(0,department.getStudents().get(0));
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ProfessorTest {
static Department department;
static Student student;
static Course course;
static Professor professor;
@BeforeAll
public static void creatStudent()
{
department=new Department("abc");
professor=new Professor(department,"kz");
}
@Test
public void Test(){
assertEquals(department,professor.getDepartment());
assertEquals("kz",professor.getName());
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
class StudentTest {
static Department department;
static Student student;
static Course course,c;
static Professor professor;
static ArrayList<Course>courses;
@BeforeAll
public static void creatStudent()
{
courses=new ArrayList<>();
department=new Department("abc");
professor=new Professor(department,"kz");
student=new Student("ali","1234","aaa",department);
course=new Course("123","math",department,professor,3);
c=new Course("12","Mohammad",department,professor,2);
student.addCourse(course);
courses.add(course);
student.addCourse(c);
courses.add(c);
}
@Test
public void Test(){
assertEquals("ali",student.getName());
assertEquals("1234",student.getID());
assertEquals("aaa",student.getMajor());
assertEquals(department,student.getDepartment());
assertEquals(courses,student.getCourses());
}
}
\ No newline at end of file
package test;
public class UnivercityTest {
import com.university.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class UniversityTest {
static Department department;
static Student student;
static Course course;
static Professor professor;
static University university;
@BeforeAll
public static void creatStudent()
{
department=new Department("abc");
university.addDepartment(department);
}
@Test
public void Test(){
assertEquals(department,university.getDepartments().get(0));
university.removeDepartment(department);
assertEquals(0,university.getDepartments().get(0));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment