Unified unit test format

This commit is contained in:
Peleus 2024-04-09 22:31:48 +08:00
parent 2f439c53fd
commit 5b7bcb01b5

View File

@ -1,7 +1,6 @@
package calendar
import (
"strconv"
"testing"
"time"
@ -13,20 +12,23 @@ func TestGregorian_Year(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 2020,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Year(), "args(%v)", tt.args.g)
})
}
@ -37,20 +39,23 @@ func TestGregorian_Month(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 8,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Month(), "args(%v)", tt.args.g)
})
}
@ -61,20 +66,23 @@ func TestGregorian_Week(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 3,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Week(), "args(%v)", tt.args.g)
})
}
@ -85,20 +93,23 @@ func TestGregorian_Day(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 5,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Day(), "args(%v)", tt.args.g)
})
}
@ -109,20 +120,23 @@ func TestGregorian_Hour(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 13,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Hour(), "args(%v)", tt.args.g)
})
}
@ -133,20 +147,23 @@ func TestGregorian_Minute(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 14,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Minute(), "args(%v)", tt.args.g)
})
}
@ -157,20 +174,23 @@ func TestGregorian_Second(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want int
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: 0,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: 15,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Second(), "args(%v)", tt.args.g)
})
}
@ -181,20 +201,23 @@ func TestGregorian_String(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want string
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: "",
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: "2020-08-05 13:14:15",
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.String(), "args(%v)", tt.args.g)
})
}
@ -205,20 +228,23 @@ func TestGregorian_Location(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want string
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: "UTC",
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: "Local",
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.Location().String(), "args(%v)", tt.args.g)
})
}
@ -229,26 +255,29 @@ func TestGregorian_Date(t *testing.T) {
Time time.Time
}
tests := []struct {
name string
args args
wantYear int
wantMonth int
wantDay int
}{
{
name: "case1",
args: args{time.Time{}},
wantYear: 0,
wantMonth: 0,
wantDay: 0,
},
{
name: "case2",
args: args{time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local)},
wantYear: 2020,
wantMonth: 8,
wantDay: 5,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewGregorian(tt.args.Time)
gotYear, gotMonth, gotDay := g.Date()
assert.Equalf(t, tt.wantYear, gotYear, "Date()")
@ -263,26 +292,29 @@ func TestGregorian_Clock(t *testing.T) {
Time time.Time
}
tests := []struct {
name string
args args
wantHour int
wantMinute int
wantSecond int
}{
{
name: "case1",
args: args{time.Time{}},
wantHour: 0,
wantMinute: 0,
wantSecond: 0,
},
{
name: "case2",
args: args{time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local)},
wantHour: 13,
wantMinute: 14,
wantSecond: 15,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewGregorian(tt.args.Time)
gotHour, goMinute, gotSecond := g.Clock()
assert.Equalf(t, tt.wantHour, gotHour, "Clock()")
@ -297,20 +329,23 @@ func TestGregorian_IsZero(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want bool
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: true,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 13, 14, 15, 0, time.Local))},
want: false,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.IsZero(), "args(%v)", tt.args.g)
})
}
@ -321,24 +356,28 @@ func TestGregorian_IsLeapYear(t *testing.T) {
g Gregorian
}
tests := []struct {
name string
args args
want bool
}{
{
name: "case1",
args: args{NewGregorian(time.Time{})},
want: false,
},
{
name: "case2",
args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))},
want: true,
},
{
name: "case3",
args: args{NewGregorian(time.Date(2021, 8, 5, 0, 0, 0, 0, time.Local))},
want: false,
},
}
for index, tt := range tests {
t.Run(strconv.Itoa(index), func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.args.g.IsLeapYear(), "args(%v)", tt.args.g)
})
}