-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TEST] 출석 관련 단위 테스트 추가 및 행사 출석 로직 수정 #254
Changes from all commits
ffa2c20
8f67dca
ef9cff4
246e287
939e385
9ecbe65
7b90765
8abf1d4
e25492f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,13 @@ public class Attendance { | |
@OneToMany(mappedBy = "attendance") | ||
private final List<SubAttendance> subAttendances = new ArrayList<>(); | ||
|
||
protected Attendance(Long id, Member member, Lecture lecture, AttendanceStatus status) { | ||
this.id = id; | ||
setMember(member); | ||
setLecture(lecture); | ||
this.status = status; | ||
} | ||
|
||
Comment on lines
+51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yummygyudon |
||
public Attendance(Member member, Lecture lecture) { | ||
setMember(member); | ||
setLecture(lecture); | ||
|
@@ -79,13 +86,12 @@ public AttendanceStatus getStatus() { | |
val second = getSubAttendanceByRound(2); | ||
|
||
return switch (this.lecture.getAttribute()) { | ||
case SEMINAR -> { | ||
case SEMINAR, EVENT -> { | ||
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) { | ||
yield ATTENDANCE; | ||
} | ||
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY; | ||
} | ||
case EVENT -> second.getStatus().equals(ATTENDANCE) ? ATTENDANCE : ABSENT; | ||
case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE; | ||
}; | ||
} | ||
|
@@ -103,7 +109,7 @@ public float getScore() { | |
yield 0f; | ||
} | ||
} | ||
case EVENT -> this.status.equals(ATTENDANCE) ? 0.5f : 0f; | ||
case EVENT -> this.status.equals(ABSENT) ? 0f : 0.5f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 행사 점수 연산 방식을 전달 드리기 전에 올리신 PR인 것 같습니다! Score 조회 메서드는 원용씨가 하신대로 가면될 듯 하구 현재는 2차 출석값만 확인하는 로직인 듯 합니다!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
return switch (this.lecture.getAttribute()) {
case SEMINAR -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
}
case EVENT -> second.getStatus().equals(ATTENDANCE) ? ATTENDANCE : ABSENT;
case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE;
};
return switch (this.lecture.getAttribute()) {
case SEMINAR -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
}
case EVENT -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE;
}; 메서드 길이가 길어지는 문제와 함께 중복되는 코드가 발생하는 문제가 존재할 것 같은데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yummygyudon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 행사도 연산 점수 로직 바뀐거 확인했습니다 ! 동규님 꼼꼼하게 체크해주시고 바로 반영해준 원용님 감사합니다 ~! |
||
default -> 0f; | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.sopt.makers.operation.attendance.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.sopt.makers.operation.common.domain.Part; | ||
import org.sopt.makers.operation.dummy.AttendanceDummy; | ||
import org.sopt.makers.operation.dummy.LectureDummy; | ||
import org.sopt.makers.operation.dummy.MemberDummy; | ||
import org.sopt.makers.operation.lecture.domain.Attribute; | ||
import org.sopt.makers.operation.lecture.domain.Lecture; | ||
import org.sopt.makers.operation.lecture.domain.LectureStatus; | ||
import org.sopt.makers.operation.member.domain.Member; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class AttendanceGetScoreTest { | ||
|
||
private Member member; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
member = MemberDummy.builder() | ||
.id(1L) | ||
.attendances(new ArrayList<>()) | ||
.build(); | ||
} | ||
|
||
@Nested | ||
@DisplayName("[세미나 출석 점수 반환 테스트]") | ||
public class SeminarTest { | ||
@Test | ||
@DisplayName("세미나에 출석을 했으면 0f를 반환한다.") | ||
public void getScoreTest() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0f); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에 지각을 했으면 -0.5f를 반환한다.") | ||
public void getScoreTest2() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.TARDY); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(-0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에 결석을 했으면 -1f를 반환한다.") | ||
public void getScoreTest3() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(-1f); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("[행사 출석 점수 반환 테스트]") | ||
public class EventTest { | ||
@Test | ||
@DisplayName("행사에 출석을 했으면 0.5f를 반환한다.") | ||
public void getScoreTest() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("행사에 지각을 했으면 0.5f를 반환한다.") | ||
public void getScoreTest2() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.TARDY); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("행사에 결석을 했으면 0f를 반환한다.") | ||
public void getScoreTest3() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0f); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 진짜 메이커스에서 테스트하는 것 감격...!!