이벤트 가져오기 위젯 테스트 추가 및 테스트 훅 도입

This commit is contained in:
2025-09-12 06:33:44 +09:00
parent 107abc963f
commit a5f2544d11
121 changed files with 39277 additions and 3911 deletions
-113
View File
@@ -177,100 +177,6 @@ class TieBreakerUtil {
});
}
/// 동점자 그룹 찾기
static Map<int, List<Score>> _findTiedGroups(List<Score> sortedScores, bool includeHandicap) {
Map<int, List<Score>> tiedGroups = {};
for (int i = 0; i < sortedScores.length; i++) {
int currentScore = includeHandicap
? (sortedScores[i].totalScore + (sortedScores[i].handicap ?? 0))
: sortedScores[i].totalScore;
List<Score> sameScores = [sortedScores[i]];
// 같은 점수를 가진 항목 찾기
for (int j = i + 1; j < sortedScores.length; j++) {
int nextScore = includeHandicap
? (sortedScores[j].totalScore + (sortedScores[j].handicap ?? 0))
: sortedScores[j].totalScore;
if (currentScore == nextScore) {
sameScores.add(sortedScores[j]);
i = j; // 이미 처리한 항목 건너뛰기
} else {
break; // 다른 점수 발견 시 중단
}
}
// 동점자가 2명 이상인 경우만 그룹에 추가
if (sameScores.length > 1) {
tiedGroups[currentScore] = sameScores;
}
}
return tiedGroups;
}
/// 동점자 처리 옵션 적용
static List<Score> _applyTieBreakerOption(
List<Score> tiedScores,
TieBreakerOption option,
List<Member>? members,
bool includeHandicap
) {
switch (option) {
case TieBreakerOption.lowerHandicap:
return _sortByLowerHandicap(tiedScores);
case TieBreakerOption.lowerScoreGap:
return _sortByLowerScoreGap(tiedScores);
case TieBreakerOption.olderAge:
return _sortByOlderAge(tiedScores, members);
case TieBreakerOption.none:
return tiedScores; // 변경 없음
}
}
/// 핸디캡이 적은 순으로 정렬
static List<Score> _sortByLowerHandicap(List<Score> tiedScores) {
return List.from(tiedScores)..sort((a, b) {
int handicapA = a.handicap ?? 0;
int handicapB = b.handicap ?? 0;
return handicapA.compareTo(handicapB); // 오름차순 (적은 것이 우선)
});
}
/// 점수 격차가 적은 순으로 정렬
static List<Score> _sortByLowerScoreGap(List<Score> tiedScores) {
return List.from(tiedScores)..sort((a, b) {
// 프레임 점수 중 최고점과 최저점의 차이 계산
int gapA = _calculateScoreGap(a.frames);
int gapB = _calculateScoreGap(b.frames);
return gapA.compareTo(gapB); // 오름차순 (격차가 적은 것이 우선)
});
}
/// 연장자 우선으로 정렬
static List<Score> _sortByOlderAge(List<Score> tiedScores, List<Member>? members) {
if (members == null || members.isEmpty) return tiedScores;
return List.from(tiedScores)..sort((a, b) {
// 회원 정보에서 생년월일 찾기
DateTime? birthDateA = _findMemberBirthDate(a.memberId, members);
DateTime? birthDateB = _findMemberBirthDate(b.memberId, members);
// 생년월일이 없으면 정렬 불가
if (birthDateA == null || birthDateB == null) return 0;
// 생년월일 비교 (오래된 날짜 = 연장자가 우선)
// 연장자가 우선이므로 더 오래된 날짜(더 작은 값)가 앞에 와야 함
// 연장자 우선이므로 더 오래된 날짜(A)가 더 최근 날짜(B)보다 앞에 와야 함
return birthDateA.compareTo(birthDateB); // 오름차순 정렬로 연장자 우선
});
}
/// 회원 ID로 생년월일 찾기
static DateTime? _findMemberBirthDate(String? memberId, List<Member> members) {
if (memberId == null) return null;
@@ -293,25 +199,6 @@ class TieBreakerUtil {
return max - min;
}
/// 모든 점수가 서로 다른지 확인
static bool _allScoresHaveDifferentValues(List<Score> scores, bool includeHandicap) {
Set<int> uniqueScores = {};
for (var score in scores) {
int totalScore = includeHandicap
? (score.totalScore + (score.handicap ?? 0))
: score.totalScore;
if (uniqueScores.contains(totalScore)) {
return false;
}
uniqueScores.add(totalScore);
}
return true;
}
/// 정렬된 동점자 그룹으로 원래 목록 업데이트
static Map<String, int> calculateRanks(
List<Score> scores,