-
-
Notifications
You must be signed in to change notification settings - Fork 244
/
extremum_unit_test.go
executable file
·142 lines (136 loc) · 2.88 KB
/
extremum_unit_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
package carbon
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCarbon_Closest(t *testing.T) {
tests := []struct {
name string
carbon1 Carbon
carbon2 Carbon
carbon3 Carbon
want string
}{
{
name: "case1",
carbon1: Parse(""),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-04-16"),
want: "2023-03-28",
},
{
name: "case2",
carbon1: Parse("2023-04-01"),
carbon2: Parse(""),
carbon3: Parse("2023-04-16"),
want: "2023-04-16",
},
{
name: "case3",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse(""),
want: "2023-03-28",
},
{
name: "case4",
carbon1: Parse("2023-04-01"),
carbon2: Parse(""),
carbon3: Parse(""),
want: "",
},
{
name: "case5",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-03-28"),
want: "2023-03-28",
},
{
name: "case6",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-04-16"),
want: "2023-03-28",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon1.Closest(tt.carbon2, tt.carbon3).ToDateString(), "Closest()")
})
}
}
func TestCarbon_Farthest(t *testing.T) {
tests := []struct {
name string
carbon1 Carbon
carbon2 Carbon
carbon3 Carbon
want string
}{
{
name: "case1",
carbon1: Parse(""),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-04-16"),
want: "2023-04-16",
},
{
name: "case2",
carbon1: Parse("2023-04-01"),
carbon2: Parse(""),
carbon3: Parse("2023-04-16"),
want: "2023-04-16",
},
{
name: "case3",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse(""),
want: "2023-03-28",
},
{
name: "case4",
carbon1: Parse("2023-04-01"),
carbon2: Parse(""),
carbon3: Parse(""),
want: "",
},
{
name: "case5",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-03-28"),
want: "2023-03-28",
},
{
name: "case6",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-03-28"),
carbon3: Parse("2023-03-28"),
want: "2023-03-28",
},
{
name: "case7",
carbon1: Parse("2023-04-01"),
carbon2: Parse("2023-04-05"),
carbon3: Parse("2023-04-02"),
want: "2023-04-05",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon1.Farthest(tt.carbon2, tt.carbon3).ToDateString(), "Farthest()")
})
}
}
func TestCarbon_Max(t *testing.T) {
now := Now()
max := Max(now.SubDay(), now, now.AddDay())
assert.Equal(t, now.AddDay().Timestamp(), max.Timestamp())
}
func TestCarbon_Min(t *testing.T) {
now := Now()
min := Min(now, now.SubDay(), now.AddDay())
assert.Equal(t, now.SubDay().Timestamp(), min.Timestamp())
}