-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduration_test.go
More file actions
93 lines (90 loc) · 1.42 KB
/
duration_test.go
File metadata and controls
93 lines (90 loc) · 1.42 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package hdur
import (
"testing"
)
func TestDuration_Normalize(t *testing.T) {
tests := []struct {
name string
input Duration
expected Duration
}{
{
name: "normalize seconds",
input: Duration{
Seconds: 65,
},
expected: Duration{
Minutes: 1,
Seconds: 5,
},
},
{
name: "normalize minutes",
input: Duration{
Minutes: 125,
},
expected: Duration{
Hours: 2,
Minutes: 5,
},
},
{
name: "normalize hours",
input: Duration{
Hours: 25,
},
expected: Duration{
Days: 1,
Hours: 1,
},
},
{
name: "normalize months",
input: Duration{
Months: 14,
},
expected: Duration{
Years: 1,
Months: 2,
},
},
{
name: "normalize nanoseconds",
input: Duration{
Nanos: 1500000000, // 1.5 seconds in nanoseconds
},
expected: Duration{
Seconds: 1,
Nanos: 500000000,
},
},
{
name: "normalize complex",
input: Duration{
Months: 25,
Days: 45,
Hours: 30,
Minutes: 70,
Seconds: 75,
Nanos: 2500000000,
},
expected: Duration{
Years: 2,
Months: 1,
Days: 46,
Hours: 7,
Minutes: 11,
Seconds: 17,
Nanos: 500000000,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.input.normalize()
if tt.input != tt.expected {
t.Errorf("normalize() got = %v, want %v", tt.input, tt.expected)
}
})
}
}