Commit d959a36c authored by 9731001's avatar 9731001

lab6

parents
Pipeline #645 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;
int credit;
ArrayList<Student> students = new ArrayList<Student>();
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[] myStudents = new Student[students.size()];
students.toArray(myStudents);
return myStudents;
}
public Professor getProfessor() {
return professor;
}
public int getCredit() {
return 0;
}
public void enrollStudent(Student student){
if(student.getDepartment().equals(department))
students.add(student);
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.*;
public class CourseTest {
static Course course;
static Department department;
static Professor professor;
@BeforeAll
public static void creatCourse(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
course = new Course("3110" , "AP" , department , professor , 20);
}
@Test
public void testGetID(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
course = new Course("3110" , "AP" , department , professor , 20);
assertNotNull(course.getID());
assertEquals("3110" , course.getID());
}
@Test
public void testDepartment(){
assertNotNull(course.getDepartment());
assertEquals(department , course.getDepartment());
}
@Test
public void testGetName(){
assertNotNull(course.getName());
assertEquals("AP" , course.getName());
}
@Test
public void testProfessor(){
assertNotNull(course.getProfessor());
assertEquals(professor , course.getProfessor());
}
@Test
public void testEnrollStudent(){
for(Student st : course.getStudents()){
assertEquals(department , st.getDepartment());
}
}
}
package com.university;
import java.util.ArrayList;
public class Department {
String name;
ArrayList<Student> students = new ArrayList<Student>();
ArrayList<Course> courses = new ArrayList<Course>();
ArrayList<Professor> professors = new ArrayList<Professor>();
public Department(String name) {
this.name = name;
}
public String getName(){
return name;
}
public void addStudent(Student student){
if(student.getDepartment().equals(this))
students.add(student);
}
public Student[] getStudents(){
Student[] myStudents = new Student[students.size()];
students.toArray(myStudents);
return myStudents;
}
public void removeStudent(Student student){
if(student.getDepartment().equals(this)){
for(Student st : students){
if(st.equals(student)){
students.remove(st);
break;
}
}
}
}
public void addCourse(Course course){
if(course.getDepartment().equals(this))
courses.add(course);
}
public Course[] getCourses(){
Course[] myCourses = new Course[courses.size()];
courses.toArray(myCourses);
return myCourses;
}
public void removeCourse(Course course){
if(course.getDepartment().equals(this)){
for(Course cs : courses){
if(cs.equals(course)){
courses.remove(cs);
break;
}
}
}
}
public void addProfessor(Professor professor){
if(professor.getDepartment().equals(this))
professors.add(professor);
}
public Professor[] getProfessors(){
Professor[] myProfessors = new Professor[professors.size()];
professors.toArray(myProfessors);
return myProfessors;
}
public void removeProfessor(Professor professor){
if(professor.getDepartment().equals(this)){
for(Professor pr : professors){
if(pr.equals(professor)){
professors.remove(pr);
break;
}
}
}
}
}
package com.university;
import java.util.ArrayList;
public class Professor {
Department department;
String name;
ArrayList<Course> courses = new ArrayList<Course>();
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[] myCourses = new Course[courses.size()];
courses.toArray(myCourses);
return myCourses;
}
}
package com.university;
import java.util.ArrayList;
public class Student {
private String name = new String();
private String ID = new String();
private String major = new String();
private Department department;
private ArrayList<Course> courses = new ArrayList<Course>();
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 [] myCourses = new Course[courses.size()];
courses.toArray(myCourses);
return myCourses;
}
public void addCourse(Course course){
if(! course.equals(null))
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 org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
assertEquals("Alireza", student.getName());
}
@Test
public void testStudenGetCourses(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
assertNotNull(student.getCourses());
assertEquals(0, student.getCourses().length);
}
@Test
public void testStudentGetMajor(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
assertNotNull(student.getMajor());
assertEquals("Software Eng" , student.getMajor());
}
@Test
public void testStudentGetID(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
assertNotNull(student.getID());
assertEquals("1234" , student.getID());
}
@Test
public void testStudentGetDepartment(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
assertNotNull(student.getDepartment());
assertEquals(department , student.getDepartment());
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class TestDepartment {
static Department department;
@BeforeAll
public static void creatDepartment(){
department = new Department("Computer and IT Eng");
}
@Test
public void testAddStudent(){
department = new Department("Computer and IT Eng");
for(Student st : department.getStudents()){
assertEquals(department , st.getDepartment());
}
}
@Test
public void testGetStudents(){
department = new Department("Computer and IT Eng");
assertNotNull(department.getStudents());
assertEquals(0 , department.getStudents().length);
}
@Test
public void testGetName(){
department = new Department("Computer and IT Eng");
assertNotNull(department.getName());
assertEquals("Computer and IT Eng" , department.getName());
}
@Test
public void tsetAddCourse(){
department = new Department("Computer and IT Eng");
for(Course cs : department.getCourses())
assertEquals(department , cs.getDepartment());
}
@Test
public void testGetCourses(){
department = new Department("Computer and IT Eng");
assertNotNull(department.getCourses());
assertEquals(0 , department.getCourses().length);
}
@Test
public void testAddProfessor(){
department = new Department("Computer and IT Eng");
for(Professor pr : department.getProfessors())
assertEquals(department , pr.getDepartment());
}
@Test
public void testGetProfessors(){
department = new Department("Computer and IT Eng");
assertNotNull(department.getProfessors());
assertEquals(0 , department.getProfessors().length);
}
}
package com.university;
import java.util.ArrayList;
public class University {
ArrayList<Department> departments = new ArrayList<Department>();
public Department[] getDepartments(){
Department[] myDepartments = new Department[departments.size()];
departments.toArray(myDepartments);
return myDepartments;
}
public void addDepartment(Department department){
departments.add(department);
}
public void removeDepartment(Department department){
for(Department dep : departments)
if(dep.equals(department))
departments.remove(dep);
}
}
package test;
import com.university.Department;
import com.university.Professor;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class testProfessor {
static Professor professor;
static Department department;
@BeforeAll
public static void creatProfessor(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
}
@Test
public void testGetDepartment(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
assertNotNull(professor.getDepartment());
assertEquals(department , professor.getDepartment());
}
@Test
public void testGetName(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
assertNotNull(professor.getName());
assertEquals("ostad" , professor.getName());
}
@Test
public void testGetCourses(){
department = new Department("Computer and IT Eng");
professor = new Professor(department , "ostad");
assertNotNull(professor.getCourses());
assertEquals(0 , professor.getCourses().length);
}
}
package test;
import com.university.University;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class universityTest {
static University university;
@BeforeAll
public static void creatUniversity(){
university = new University();
}
@Test
public void testGetDepartment(){
university = new University();
assertNotNull(university.getDepartments());
assertEquals(0 , university.getDepartments().length);
}
}
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