-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconv_test.go
176 lines (139 loc) · 5.43 KB
/
conv_test.go
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package DateTimeMate
import "testing"
func testConv(t *testing.T, source, target string, brief bool, correct string) {
t.Helper()
conv := NewConv(
ConvWithSource(source),
ConvWithTarget(target),
ConvWithBrief(brief))
result, err := conv.ConvertDuration()
if err != nil {
t.Error(err)
}
if result != correct {
t.Errorf("\n[computed: %v] !=\n[correct : %v]", result, correct)
}
}
func TestConvHoursMinutesSeconds(t *testing.T) {
t.Parallel()
source := "386 hours 24 minutes 36 seconds"
target := "days hours minutes seconds"
correct := "16 days 2 hours 24 minutes 36 seconds"
testConv(t, source, target, false, correct)
correct = "16D2h24m36s"
testConv(t, source, target, true, correct)
source = "-386 hours 24 minutes 36 seconds"
correct = "-16 days 2 hours 24 minutes 36 seconds"
testConv(t, source, target, false, correct)
correct = "-16D2h24m36s"
testConv(t, source, target, true, correct)
source = "2 years 26 weeks 15 days 12 hours 30 minutes 30 seconds"
target = "hours minutes seconds"
correct = "22272 hours 30 minutes 30 seconds"
testConv(t, source, target, false, correct)
source = "-2 years 26 weeks 15 days 12 hours 30 minutes 30 seconds"
correct = "-22272 hours 30 minutes 30 seconds"
testConv(t, source, target, false, correct)
}
func TestConvSeconds(t *testing.T) {
t.Parallel()
source := "1198861 seconds"
target := "days hours minutes seconds"
correct := "13 days 21 hours 1 minute 1 second"
testConv(t, source, target, false, correct)
correct = "13D21h1m1s"
testConv(t, source, target, true, correct)
source = "-1198861 seconds"
correct = "-13 days 21 hours 1 minute 1 second"
testConv(t, source, target, false, correct)
correct = "-13D21h1m1s"
testConv(t, source, target, true, correct)
source = "2 years 26 weeks 15 days 12 hours 30 minutes 30 seconds"
target = "seconds"
correct = "80181030 seconds"
testConv(t, source, target, false, correct)
correct = "80181030s"
testConv(t, source, target, true, correct)
source = "-2 years 26 weeks 15 days 12 hours 30 minutes 30 seconds"
correct = "-80181030 seconds"
testConv(t, source, target, false, correct)
correct = "-80181030s"
testConv(t, source, target, true, correct)
}
func TestConvMinutes(t *testing.T) {
t.Parallel()
source := "15682 minutes 29 seconds"
target := "weeks days hours minutes seconds"
correct := "1 week 3 days 21 hours 22 minutes 29 seconds"
testConv(t, source, target, false, correct)
source = "-15682 minutes 29 seconds"
correct = "-1 week 3 days 21 hours 22 minutes 29 seconds"
testConv(t, source, target, false, correct)
source = "15682 minutes 29 seconds"
correct = "1W3D21h22m29s"
testConv(t, source, target, true, correct)
source = "-15682 minutes 29 seconds"
correct = "-1W3D21h22m29s"
testConv(t, source, target, true, correct)
}
func TestConvSingular(t *testing.T) {
t.Parallel()
source := "694801 seconds 1 millisecond 1 microsecond 1 nanosecond"
target := "weeks days hours minutes seconds milliseconds microseconds nanoseconds"
correct := "1 week 1 day 1 hour 1 second 1 millisecond 1 microsecond 1 nanosecond"
testConv(t, source, target, false, correct)
source = "-694801 seconds 1 millisecond 1 microsecond 1 nanosecond"
correct = "-1 week 1 day 1 hour 1 second 1 millisecond 1 microsecond 1 nanosecond"
testConv(t, source, target, false, correct)
source = "694801 seconds 1 millisecond 1 microsecond 1 nanosecond"
target = "WDhms.msusns"
correct = "1W1D1h1s1ms1us1ns"
testConv(t, source, target, true, correct)
source = "-694801 seconds 1 millisecond 1 microsecond 1 nanosecond"
correct = "-1W1D1h1s1ms1us1ns"
testConv(t, source, target, true, correct)
}
func TestConvMsUsNs(t *testing.T) {
t.Parallel()
source := "4321s123456789ns"
target := "hms.msusns"
correct := "1 hour 12 minutes 1 second 123 milliseconds 456 microseconds 788 nanoseconds"
testConv(t, source, target, false, correct)
source = "-4321s123456789ns"
correct = "-1 hour 12 minutes 1 second 123 milliseconds 456 microseconds 788 nanoseconds"
testConv(t, source, target, false, correct)
source = "4321s123456789ns"
correct = "1h12m1s123ms456us788ns"
testConv(t, source, target, true, correct)
source = "-4321s123456789ns"
correct = "-1h12m1s123ms456us788ns"
testConv(t, source, target, true, correct)
source = "4321s001001001ns"
correct = "1 hour 12 minutes 1 second 1 millisecond 1 microsecond 1 nanosecond"
testConv(t, source, target, false, correct)
source = "-4321s001001001ns"
correct = "-1 hour 12 minutes 1 second 1 millisecond 1 microsecond 1 nanosecond"
testConv(t, source, target, false, correct)
source = "4321s001001001ns"
correct = "1h12m1s1ms1us1ns"
testConv(t, source, target, true, correct)
source = "-4321s001001001ns"
correct = "-1h12m1s1ms1us1ns"
testConv(t, source, target, true, correct)
}
func TestConvNanoseconds1(t *testing.T) {
t.Parallel()
source := "1234567890987654321ns"
target := "YWDhms.msusns"
correct := "39 years 6 weeks 2 days 5 hours 31 minutes 30 seconds 987 milliseconds 654 microseconds 447 nanoseconds"
testConv(t, source, target, false, correct)
source = "-1234567890987654321ns"
correct = "-39 years 6 weeks 2 days 5 hours 31 minutes 30 seconds 987 milliseconds 654 microseconds 447 nanoseconds"
testConv(t, source, target, false, correct)
source = "1234567890987654321ns"
correct = "39Y6W2D5h31m30s987ms654us447ns"
testConv(t, source, target, true, correct)
source = "-1234567890987654321ns"
correct = "-39Y6W2D5h31m30s987ms654us447ns"
testConv(t, source, target, true, correct)
}