Commit 37feb3ae authored by 9731050's avatar 9731050

last change

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