|
@ -1,6 +1,7 @@ |
|
|
package time_arrow |
|
|
package time_arrow |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"reflect" |
|
|
"testing" |
|
|
"testing" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
@ -310,3 +311,238 @@ func TestGetHitTimeArrow(t *testing.T) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Test_isInDayOfMonth(t *testing.T) { |
|
|
|
|
|
type args struct { |
|
|
|
|
|
t time.Time |
|
|
|
|
|
ta TimeArrow |
|
|
|
|
|
} |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
args args |
|
|
|
|
|
want bool |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
if got := isInDayOfMonth(tt.args.t, tt.args.ta); got != tt.want { |
|
|
|
|
|
t.Errorf("isInDayOfMonth() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Test_isInHolidays(t *testing.T) { |
|
|
|
|
|
GetHolidaysData = func() (items []HolidaysItem, e error) { |
|
|
|
|
|
start, _ := time.Parse("2006-01-02 15:04:05", "2020-10-01 00:00:00") |
|
|
|
|
|
end, _ := time.Parse("2006-01-02 15:04:05", "2020-10-07 23:59:59") |
|
|
|
|
|
return []HolidaysItem{ |
|
|
|
|
|
{ |
|
|
|
|
|
Name: "国庆节", |
|
|
|
|
|
Start: start, |
|
|
|
|
|
End: end, |
|
|
|
|
|
}, |
|
|
|
|
|
}, nil |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ := time.Parse("2006-01-02 15:04:05", "2020-10-03 11:00:00") |
|
|
|
|
|
if !isInHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-10-08 11:00:00") |
|
|
|
|
|
if isInHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-09-08 11:00:00") |
|
|
|
|
|
if isInHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Test_isInAtLastDayHolidays(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
GetHolidaysData = func() (items []HolidaysItem, e error) { |
|
|
|
|
|
start, _ := time.Parse("2006-01-02 15:04:05", "2020-10-01 00:00:00") |
|
|
|
|
|
end, _ := time.Parse("2006-01-02 15:04:05", "2020-10-07 23:59:59") |
|
|
|
|
|
return []HolidaysItem{ |
|
|
|
|
|
{ |
|
|
|
|
|
Name: "国庆节", |
|
|
|
|
|
Start: start, |
|
|
|
|
|
End: end, |
|
|
|
|
|
}, |
|
|
|
|
|
}, nil |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ := time.Parse("2006-01-02 15:04:05", "2020-10-03 11:00:00") |
|
|
|
|
|
if isInAtLastDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-10-08 11:00:00") |
|
|
|
|
|
if isInAtLastDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-09-08 11:00:00") |
|
|
|
|
|
if isInAtLastDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-10-07 11:00:00") |
|
|
|
|
|
if !isInAtLastDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Test_isInPriorToDayHolidays(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
GetHolidaysData = func() (items []HolidaysItem, e error) { |
|
|
|
|
|
start, _ := time.Parse("2006-01-02 15:04:05", "2020-10-01 00:00:00") |
|
|
|
|
|
end, _ := time.Parse("2006-01-02 15:04:05", "2020-10-07 23:59:59") |
|
|
|
|
|
return []HolidaysItem{ |
|
|
|
|
|
{ |
|
|
|
|
|
Name: "国庆节", |
|
|
|
|
|
Start: start, |
|
|
|
|
|
End: end, |
|
|
|
|
|
}, |
|
|
|
|
|
}, nil |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ := time.Parse("2006-01-02 15:04:05", "2020-10-03 11:00:00") |
|
|
|
|
|
if isInPriorToDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-10-08 11:00:00") |
|
|
|
|
|
if isInPriorToDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-09-08 11:00:00") |
|
|
|
|
|
if isInPriorToDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
tt, _ = time.Parse("2006-01-02 15:04:05", "2020-09-30 11:00:00") |
|
|
|
|
|
if !isInPriorToDayHolidays(tt) { |
|
|
|
|
|
t.Fatal("error") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Test_createUUID(t *testing.T) { |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
want string |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
if got := createUUID(); got != tt.want { |
|
|
|
|
|
t.Errorf("createUUID() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCreateDayOfWeekTypePlan(t *testing.T) { |
|
|
|
|
|
type args struct { |
|
|
|
|
|
group string |
|
|
|
|
|
dayOfWeek []int |
|
|
|
|
|
timesOnDay []string |
|
|
|
|
|
expandValue interface{} |
|
|
|
|
|
expandTags []string |
|
|
|
|
|
weights float64 |
|
|
|
|
|
} |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
args args |
|
|
|
|
|
want TimeArrow |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
if got := CreateDayOfWeekTypePlan(tt.args.group, tt.args.dayOfWeek, tt.args.timesOnDay, tt.args.expandValue, tt.args.expandTags, tt.args.weights); !reflect.DeepEqual(got, tt.want) { |
|
|
|
|
|
t.Errorf("CreateDayOfWeekTypePlan() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCreateDayOfMonthTypePlan(t *testing.T) { |
|
|
|
|
|
type args struct { |
|
|
|
|
|
group string |
|
|
|
|
|
dayOfMonth []int |
|
|
|
|
|
timesOnDay []string |
|
|
|
|
|
expandValue interface{} |
|
|
|
|
|
expandTags []string |
|
|
|
|
|
weights float64 |
|
|
|
|
|
} |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
args args |
|
|
|
|
|
want TimeArrow |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
if got := CreateDayOfMonthTypePlan(tt.args.group, tt.args.dayOfMonth, tt.args.timesOnDay, tt.args.expandValue, tt.args.expandTags, tt.args.weights); !reflect.DeepEqual(got, tt.want) { |
|
|
|
|
|
t.Errorf("CreateDayOfMonthTypePlan() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCreateDateSliceTypePlan(t *testing.T) { |
|
|
|
|
|
type args struct { |
|
|
|
|
|
group string |
|
|
|
|
|
dateSlice []DateSlice |
|
|
|
|
|
timesOnDay []string |
|
|
|
|
|
expandValue interface{} |
|
|
|
|
|
expandTags []string |
|
|
|
|
|
weights float64 |
|
|
|
|
|
} |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
args args |
|
|
|
|
|
want TimeArrow |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
if got := CreateDateSliceTypePlan(tt.args.group, tt.args.dateSlice, tt.args.timesOnDay, tt.args.expandValue, tt.args.expandTags, tt.args.weights); !reflect.DeepEqual(got, tt.want) { |
|
|
|
|
|
t.Errorf("CreateDateSliceTypePlan() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestTimeArrowHelper_GetHitTimeArrow(t *testing.T) { |
|
|
|
|
|
type fields struct { |
|
|
|
|
|
GetData func(group string) (TimeArrows, error) |
|
|
|
|
|
} |
|
|
|
|
|
type args struct { |
|
|
|
|
|
t time.Time |
|
|
|
|
|
group string |
|
|
|
|
|
expandTags []string |
|
|
|
|
|
} |
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
name string |
|
|
|
|
|
fields fields |
|
|
|
|
|
args args |
|
|
|
|
|
want *TimeArrow |
|
|
|
|
|
wantErr bool |
|
|
|
|
|
}{ |
|
|
|
|
|
// TODO: Add test cases.
|
|
|
|
|
|
} |
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
th := &TimeArrowHelper{ |
|
|
|
|
|
GetData: tt.fields.GetData, |
|
|
|
|
|
} |
|
|
|
|
|
got, err := th.GetHitTimeArrow(tt.args.t, tt.args.group, tt.args.expandTags...) |
|
|
|
|
|
if (err != nil) != tt.wantErr { |
|
|
|
|
|
t.Errorf("TimeArrowHelper.GetHitTimeArrow() error = %v, wantErr %v", err, tt.wantErr) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if !reflect.DeepEqual(got, tt.want) { |
|
|
|
|
|
t.Errorf("TimeArrowHelper.GetHitTimeArrow() = %v, want %v", got, tt.want) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |