代码拉取完成,页面将自动刷新
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())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。