|
|
|
|
@ -1,689 +0,0 @@
|
|
|
|
|
package net.mooctest;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.EnumMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 开发者做题说明:
|
|
|
|
|
* 1、该测试类为测试类示例,不要求完全按照该示例类的格式;考生也可自行创建测试类,类名可自行定义
|
|
|
|
|
* 2、所有测试方法放在该顶层类中,不建议再创建内部类
|
|
|
|
|
* 3、不要修改被测代码
|
|
|
|
|
* 4、提交答案时只提交一个测试类.java文件
|
|
|
|
|
* 5、无论最终的类名是什么,都要保证文件名与类名一致(遵循Java语法),如测试类为MementoTest,则提交时的文件名应为MementoTest.java,否则将因不符合语法而判0分!
|
|
|
|
|
* 6、建议尽量避免卡点提交答案
|
|
|
|
|
*
|
|
|
|
|
* */
|
|
|
|
|
public class StudentTest {
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void setUpBeforeClass() throws Exception {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void tearDownAfterClass() throws Exception {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== Student类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentConstructor() {
|
|
|
|
|
LocalDate birthDate = LocalDate.of(2000, 1, 1);
|
|
|
|
|
Student student = new Student("张三", birthDate);
|
|
|
|
|
assertNotNull(student.getId());
|
|
|
|
|
assertEquals("张三", student.getName());
|
|
|
|
|
assertEquals(birthDate, student.getDateOfBirth());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentConstructorTrimsName() {
|
|
|
|
|
Student student = new Student(" 李四 ", LocalDate.of(2000, 1, 1));
|
|
|
|
|
assertEquals("李四", student.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentConstructorNullName() {
|
|
|
|
|
new Student(null, LocalDate.of(2000, 1, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentConstructorEmptyName() {
|
|
|
|
|
new Student("", LocalDate.of(2000, 1, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentConstructorNullDate() {
|
|
|
|
|
new Student("王五", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentConstructorFutureDate() {
|
|
|
|
|
new Student("赵六", LocalDate.now().plusDays(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentSetName() {
|
|
|
|
|
Student student = new Student("原名", LocalDate.of(2000, 1, 1));
|
|
|
|
|
student.setName("新名");
|
|
|
|
|
assertEquals("新名", student.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentSetNameNull() {
|
|
|
|
|
Student student = new Student("原名", LocalDate.of(2000, 1, 1));
|
|
|
|
|
student.setName(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentSetDateOfBirth() {
|
|
|
|
|
Student student = new Student("测试", LocalDate.of(2000, 1, 1));
|
|
|
|
|
LocalDate newDate = LocalDate.of(1990, 1, 1);
|
|
|
|
|
student.setDateOfBirth(newDate);
|
|
|
|
|
assertEquals(newDate, student.getDateOfBirth());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testStudentSetDateOfBirthNull() {
|
|
|
|
|
Student student = new Student("测试", LocalDate.of(2000, 1, 1));
|
|
|
|
|
student.setDateOfBirth(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentEquals() {
|
|
|
|
|
Student s1 = new Student("学生1", LocalDate.of(2000, 1, 1));
|
|
|
|
|
Student s2 = new Student("学生2", LocalDate.of(2000, 1, 1));
|
|
|
|
|
assertTrue(s1.equals(s1));
|
|
|
|
|
assertFalse(s1.equals(s2));
|
|
|
|
|
assertFalse(s1.equals(null));
|
|
|
|
|
assertFalse(s1.equals("字符串"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStudentHashCode() {
|
|
|
|
|
Student student = new Student("测试", LocalDate.of(2000, 1, 1));
|
|
|
|
|
assertEquals(student.hashCode(), student.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== Course类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseConstructor() {
|
|
|
|
|
Course course = new Course("cs101", "计算机科学", 3);
|
|
|
|
|
assertNotNull(course.getId());
|
|
|
|
|
assertEquals("CS101", course.getCode());
|
|
|
|
|
assertEquals("计算机科学", course.getTitle());
|
|
|
|
|
assertEquals(3, course.getCreditHours());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseConstructorTrims() {
|
|
|
|
|
Course course = new Course(" math201 ", " 数学 ", 4);
|
|
|
|
|
assertEquals("MATH201", course.getCode());
|
|
|
|
|
assertEquals("数学", course.getTitle());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseConstructorNullCode() {
|
|
|
|
|
new Course(null, "标题", 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseConstructorNullTitle() {
|
|
|
|
|
new Course("CS101", null, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseConstructorZeroCredits() {
|
|
|
|
|
new Course("CS101", "标题", 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseConstructorNegativeCredits() {
|
|
|
|
|
new Course("CS101", "标题", -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseSetCode() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
course.setCode("cs102");
|
|
|
|
|
assertEquals("CS102", course.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseSetCodeNull() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
course.setCode(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseSetTitle() {
|
|
|
|
|
Course course = new Course("CS101", "原标题", 3);
|
|
|
|
|
course.setTitle("新标题");
|
|
|
|
|
assertEquals("新标题", course.getTitle());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseSetTitleNull() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
course.setTitle(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseSetCreditHours() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
course.setCreditHours(4);
|
|
|
|
|
assertEquals(4, course.getCreditHours());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testCourseSetCreditHoursZero() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
course.setCreditHours(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseEquals() {
|
|
|
|
|
Course c1 = new Course("CS101", "标题1", 3);
|
|
|
|
|
Course c2 = new Course("CS102", "标题2", 4);
|
|
|
|
|
assertTrue(c1.equals(c1));
|
|
|
|
|
assertFalse(c1.equals(c2));
|
|
|
|
|
assertFalse(c1.equals(null));
|
|
|
|
|
assertFalse(c1.equals("字符串"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCourseHashCode() {
|
|
|
|
|
Course course = new Course("CS101", "标题", 3);
|
|
|
|
|
assertEquals(course.hashCode(), course.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== Enrollment类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentConstructor() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
assertNotNull(e.getId());
|
|
|
|
|
assertEquals("student1", e.getStudentId());
|
|
|
|
|
assertEquals("course1", e.getCourseId());
|
|
|
|
|
assertEquals(2024, e.getYear());
|
|
|
|
|
assertEquals(Term.SPRING, e.getTerm());
|
|
|
|
|
assertEquals(EnrollmentStatus.ENROLLED, e.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentConstructorNullStudentId() {
|
|
|
|
|
new Enrollment(null, "course1", 2024, Term.SPRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentConstructorNullCourseId() {
|
|
|
|
|
new Enrollment("student1", null, 2024, Term.SPRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentConstructorZeroYear() {
|
|
|
|
|
new Enrollment("student1", "course1", 0, Term.SPRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentConstructorNullTerm() {
|
|
|
|
|
new Enrollment("student1", "course1", 2024, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentDrop() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.drop();
|
|
|
|
|
assertEquals(EnrollmentStatus.DROPPED, e.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = DomainException.class)
|
|
|
|
|
public void testEnrollmentDropCompleted() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.complete();
|
|
|
|
|
e.drop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentComplete() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.complete();
|
|
|
|
|
assertEquals(EnrollmentStatus.COMPLETED, e.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = DomainException.class)
|
|
|
|
|
public void testEnrollmentCompleteDropped() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.drop();
|
|
|
|
|
e.complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentMarkIncomplete() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.markIncomplete();
|
|
|
|
|
assertEquals(EnrollmentStatus.INCOMPLETE, e.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = DomainException.class)
|
|
|
|
|
public void testEnrollmentMarkIncompleteFromDropped() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.drop();
|
|
|
|
|
e.markIncomplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentRecordGrade() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
GradeRecord record = new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0);
|
|
|
|
|
e.recordGrade(record);
|
|
|
|
|
assertEquals(1, e.getGradesByComponent().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = DomainException.class)
|
|
|
|
|
public void testEnrollmentRecordGradeDropped() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.drop();
|
|
|
|
|
e.recordGrade(new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentRecordGradeNull() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.recordGrade(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentGetAverageScore() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.recordGrade(new GradeRecord(GradeComponentType.ASSIGNMENT, 80.0));
|
|
|
|
|
e.recordGrade(new GradeRecord(GradeComponentType.FINAL, 90.0));
|
|
|
|
|
|
|
|
|
|
Map<GradeComponentType, GradeComponent> policy = new EnumMap<>(GradeComponentType.class);
|
|
|
|
|
policy.put(GradeComponentType.ASSIGNMENT, new GradeComponent(GradeComponentType.ASSIGNMENT, 0.4));
|
|
|
|
|
policy.put(GradeComponentType.FINAL, new GradeComponent(GradeComponentType.FINAL, 0.6));
|
|
|
|
|
|
|
|
|
|
double avg = e.getAverageScore(policy);
|
|
|
|
|
assertEquals(86.0, avg, 0.01);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentGetAverageScoreNullPolicy() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.getAverageScore(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testEnrollmentGetAverageScoreEmptyPolicy() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
e.getAverageScore(new EnumMap<>(GradeComponentType.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentEquals() {
|
|
|
|
|
Enrollment e1 = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
Enrollment e2 = new Enrollment("student2", "course2", 2024, Term.FALL);
|
|
|
|
|
assertTrue(e1.equals(e1));
|
|
|
|
|
assertFalse(e1.equals(e2));
|
|
|
|
|
assertFalse(e1.equals(null));
|
|
|
|
|
assertFalse(e1.equals("字符串"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentHashCode() {
|
|
|
|
|
Enrollment e = new Enrollment("student1", "course1", 2024, Term.SPRING);
|
|
|
|
|
assertEquals(e.hashCode(), e.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== GradeComponent类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentConstructor() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
assertEquals(GradeComponentType.ASSIGNMENT, gc.getType());
|
|
|
|
|
assertEquals(0.3, gc.getWeight(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeComponentConstructorNullType() {
|
|
|
|
|
new GradeComponent(null, 0.3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeComponentConstructorNegativeWeight() {
|
|
|
|
|
new GradeComponent(GradeComponentType.ASSIGNMENT, -0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeComponentConstructorWeightTooHigh() {
|
|
|
|
|
new GradeComponent(GradeComponentType.ASSIGNMENT, 1.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentSetType() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
gc.setType(GradeComponentType.QUIZ);
|
|
|
|
|
assertEquals(GradeComponentType.QUIZ, gc.getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeComponentSetTypeNull() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
gc.setType(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentSetWeight() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
gc.setWeight(0.5);
|
|
|
|
|
assertEquals(0.5, gc.getWeight(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeComponentSetWeightNegative() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
gc.setWeight(-0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentEquals() {
|
|
|
|
|
GradeComponent gc1 = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
GradeComponent gc2 = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.5);
|
|
|
|
|
GradeComponent gc3 = new GradeComponent(GradeComponentType.QUIZ, 0.3);
|
|
|
|
|
assertTrue(gc1.equals(gc1));
|
|
|
|
|
assertTrue(gc1.equals(gc2));
|
|
|
|
|
assertFalse(gc1.equals(gc3));
|
|
|
|
|
assertFalse(gc1.equals(null));
|
|
|
|
|
assertFalse(gc1.equals("字符串"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentHashCode() {
|
|
|
|
|
GradeComponent gc = new GradeComponent(GradeComponentType.ASSIGNMENT, 0.3);
|
|
|
|
|
assertEquals(gc.hashCode(), gc.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== GradeRecord类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeRecordConstructor() {
|
|
|
|
|
GradeRecord gr = new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0);
|
|
|
|
|
assertEquals(GradeComponentType.ASSIGNMENT, gr.getComponentType());
|
|
|
|
|
assertEquals(85.0, gr.getScore(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeRecordConstructorNullType() {
|
|
|
|
|
new GradeRecord(null, 85.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeRecordConstructorNegativeScore() {
|
|
|
|
|
new GradeRecord(GradeComponentType.ASSIGNMENT, -1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeRecordConstructorScoreTooHigh() {
|
|
|
|
|
new GradeRecord(GradeComponentType.ASSIGNMENT, 101.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeRecordSetScore() {
|
|
|
|
|
GradeRecord gr = new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0);
|
|
|
|
|
gr.setScore(90.0);
|
|
|
|
|
assertEquals(90.0, gr.getScore(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeRecordSetScoreNegative() {
|
|
|
|
|
GradeRecord gr = new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0);
|
|
|
|
|
gr.setScore(-1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradeRecordSetScoreTooHigh() {
|
|
|
|
|
GradeRecord gr = new GradeRecord(GradeComponentType.ASSIGNMENT, 85.0);
|
|
|
|
|
gr.setScore(101.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeRecordBoundaryScores() {
|
|
|
|
|
GradeRecord gr1 = new GradeRecord(GradeComponentType.ASSIGNMENT, 0.0);
|
|
|
|
|
assertEquals(0.0, gr1.getScore(), 0.001);
|
|
|
|
|
GradeRecord gr2 = new GradeRecord(GradeComponentType.ASSIGNMENT, 100.0);
|
|
|
|
|
assertEquals(100.0, gr2.getScore(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== GradingPolicy类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradingPolicyConstructor() {
|
|
|
|
|
Map<GradeComponentType, GradeComponent> components = new EnumMap<>(GradeComponentType.class);
|
|
|
|
|
components.put(GradeComponentType.ASSIGNMENT, new GradeComponent(GradeComponentType.ASSIGNMENT, 0.4));
|
|
|
|
|
components.put(GradeComponentType.FINAL, new GradeComponent(GradeComponentType.FINAL, 0.6));
|
|
|
|
|
GradingPolicy policy = new GradingPolicy(components);
|
|
|
|
|
assertEquals(2, policy.getComponents().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradingPolicyConstructorNull() {
|
|
|
|
|
new GradingPolicy(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradingPolicyConstructorEmpty() {
|
|
|
|
|
new GradingPolicy(new EnumMap<>(GradeComponentType.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testGradingPolicyConstructorWeightNotOne() {
|
|
|
|
|
Map<GradeComponentType, GradeComponent> components = new EnumMap<>(GradeComponentType.class);
|
|
|
|
|
components.put(GradeComponentType.ASSIGNMENT, new GradeComponent(GradeComponentType.ASSIGNMENT, 0.4));
|
|
|
|
|
components.put(GradeComponentType.FINAL, new GradeComponent(GradeComponentType.FINAL, 0.5));
|
|
|
|
|
new GradingPolicy(components);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradingPolicyGetComponents() {
|
|
|
|
|
Map<GradeComponentType, GradeComponent> components = new EnumMap<>(GradeComponentType.class);
|
|
|
|
|
components.put(GradeComponentType.ASSIGNMENT, new GradeComponent(GradeComponentType.ASSIGNMENT, 1.0));
|
|
|
|
|
GradingPolicy policy = new GradingPolicy(components);
|
|
|
|
|
assertNotNull(policy.getComponents());
|
|
|
|
|
assertEquals(1, policy.getComponents().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== Transcript类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testTranscriptConstructor() {
|
|
|
|
|
Transcript transcript = new Transcript();
|
|
|
|
|
assertNotNull(transcript.getItems());
|
|
|
|
|
assertEquals(0, transcript.getItems().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTranscriptAddItem() {
|
|
|
|
|
Transcript transcript = new Transcript();
|
|
|
|
|
Transcript.LineItem item = new Transcript.LineItem("CS101", "计算机科学", 3, 85.0, 3.5);
|
|
|
|
|
transcript.addItem(item);
|
|
|
|
|
assertEquals(1, transcript.getItems().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testTranscriptAddItemNull() {
|
|
|
|
|
Transcript transcript = new Transcript();
|
|
|
|
|
transcript.addItem(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTranscriptComputeCumulativeGpa() {
|
|
|
|
|
Transcript transcript = new Transcript();
|
|
|
|
|
transcript.addItem(new Transcript.LineItem("CS101", "计算机科学", 3, 85.0, 3.5));
|
|
|
|
|
transcript.addItem(new Transcript.LineItem("MATH201", "数学", 4, 90.0, 4.0));
|
|
|
|
|
double gpa = transcript.computeCumulativeGpa();
|
|
|
|
|
assertEquals(3.785714, gpa, 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTranscriptComputeCumulativeGpaEmpty() {
|
|
|
|
|
Transcript transcript = new Transcript();
|
|
|
|
|
assertEquals(0.0, transcript.computeCumulativeGpa(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTranscriptLineItemGetters() {
|
|
|
|
|
Transcript.LineItem item = new Transcript.LineItem("CS101", "计算机科学", 3, 85.0, 3.5);
|
|
|
|
|
assertEquals("CS101", item.getCourseCode());
|
|
|
|
|
assertEquals("计算机科学", item.getCourseTitle());
|
|
|
|
|
assertEquals(3, item.getCreditHours());
|
|
|
|
|
assertEquals(85.0, item.getPercentage(), 0.001);
|
|
|
|
|
assertEquals(3.5, item.getGpaPoints(), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== DomainException类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testDomainExceptionWithMessage() {
|
|
|
|
|
DomainException ex = new DomainException("测试错误");
|
|
|
|
|
assertEquals("测试错误", ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDomainExceptionWithMessageAndCause() {
|
|
|
|
|
Exception cause = new Exception("原因");
|
|
|
|
|
DomainException ex = new DomainException("测试错误", cause);
|
|
|
|
|
assertEquals("测试错误", ex.getMessage());
|
|
|
|
|
assertEquals(cause, ex.getCause());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== ValidationException类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationException() {
|
|
|
|
|
ValidationException ex = new ValidationException("验证错误");
|
|
|
|
|
assertEquals("验证错误", ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== ValidationUtil类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationUtilRequireNonBlank() {
|
|
|
|
|
ValidationUtil.requireNonBlank("测试", "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireNonBlankNull() {
|
|
|
|
|
ValidationUtil.requireNonBlank(null, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireNonBlankEmpty() {
|
|
|
|
|
ValidationUtil.requireNonBlank("", "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireNonBlankBlank() {
|
|
|
|
|
ValidationUtil.requireNonBlank(" ", "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationUtilRequirePositive() {
|
|
|
|
|
ValidationUtil.requirePositive(1, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequirePositiveZero() {
|
|
|
|
|
ValidationUtil.requirePositive(0, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequirePositiveNegative() {
|
|
|
|
|
ValidationUtil.requirePositive(-1, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationUtilRequireNonNegative() {
|
|
|
|
|
ValidationUtil.requireNonNegative(0.0, "field");
|
|
|
|
|
ValidationUtil.requireNonNegative(1.0, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireNonNegativeNegative() {
|
|
|
|
|
ValidationUtil.requireNonNegative(-0.1, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationUtilRequireBetween() {
|
|
|
|
|
ValidationUtil.requireBetween(5.0, 0.0, 10.0, "field");
|
|
|
|
|
ValidationUtil.requireBetween(0.0, 0.0, 10.0, "field");
|
|
|
|
|
ValidationUtil.requireBetween(10.0, 0.0, 10.0, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireBetweenTooLow() {
|
|
|
|
|
ValidationUtil.requireBetween(-1.0, 0.0, 10.0, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequireBetweenTooHigh() {
|
|
|
|
|
ValidationUtil.requireBetween(11.0, 0.0, 10.0, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidationUtilRequirePastOrPresent() {
|
|
|
|
|
ValidationUtil.requirePastOrPresent(LocalDate.now(), "field");
|
|
|
|
|
ValidationUtil.requirePastOrPresent(LocalDate.now().minusDays(1), "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequirePastOrPresentNull() {
|
|
|
|
|
ValidationUtil.requirePastOrPresent(null, "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = ValidationException.class)
|
|
|
|
|
public void testValidationUtilRequirePastOrPresentFuture() {
|
|
|
|
|
ValidationUtil.requirePastOrPresent(LocalDate.now().plusDays(1), "field");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== Enum类测试 ==========
|
|
|
|
|
@Test
|
|
|
|
|
public void testEnrollmentStatusValues() {
|
|
|
|
|
EnrollmentStatus[] values = EnrollmentStatus.values();
|
|
|
|
|
assertEquals(4, values.length);
|
|
|
|
|
assertEquals(EnrollmentStatus.ENROLLED, EnrollmentStatus.valueOf("ENROLLED"));
|
|
|
|
|
assertEquals(EnrollmentStatus.DROPPED, EnrollmentStatus.valueOf("DROPPED"));
|
|
|
|
|
assertEquals(EnrollmentStatus.COMPLETED, EnrollmentStatus.valueOf("COMPLETED"));
|
|
|
|
|
assertEquals(EnrollmentStatus.INCOMPLETE, EnrollmentStatus.valueOf("INCOMPLETE"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTermValues() {
|
|
|
|
|
Term[] values = Term.values();
|
|
|
|
|
assertEquals(4, values.length);
|
|
|
|
|
assertEquals(Term.SPRING, Term.valueOf("SPRING"));
|
|
|
|
|
assertEquals(Term.SUMMER, Term.valueOf("SUMMER"));
|
|
|
|
|
assertEquals(Term.FALL, Term.valueOf("FALL"));
|
|
|
|
|
assertEquals(Term.WINTER, Term.valueOf("WINTER"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGradeComponentTypeValues() {
|
|
|
|
|
GradeComponentType[] values = GradeComponentType.values();
|
|
|
|
|
assertEquals(7, values.length);
|
|
|
|
|
assertEquals(GradeComponentType.ASSIGNMENT, GradeComponentType.valueOf("ASSIGNMENT"));
|
|
|
|
|
assertEquals(GradeComponentType.QUIZ, GradeComponentType.valueOf("QUIZ"));
|
|
|
|
|
assertEquals(GradeComponentType.MIDTERM, GradeComponentType.valueOf("MIDTERM"));
|
|
|
|
|
assertEquals(GradeComponentType.FINAL, GradeComponentType.valueOf("FINAL"));
|
|
|
|
|
assertEquals(GradeComponentType.PROJECT, GradeComponentType.valueOf("PROJECT"));
|
|
|
|
|
assertEquals(GradeComponentType.PARTICIPATION, GradeComponentType.valueOf("PARTICIPATION"));
|
|
|
|
|
assertEquals(GradeComponentType.EXTRA_CREDIT, GradeComponentType.valueOf("EXTRA_CREDIT"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|