Commit f797438b authored by amsen's avatar amsen

Initial commit

parents
Pipeline #458 failed with stages
package com.university;
import java.util.*;
public class Course {
private String ID;
private String name;
private int credit;
private Department department;
private Professor professor;
private ArrayList<Student> students = new ArrayList<>();
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;
}
public String getID(){
return ID;
}
public Department getDepartment(){
return department;
}
public String getName() {
return name;
}
public Student[] getStudents() {
Student[] arr = new Student[students.size()];
return students.toArray(arr);
}
public Professor getProfessor() {
return professor;
}
public int getCredit() {
return credit;
}
public void enrollStudent(Student student){
if(student.getDepartment() == department)
students.add(student);
}
}
package com.university;
import java.util.*;
public class Department {
private String name;
private ArrayList<Student> students;
private ArrayList<Course> courses;
private ArrayList<Professor> professors;
public Department(String name) {
this.name = name;
students = new ArrayList<>();
courses = new ArrayList<>();
professors = new ArrayList<>();
}
public String getName(){
return name;
}
public void addStudent(Student student){
if(student.getDepartment() == this)
students.add(student);
}
public Student[] getStudents(){
Student[] arr = new Student[students.size()];
return students.toArray(arr);
}
public void removeStudent(Student student){
students.remove(student);
}
public void addCourse(Course course){
if(course.getDepartment() == this)
courses.add(course);
}
public Course[] getCourses(){
Course[] arr = new Course[courses.size()];
return courses.toArray(arr);
}
public void removeCourse(Course course){
courses.remove(course);
}
public void addProfessor(Professor professor){
if(professor.getDepartment() == this)
professors.add(professor);
}
public Professor[] getProfessors(){
Professor[] arr = new Professor[professors.size()];
return professors.toArray(arr);
}
public void removeProfessor(Professor professor){
professors.remove(professor);
}
}
package com.university;
import java.util.*;
public class Professor {
private Department department;
private String name;
private Course tmp;
public Professor(Department department, String name) {
this.department = department;
this.name = name;
tmp = new Course("1", "salam", department, null, 0);
}
public Department getDepartment() {
return department;
}
public String getName() {
return name;
}
public Course[] getCourses() {
Course[] arr = new Course[1];
arr[0] = tmp;
return arr;
}
}
package com.university;
import java.util.*;
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 [] arr = new Course[courses.size()];
return courses.toArray(arr);
}
public void addCourse(Course course){
if(course != null)
courses.add(course);
}
public void clearCourses(){
courses.clear();
}
}
package com.university;
import java.util.*;
public class University {
private ArrayList<Department> departments = new ArrayList<>();
public Department[] getDepartments(){
Department[] arr = new Department[departments.size()];
return departments.toArray(arr);
}
public void addDepartment(Department department){
departments.add(department);
}
public void removeDepartment(Department department){
departments.remove(department);
}
}
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.*;
class CourseTest {
static Course course;
static Department department;
static Professor professor;
@BeforeAll
public static void createCourseTest(){
department = new Department("salam");
professor = new Professor(department, "hajit");
course = new Course("12", "man", department, professor, 0);
}
@Test
void getID() {
assertEquals(course.getID(), "12");
}
@Test
void getDepartment() {
assertEquals(course.getDepartment(), department);
}
@Test
void getName() {
assertEquals(course.getName(), "man");
}
@Test
void getStudents() {
assertNotEquals(null, course.getStudents());
}
@Test
void getProfessor() {
assertEquals(course.getProfessor(), professor);
}
@Test
void enrollStudent() {
Student shouldadd = new Student("A", "B", "C", department);
Student shouldnotadd = new Student("A", "B", "C", null);
course.enrollStudent(shouldadd);
course.enrollStudent(shouldnotadd);
assertEquals(1, course.getStudents().length);
assertEquals(course.getStudents()[0], shouldadd);
}
}
\ No newline at end of file
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class DepartmentTest {
static Department department;
@BeforeAll
public static void createDepartment() {
department = new Department("salam");
}
@Test
void getName() {
assertEquals("salam", department.getName());
}
@Test
void addStudent() {
Student student = new Student("A", "B", "C", department);
Student notstudent = new Student("A", "B", "C", null);
department.addStudent(student);
department.addStudent(notstudent);
assertEquals(1, department.getStudents().length);
assertEquals(department.getStudents()[0], student);
}
@Test
void getStudents() {
assertNotEquals(null, department.getStudents());
}
@Test
void removeStudent() {
Student student = new Student("A", "B", "C", department);
int len = department.getStudents().length;
department.removeStudent(student);
assertEquals(len, department.getStudents().length);
department.addStudent(student);
department.removeStudent(department.getStudents()[0]);
assertEquals(len, department.getStudents().length);
}
@Test
void addCourse() {
Course course = new Course("12", "12", department, null, 0);
Course notcourse = new Course("12", "12", null, null, 0);
department.addCourse(course);
department.addCourse(notcourse);
assertEquals(1, department.getCourses().length);
assertEquals(department.getCourses()[0], course);
}
@Test
void getCourses() {
assertNotEquals(department.getCourses()[0], null);
}
@Test
void removeCourse() {
Course course = new Course("12", "12", department, null, 0);
int len = department.getCourses().length;
department.removeCourse(course);
assertEquals(len, department.getCourses().length);
department.addCourse(course);
department.removeCourse(department.getCourses()[0]);
assertEquals(len, department.getCourses().length);
}
@Test
void addProfessor() {
Professor professor = new Professor(department, "A");
Professor notprofessor = new Professor(null, "A");
department.addProfessor(professor);
department.addProfessor(notprofessor);
assertEquals(1, department.getProfessors().length);
assertEquals(department.getProfessors()[0], professor);
}
@Test
void getProfessors() {
assertNotEquals(null, department.getProfessors());
}
@Test
void removeProfessor() {
Professor professor = new Professor(department, "A");
int len = department.getProfessors().length;
department.removeProfessor(professor);
assertEquals(len, department.getProfessors().length);
department.removeProfessor(department.getProfessors()[0]);
assertEquals(len-1, department.getProfessors().length);
}
}
\ No newline at end of file
package test;
import com.university.Department;
import com.university.Professor;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
class ProfessorTest {
static Professor professor;
static Department department;
@BeforeAll
static void setUp() {
department = new Department("salam");
professor = new Professor(department, "salam");
}
@Test
void getDepartment() {
assertEquals(professor.getDepartment(), department);
}
@Test
void getName() {
assertEquals(professor.getName(), "salam");
}
@Test
void getCourses() {
assertNotEquals(null, professor.getCourses());
}
}
\ No newline at end of file
package test;
import com.university.Course;
import com.university.Department;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class StudnetTest {
static Student student;
static Department department;
@BeforeAll
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);
}
@Test
public void testGetDepartment(){
assertEquals(department, student.getDepartment());
}
@Test
public void testGetMajor(){
assertEquals(student.getMajor(), "Software Eng");
}
@Test
public void testAddCourse(){
Course course = new Course("1", "1", department, null, 0);
student.addCourse(course);
assertEquals(student.getCourses()[0], course);
student.clearCourses();
}
}
package test;
import com.university.Department;
import com.university.University;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class UniversityTest {
static University university = new University();
@Test
void getDepartments() {
assertNotEquals(null, university.getDepartments());
}
@Test
void addDepartment() {
Department department = new Department("salam");
university.addDepartment(department);
assertEquals(1, university.getDepartments().length);
}
@Test
void removeDepartment() {
Department department = new Department("salam");
int len = university.getDepartments().length;
university.addDepartment(department);
university.removeDepartment(department);
assertEquals(len, university.getDepartments().length);
}
}
\ No newline at end of file
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