forked from samber/lo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
149 lines (133 loc) · 3.94 KB
/
time_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
package lo
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDuration(t *testing.T) {
t.Parallel()
is := assert.New(t)
result := Duration(func() { time.Sleep(10 * time.Millisecond) })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
}
func TestDurationX(t *testing.T) {
t.Parallel()
is := assert.New(t)
{
result := Duration0(func() { time.Sleep(10 * time.Millisecond) })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
}
{
a, result := Duration1(func() string { time.Sleep(10 * time.Millisecond); return "a" })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
}
{
a, b, result := Duration2(func() (string, string) { time.Sleep(10 * time.Millisecond); return "a", "b" })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
}
{
a, b, c, result := Duration3(func() (string, string, string) { time.Sleep(10 * time.Millisecond); return "a", "b", "c" })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
}
{
a, b, c, d, result := Duration4(func() (string, string, string, string) { time.Sleep(10 * time.Millisecond); return "a", "b", "c", "d" })
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
}
{
a, b, c, d, e, result := Duration5(func() (string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
}
{
a, b, c, d, e, f, result := Duration6(func() (string, string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e", "f"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
is.Equal("f", f)
}
{
a, b, c, d, e, f, g, result := Duration7(func() (string, string, string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e", "f", "g"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
is.Equal("f", f)
is.Equal("g", g)
}
{
a, b, c, d, e, f, g, h, result := Duration8(func() (string, string, string, string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e", "f", "g", "h"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
is.Equal("f", f)
is.Equal("g", g)
is.Equal("h", h)
}
{
a, b, c, d, e, f, g, h, i, result := Duration9(func() (string, string, string, string, string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e", "f", "g", "h", "i"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
is.Equal("f", f)
is.Equal("g", g)
is.Equal("h", h)
is.Equal("i", i)
}
{
a, b, c, d, e, f, g, h, i, j, result := Duration10(func() (string, string, string, string, string, string, string, string, string, string) {
time.Sleep(10 * time.Millisecond)
return "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"
})
is.InEpsilon(10*time.Millisecond, result, float64(2*time.Millisecond))
is.Equal("a", a)
is.Equal("b", b)
is.Equal("c", c)
is.Equal("d", d)
is.Equal("e", e)
is.Equal("f", f)
is.Equal("g", g)
is.Equal("h", h)
is.Equal("i", i)
is.Equal("j", j)
}
}