-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain_test.go
More file actions
77 lines (74 loc) · 1.9 KB
/
Copy pathmain_test.go
File metadata and controls
77 lines (74 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"git-metrics/pkg/utils"
"testing"
"time"
)
func TestCalculateYearsMonthsDays(t *testing.T) {
tests := []struct {
name string
start time.Time
end time.Time
wantYears int
wantMonths int
wantDays int
}{
{
name: "Same day",
start: time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC),
end: time.Date(2023, 1, 1, 15, 0, 0, 0, time.UTC),
wantYears: 0,
wantMonths: 0,
wantDays: 0,
},
{
name: "Few days",
start: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
end: time.Date(2023, 1, 5, 0, 0, 0, 0, time.UTC),
wantYears: 0,
wantMonths: 0,
wantDays: 4,
},
{
name: "One month",
start: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
end: time.Date(2023, 2, 1, 0, 0, 0, 0, time.UTC),
wantYears: 0,
wantMonths: 1,
wantDays: 0,
},
{
name: "One year",
start: time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC),
end: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
wantYears: 1,
wantMonths: 0,
wantDays: 0,
},
{
name: "Complex case",
start: time.Date(2022, 1, 15, 0, 0, 0, 0, time.UTC),
end: time.Date(2023, 3, 20, 0, 0, 0, 0, time.UTC),
wantYears: 1,
wantMonths: 2,
wantDays: 5,
},
{
name: "Month boundary",
start: time.Date(2023, 1, 31, 0, 0, 0, 0, time.UTC),
end: time.Date(2023, 3, 1, 0, 0, 0, 0, time.UTC),
wantYears: 0,
wantMonths: 1,
wantDays: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
years, months, days := utils.CalculateYearsMonthsDays(tt.start, tt.end)
if years != tt.wantYears || months != tt.wantMonths || days != tt.wantDays {
t.Errorf("calculateYMD() = %v years, %v months, %v days; want %v years, %v months, %v days",
years, months, days, tt.wantYears, tt.wantMonths, tt.wantDays)
}
})
}
}