주 시작 선택을 달력 표시 옵션에 추가했다. 앱과 웹의 머리글과 날짜 배열 및 월간과 두 주 위젯이 같은 설정을 사용한다. 주말 색상은 실제 요일을 따르며 당직 기준일과 반복 근무는 바꾸지 않는다. 0.12.0과 설치 번호 16 및 웹 2026-11-21.2로 맞췄다. 서버는 weekStart에 일요일 0과 월요일 1만 허용한다. 구버전에서 필드를 생략하면 기존 값을 유지한다. 반복 근무와 개인 옵션은 같은 트랜잭션에서 버전을 맞춘다. DB 구조 변경은 없다. 앱 단위 37개와 서버 검사 66개 및 웹의 주 시작·음력·반복·업데이트 검사 통과. APK와 공개 소스 ZIP 새 폴더 빌드 통과. 정적 검사 오류 0개와 경고 71개. 가상 기기에서 월·일 머리글과 첫 날짜 및 주말 색상과 두 주 위젯의 시작을 확인했다. 웹에서 월요일 선택 저장과 재접속 유지 및 42칸을 확인했다. 변경 전 소스와 DB는 보조서버 비공개 20261121-week-start 백업에 보관했다. 운영 웹과 직접 APK 업데이트 경로에 반영했다. 요청한 관리자 계정의 weekStart만 월요일로 바꾸고 나머지 근무와 표시 옵션을 보존했다. 실물 휴대폰과 제조사별 홈 화면은 별도 확인이 필요하다.
140 lines
8.0 KiB
Kotlin
140 lines
8.0 KiB
Kotlin
package kr.co.itosm.dutycalendar
|
|
|
|
import org.junit.Assert.*
|
|
import org.junit.Test
|
|
import java.time.LocalDate
|
|
import java.time.YearMonth
|
|
|
|
/**
|
|
* 반복 근무 계산에서 틀리기 쉬운 기준일 이전과 연말 및 윤년 경계를 확인한다.
|
|
* 안드로이드 화면 없이 순수 날짜 계산을 검사해 기기 시간이나 네트워크 상태의 영향을 받지 않게 한다.
|
|
* 화면 배치와 위젯 추가 및 공휴일 통신은 가상 기기에서 별도로 확인한다.
|
|
*/
|
|
class ScheduleTest {
|
|
private val anchor = LocalDate.of(2026, 11, 20)
|
|
@Test fun twoDayCycle() {
|
|
val schedule = Schedule(anchor, Schedule.preset(2))
|
|
assertEquals(listOf(Shift.DUTY, Shift.OFF, Shift.DUTY, Shift.OFF), (0L..3L).map { schedule.shiftOn(anchor.plusDays(it)) })
|
|
}
|
|
@Test fun threeDayCycle() {
|
|
val schedule = Schedule(anchor, Schedule.preset(3))
|
|
assertEquals(Shift.REGULAR, schedule.shiftOn(anchor.plusDays(2)))
|
|
assertEquals(Shift.DUTY, schedule.shiftOn(anchor.plusDays(3)))
|
|
}
|
|
@Test fun datesBeforeAnchorUseSameCycle() {
|
|
val schedule = Schedule(anchor, Schedule.preset(3))
|
|
assertEquals(Shift.REGULAR, schedule.shiftOn(anchor.minusDays(1)))
|
|
assertEquals(Shift.OFF, schedule.shiftOn(anchor.minusDays(2)))
|
|
assertEquals(Shift.DUTY, schedule.shiftOn(anchor.minusDays(3)))
|
|
}
|
|
@Test fun customPatternIsPreservedAcrossYearBoundary() {
|
|
val schedule = Schedule(LocalDate.of(2026, 12, 30), listOf(Shift.OFF, Shift.REGULAR, Shift.DUTY, Shift.OFF))
|
|
assertEquals(Shift.DUTY, schedule.shiftOn(LocalDate.of(2027, 1, 1)))
|
|
}
|
|
@Test fun leapDayAndMarchAreConsecutive() {
|
|
val schedule = Schedule(LocalDate.of(2028, 2, 28), Schedule.preset(3))
|
|
assertEquals(Shift.OFF, schedule.shiftOn(LocalDate.of(2028, 2, 29)))
|
|
assertEquals(Shift.REGULAR, schedule.shiftOn(LocalDate.of(2028, 3, 1)))
|
|
}
|
|
@Test fun monthGridIncludesAllDaysAndStartsSunday() {
|
|
val days = calendarDays(YearMonth.of(2026, 8))
|
|
assertEquals(42, days.size)
|
|
assertEquals(java.time.DayOfWeek.SUNDAY, days.first().dayOfWeek)
|
|
assertTrue(days.contains(LocalDate.of(2026, 8, 31)))
|
|
}
|
|
@Test(expected = IllegalArgumentException::class) fun emptyCycleRejected() { Schedule(anchor, emptyList()) }
|
|
@Test fun mondayGridHandlesSundayMonthStartAndYearBoundary() {
|
|
assertEquals(LocalDate.of(2026,10,26),calendarDays(YearMonth.of(2026,11),1).first())
|
|
assertEquals(LocalDate.of(2026,11,1),calendarDays(YearMonth.of(2026,11),0).first())
|
|
assertEquals(LocalDate.of(2026,12,28),calendarDays(YearMonth.of(2027,1),1).first())
|
|
assertEquals(LocalDate.of(2028,2,29),calendarDays(YearMonth.of(2028,2),1).single{it==LocalDate.of(2028,2,29)})
|
|
assertEquals(LocalDate.of(2026,11,16),startOfWeek(LocalDate.of(2026,11,22),1))
|
|
assertEquals(listOf(1,2,3,4,5,6,0),calendarWeekdays(1))
|
|
}
|
|
@Test fun changingWeekStartOnlyChangesLayout() {
|
|
val sunday=Schedule(anchor,Schedule.preset(3),5,true,true,true)
|
|
val monday=sunday.copy(weekStart=1)
|
|
for(offset in -400L..400L) {
|
|
val date=anchor.plusDays(offset)
|
|
assertEquals(sunday.shiftOn(date),monday.shiftOn(date))
|
|
assertEquals(sunday.dateColor(date,true),monday.dateColor(date,true))
|
|
}
|
|
for(year in 2024..2028)for(month in 1..12)for(start in 0..1) {
|
|
val ym=YearMonth.of(year,month);val dates=calendarDays(ym,start)
|
|
assertEquals(42,dates.size)
|
|
assertEquals(ym.lengthOfMonth(),dates.count{YearMonth.from(it)==ym})
|
|
assertEquals(if(start==1)java.time.DayOfWeek.MONDAY else java.time.DayOfWeek.SUNDAY,dates.first().dayOfWeek)
|
|
assertEquals(41L,java.time.temporal.ChronoUnit.DAYS.between(dates.first(),dates.last()))
|
|
}
|
|
}
|
|
@Test(expected = IllegalArgumentException::class) fun invalidWeekStartRejected() { Schedule(anchor,Schedule.preset(2),weekStart=2) }
|
|
@Test fun longestCycleWorks() {
|
|
val schedule = Schedule(anchor, Schedule.preset(366))
|
|
assertEquals(Shift.REGULAR, schedule.shiftOn(anchor.plusDays(365)))
|
|
assertEquals(Shift.DUTY, schedule.shiftOn(anchor.plusDays(366)))
|
|
}
|
|
@Test fun dutyNumberKeepsDutyOffAndFillsRemainingDays() {
|
|
val schedule = Schedule(anchor, Schedule.preset(5))
|
|
assertEquals(listOf(Shift.DUTY, Shift.OFF, Shift.REGULAR, Shift.REGULAR, Shift.REGULAR, Shift.DUTY), (0L..5).map { schedule.shiftOn(anchor.plusDays(it)) })
|
|
}
|
|
@Test fun nightOffAndRestRemainDistinctAcrossMonthBoundary() {
|
|
val schedule = Schedule(LocalDate.of(2026, 11, 29), listOf(Shift.DAY, Shift.NIGHT, Shift.OFF, Shift.REST))
|
|
assertEquals(Shift.NIGHT, schedule.shiftOn(LocalDate.of(2026, 11, 30)))
|
|
assertEquals(Shift.OFF, schedule.shiftOn(LocalDate.of(2026, 12, 1)))
|
|
assertEquals(Shift.REST, schedule.shiftOn(LocalDate.of(2026, 12, 2)))
|
|
assertEquals(Shift.DAY, schedule.shiftOn(LocalDate.of(2026, 12, 3)))
|
|
assertFalse(Shift.REST.working)
|
|
assertTrue(Shift.EVENING.working)
|
|
}
|
|
@Test(expected = IllegalArgumentException::class) fun oversizedCycleRejected() { Schedule(anchor, List(367) { Shift.DAY }) }
|
|
@Test fun fiveDaySaturdayKeepsDutyAndRestsOtherShifts() {
|
|
val saturday = LocalDate.of(2026, 11, 21)
|
|
Shift.entries.forEach { shift ->
|
|
assertEquals(if (shift == Shift.DUTY) Shift.DUTY else Shift.REST,
|
|
Schedule(saturday, listOf(shift), 5).shiftOn(saturday))
|
|
}
|
|
}
|
|
@Test fun saturdayRestDoesNotMoveFollowingRotation() {
|
|
val schedule = Schedule(anchor, listOf(Shift.DUTY, Shift.REGULAR, Shift.NIGHT), 5)
|
|
assertEquals(Shift.REST, schedule.shiftOn(anchor.plusDays(1)))
|
|
assertEquals(Shift.NIGHT, schedule.shiftOn(anchor.plusDays(2)))
|
|
assertEquals(Shift.DUTY, schedule.shiftOn(anchor.plusDays(3)))
|
|
}
|
|
@Test fun sixDayAndLegacySaturdayKeepOriginalDuty() {
|
|
val saturday = LocalDate.of(2026, 11, 21)
|
|
Shift.entries.forEach { shift ->
|
|
assertEquals(shift, Schedule(saturday, listOf(shift)).shiftOn(saturday))
|
|
assertEquals(shift, Schedule(saturday, listOf(shift), 6).shiftOn(saturday))
|
|
}
|
|
}
|
|
@Test fun saturdayColorsFollowWorkWeekAndHolidayWins() {
|
|
val saturday = LocalDate.of(2026, 11, 21)
|
|
val five = Schedule(anchor, Schedule.preset(3), 5)
|
|
val six = five.copy(workWeek = 6)
|
|
assertEquals(0xFFBD5163.toInt(), five.dateColor(saturday))
|
|
assertEquals(0xFF365FAD.toInt(), six.dateColor(saturday))
|
|
assertEquals(0xFFBD5163.toInt(), six.dateColor(saturday, holiday = true))
|
|
}
|
|
@Test(expected = IllegalArgumentException::class) fun invalidWorkWeekRejected() { Schedule(anchor, Schedule.preset(3), 7) }
|
|
@Test fun weekdayDutyChangesOnlyDateColor() {
|
|
val duty = Schedule(anchor, listOf(Shift.DUTY), 5, true)
|
|
listOf(LocalDate.of(2026, 11, 21), LocalDate.of(2026, 11, 22), LocalDate.of(2026, 12, 25)).forEach {
|
|
assertEquals(0xFF1D2939.toInt(), duty.dateColor(it, true))
|
|
assertEquals(Shift.DUTY, duty.shiftOn(it))
|
|
assertEquals(0xFFBD5163.toInt(), duty.copy(dutyAsWeekday = false).dateColor(it, true))
|
|
}
|
|
val sunday = LocalDate.of(2026, 11, 22)
|
|
assertEquals(0xFFBD5163.toInt(), duty.copy(pattern = listOf(Shift.OFF)).dateColor(sunday))
|
|
}
|
|
@Test fun offColorOptionDoesNotChangeRotationOrOtherShifts() {
|
|
val monday = LocalDate.of(2026, 11, 23)
|
|
val off = Schedule(monday, listOf(Shift.OFF), offAsHoliday = true)
|
|
assertEquals(0xFFBD5163.toInt(), off.dateColor(monday))
|
|
assertEquals(0xFFBD5163.toInt(), off.shiftColor(monday))
|
|
assertEquals(Shift.OFF, off.shiftOn(monday))
|
|
assertEquals(Shift.OFF.color, off.copy(offAsHoliday = false).shiftColor(monday))
|
|
assertEquals(Shift.REGULAR.color, off.copy(pattern = listOf(Shift.REGULAR)).shiftColor(monday))
|
|
assertEquals(0xFF1D2939.toInt(), off.copy(pattern = listOf(Shift.DUTY), dutyAsWeekday = true).dateColor(monday, true))
|
|
}
|
|
}
|