Commit c47796bc authored by 9531304's avatar 9531304

the first part

parents
Pipeline #639 failed with stages
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 StudentTest {
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);
}
}
package com.university;
import java.util.ArrayList;
public class Course {
private String ID;
private String name;
private Department dpart;
private Professor prof;
private int credit;
private ArrayList<Student> stds = new ArrayList<Student>();
public Course(String ID, String name, Department department, Professor professor, int credit) {
this.ID = ID;
this.name = name;
dpart = department;
prof = professor;
this.credit = credit;
}
public String getID(){
return ID;
}
public Department getDepartment(){
return dpart;
}
public String getName() {
return name;
}
public Student[] getStudents() {
Student[] students = stds.toArray(new Student[stds.size()]);
return students;
}
public Professor getProfessor() {
return prof;
}
public int getCredit() {
return credit;
}
public void enrollStudent(Student student){
stds.add(student);
}
}
package com.university;
public class Department {
private String name;
public Department(String name) {
this.name = name;
}
public String getName(){
return name;
}
public void addStudent(Student student){
}
public Student[] getStudents(){
return null;
}
public void removeStudent(Student student){
}
public void addCourse(Course course){
}
public Course[] getCourses(){
return null;
}
public void removeCourse(Course course){
}
public void addProfessor(Professor student){
}
public Professor[] getProfessors(){
return null;
}
public void removeProfessor(Professor professor){
}
}
package com.university;
import java.util.ArrayList;
public class Professor {
private String name;
private Department dpart;
private ArrayList<Course> crs = new ArrayList<Course>();
public Professor(Department department, String name) {
this.name = name;
dpart = department;
}
public Department getDepartment() {
return dpart;
}
public String getName() {
return name;
}
public Course[] getCourses() {
return null;
}
}
package com.university;
import java.util.ArrayList;
public class Student {
private String name;
private String ID;
private String major;
private Department dpart;
private ArrayList<Course> crss = new ArrayList<Course>();
public Student(String name, String ID, String major, Department department) {
this.name = name;
this.ID = ID;
this.major = major;
dpart = department;
}
public String getName() {
return name;
}
public String getID() {
return ID;
}
public String getMajor() {
return major;
}
public Department getDepartment() {
return dpart;
}
public Course[] getCourses() {
Course[] courses = crss.toArray(new Course[crss.size()]);
return courses;
}
public void addCourse(Course course){
if(course != null) {
crss.add(course);
}
}
}
package com.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 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);
}
}
package com.university;
public class University {
public Department[] getDepartments(){
return null;
}
public void addDepartment(Department department){ }
public void removeDepartment(Department department){ }
}
package com.university;
public class test {
public static void main(String[] args){
Department dp = new Department("amirkabir");
Student st = new Student("Mohammad" , "1234" , "Mechanic" , dp);
System.out.println(st.getName());
}
}
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 junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
public class StudnetTest {
static Student student , student1;
static Department department;
static Professor prf;
@BeforeAll
public static void createStudent(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
prf = new Professor(department , "Ohadi");
Course c1 = new Course("12" , "mathematic" , department , prf , 1);
Course c2 = new Course("14" , "Physic" , department , prf , 2);
student1 = new Student("Mohammad" , "4321" , "Mechanic" , department);
student1.addCourse(null);
}
@Test
public void testStudentGetName(){
assertEquals("Alireza", student.getName());
}
@Test
public void testStudenGetCourses(){
assertNotNull(student.getCourses());
assertEquals(0, student.getCourses().length);
}
@Test
public void testStudentID(){
assertNotNull(student.getID());
}
@Test
public void testStudentDepartment(){
assertNotNull(student.getDepartment());
}
@Test
public void testStudentMajor(){
assertNotNull(student.getMajor());
}
@Test
public void testStudentNullCourse(){
assertEquals(0 , student1.getCourses().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