Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions internal/scorer/scorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func setupGitRepo(t *testing.T, years, months int) (string, string) {
t.Fatalf("write file failed: %v", err)
}

commitDate := time.Now().AddDate(years, months, 0).Format(time.RFC3339)
commitDate := gitAgeBonusAnchor(years, months)
env := append(os.Environ(),
"GIT_AUTHOR_DATE="+commitDate,
"GIT_COMMITTER_DATE="+commitDate,
Expand Down Expand Up @@ -396,35 +396,42 @@ func TestFromL5Conversion(t *testing.T) {
}

// Git age bonus helper edge cases.
// The anchor day exists in every month and is never later than today's day.
func gitAgeBonusAnchor(years, months int) string {
now := time.Now()
safeDay := now.Day()
if safeDay > 28 {
safeDay = 28
}
anchor := time.Date(now.Year(), now.Month(), safeDay, 0, 0, 0, 0, now.Location())
return anchor.AddDate(years, months, 0).Format(time.RFC3339)
}

func TestGitAgeBonusExact24Months(t *testing.T) {
// Spec says >24 months for +10. Exactly 24 months qualifies for +5 (>12).
date := time.Now().AddDate(-2, 0, 0).Format(time.RFC3339)
bonus := gitAgeBonus(date)
bonus := gitAgeBonus(gitAgeBonusAnchor(-2, 0))
if bonus != 5 {
t.Errorf("expected bonus 5 for exactly 24 months, got %d", bonus)
}
}

func TestGitAgeBonusExact12Months(t *testing.T) {
// Spec says >12 months for +5. Exactly 12 months gets 0.
date := time.Now().AddDate(-1, 0, 0).Format(time.RFC3339)
bonus := gitAgeBonus(date)
bonus := gitAgeBonus(gitAgeBonusAnchor(-1, 0))
if bonus != 0 {
t.Errorf("expected bonus 0 for exactly 12 months, got %d", bonus)
}
}

func TestGitAgeBonus11Months(t *testing.T) {
date := time.Now().AddDate(0, -11, 0).Format(time.RFC3339)
bonus := gitAgeBonus(date)
bonus := gitAgeBonus(gitAgeBonusAnchor(0, -11))
if bonus != 0 {
t.Errorf("expected bonus 0 for 11 months, got %d", bonus)
}
}

func TestGitAgeBonus13Months(t *testing.T) {
date := time.Now().AddDate(-1, -1, 0).Format(time.RFC3339)
bonus := gitAgeBonus(date)
bonus := gitAgeBonus(gitAgeBonusAnchor(-1, -1))
if bonus != 5 {
t.Errorf("expected bonus 5 for 13 months, got %d", bonus)
}
Expand Down
Loading