Commit 37feb3ae authored by 9731050's avatar 9731050

last change

parent ae6d61e4
......@@ -20,6 +20,10 @@ public class Professor {
return this.name;
}
public void setCourses(Course courses){
if(getDepartment().getName().compareTo(courses.getDepartment().getName())==0)
this.courses.add(courses);
}
public ArrayList<Course> getCourses() {
return courses;
}
......
......@@ -3,7 +3,10 @@ package com.university;
import java.util.ArrayList;
public class University {
private ArrayList<Department>departments=new ArrayList<Department>();
private ArrayList<Department>departments;
public University(){
departments=new ArrayList<Department>();
}
public ArrayList<Department> getDepartments(){
return departments;
}
......
......@@ -7,23 +7,35 @@ 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 ProfessorTest {
static Department department;
static Student student;
static Course course;
static Course course,c2,c1;
static Professor professor;
static ArrayList<Course>courses;
@BeforeAll
public static void creatStudent()
{
courses=new ArrayList<>();
department=new Department("abc");
professor=new Professor(department,"kz");
c2=new Course("125","math",new Department("ss"),professor,1);
c1=new Course("124","math",department,professor,1);
course=new Course("123","ap",department,professor,2);
professor.setCourses(c2);
professor.setCourses(course);
professor.setCourses(c1);
for(int i=0;i<professor.getCourses().size();i++)
courses.add(professor.getCourses().get(i));
}
@Test
public void Test(){
assertEquals(department,professor.getDepartment());
assertEquals("kz",professor.getName());
assertEquals(courses,professor.getCourses());
}
}
......@@ -4,6 +4,8 @@ import com.university.*;
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 UniversityTest {
......@@ -12,16 +14,22 @@ public class UniversityTest {
static Course course;
static Professor professor;
static University university;
static ArrayList<Department>departments;
@BeforeAll
public static void creatStudent()
{
departments=new ArrayList<>();
department=new Department("abc");
university=new University();
university.addDepartment(department);
for(int i=0;i<university.getDepartments().size();i++)
departments.add(university.getDepartments().get(i));
}
@Test
public void Test(){
assertEquals(department,university.getDepartments().get(0));
university.removeDepartment(department);
assertEquals(0,university.getDepartments().get(0));
departments.remove(department);
assertEquals(departments,university.getDepartments());
}
}
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