Commit d1b11392 authored by Roonak's avatar Roonak

lab6

parents
Pipeline #620 failed with stages
package com.university;
import java.util.ArrayList;
public class Course {
private String ID;
private String name;
private Department department;
private Professor professor;
private int credit ;
ArrayList<Student> students;
public Course(String ID, String name, Department department, Professor professor, int credit) {
this.ID =ID ;
this.name = name ;
this.department = department;
this .professor = professor ;
this.credit = credit ;
students = new ArrayList<Student>();
}
public String getID(){
return ID;
}
public Department getDepartment(){
return department;
}
public String getName() { return name;
}
public Student[] getStudents() {
Student [] student = new Student[students.size()];
for (int i = 0; i < students.size(); i++){
student[i] = students.get(i);
}
return student;
}
public Professor getProfessor() {
return professor;
}
public int getCredit() {
return credit;
}
public void enrollStudent(Student student){
if(student.getDepartment().getName().equals(department.getName()) )
{
students.add(student);
}
}
}
package com.university;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class CourseTest {
static Course course;
static Department department;
static Professor professor;
@BeforeClass
public static void createCourse(){
department = new Department("Computer & IT Engineering");
professor = new Professor(department , "Javadi");
Student student = new Student("Alireza" , "1234" , "SE" , department);
course = new Course("1" , "computer" , department , professor , 10);
course.enrollStudent(student);
}
@Test
public void getCourseDepartmentTest(){
assertNotNull(course.getDepartment());
assertEquals(department , course.getDepartment());
}
@Test
public void getCourseNameTest(){
assertNotNull(course.getName());
assertEquals("computer" , course.getName());
}
@Test
public void courseGetProfessorTest(){
assertNotNull(course.getProfessor());
assertEquals(professor , course.getProfessor());
}
@Test
public void enrollStudentTest(){
assertNotNull(course.getStudents());
assertEquals(1 , course.getStudents().length);
}
@Test
public void notEnrollStudentTest(){
Student[] student = course.getStudents();
for(int i=0 ; i < (course.getStudents().length) ; i++){
assertEquals(student[i].getDepartment().getName() , "Computer & IT Engineering");
}
}
}
package com.university;
import java.util.ArrayList;
public class Department {
private String departmentName;
ArrayList<Student> student;
ArrayList<Course> course;
ArrayList<Professor> professor;
public Department(String name) {
departmentName = name;
student = new ArrayList<>();
course = new ArrayList<>();
professor = new ArrayList<>();
}
public String getName(){
return departmentName;
}
public void addStudent(Student student){
this.student.add(student);
}
public Student[] getStudents(){
Student[] students = new Student[student.size()];
for(int i=0 ; i< (student.size()) ; i++){
students[i] = student.get(i);
}
return students;
}
public void removeStudent(Student student){
this.student.remove(student);
}
public void addCourse(Course course){
this.course.add(course);
}
public Course[] getCourses(){
Course[] courses = new Course[course.size()];
for(int i=0 ; i < (course.size()) ; i++){
courses[i] = course.get(i);
}
return courses;
}
public void removeCourse(Course course){
this.course.remove(course);
}
public void addProfessor(Professor professor){
this.professor.add(professor);
}
public Professor[] getProfessors(){
Professor[] professors = new Professor[professor.size()];
for(int i=0 ; i< (professor.size()) ; i++){
professors[i] = professor.get(i);
}
return professors;
}
public void removeProfessor(Professor professor){
this.professor.remove(professor);
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class DepartmentTest {
static Student student;
static Department department;
static Course course;
static Professor professor;
@BeforeClass
public static void creatDepartment(){
student=new Student("Alireza", "1234", "Software Eng", department);
department = new Department("Computer and IT Eng");
professor=new Professor(department,"Ahmadi");
course=new Course("1","computer",department , professor,10);
}
@Test
public void addStudentTest(){
department.addStudent(student);
assertNotNull(department.getStudents());
}
@Test
public void addCourseTest(){
department.addCourse(course);
assertEquals(department.getCourses().length, 1);
}
@Test
public void addProfessorTest(){
department.addProfessor(professor);
assertEquals (department.getProfessors()[0].getName(),"Ahmadi");
}
}
\ No newline at end of file
package com.university;
import java.util.ArrayList;
public class Professor {
private Department department;
private String name;
private ArrayList<Course> courses = new ArrayList<>();
public Professor(Department department, String name) {
this.department = department;
this.name =name;
}
public Department getDepartment() {
return department;
}
public String getName() {
return name;
}
public Course[] getCourses() {
Course[] courses1 = new Course[courses.size()];
for (int i=0 ; i<courses1.length ; i++)
courses1[i] = courses.get(i);
return courses1;
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class ProfessorTest {
static Department department;
static Course course;
static Professor professor;
@BeforeClass
public static void createProfessor(){
department = new Department("Computer & IT Engineering");
professor = new Professor(department , "Ahmadi");
course = new Course("1" , "Computer" , department , professor , 10);
}
@Test
public void getDepartmentTest(){
department.addProfessor(professor);
assertEquals(professor.getDepartment().getName() , department.getName());
}
}
\ No newline at end of file
package com.university;
import java.util.ArrayList;
public class Student {
private String name;
private String ID;
private String major;
private Department department;
private ArrayList<Course> courses = new ArrayList<>();
public Student(String name, String ID, String major, Department department) {
this.name = name;
this.ID = ID;
this.major = major;
this.department = department;
}
public String getName() {
return name;
}
public String getID() {
return ID;
}
public String getMajor() {
return major;
}
public Department getDepartment() {
return department;
}
public Course[] getCourses() {
Course[] course = new Course[courses.size()];
for (int i=0 ; i<course.length ; i++)
course[i] = courses.get(i);
return course;
}
public void addCourse(Course course){
courses.add(course);
}
}
package test;
import com.university.Department;
import com.university.Student;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class StudnetTest {
static Student student;
static Department department;
@BeforeClass
public static void createStudent(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
}
@Test
public void testStudentGetName(){
assertEquals("Alireza", student.getName());
}
@Test
public void testStudenGetCourses(){
assertNotNull(student.getCourses());
assertEquals(0, student.getCourses().length);
}
}
\ No newline at end of file
package com.university;
import org.junit.Test;
import java.util.ArrayList;
public class University {
ArrayList<Department> departments = new ArrayList<>();
public Department[] getDepartments(){
Department[] department = new Department[departments.size()];
for (int i=0 ; i<department.length ; i++)
department[i] = departments.get(i);
return department;
}
public void addDepartment(Department department){
departments.add(department);
}
public void removeDepartment(Department department){
departments.remove(department);
}
}
package test;
import com.university.Department;
import com.university.University;
import org.junit.BeforeClass;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class UniversityTest {
static Department department , department1;
static University university;
@BeforeClass
public static void createUni(){
department = new Department("Computer and IT Eng");
university = new University();
department1 = new Department("Math");
}
@Test
public void getDepartmentsTest(){
university.addDepartment(department1);
university.addDepartment(department);
assertEquals (university.getDepartments()[1].getName() , department.getName());
}
@Test
public void removeDepartmentTest(){
university.removeDepartment(department1);
assertEquals(university.getDepartments().length, 1);
}
}
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