github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/weekday/weekday_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package weekday 16 17 import ( 18 "reflect" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 ) 23 24 func ParseDateCast(s string) types.Date { 25 date, _ := types.ParseDateCast(s) 26 return date 27 } 28 29 func parseDatetime(s string) types.Datetime { 30 datetime, _ := types.ParseDatetime(s, 6) 31 return datetime 32 } 33 34 func TestDateToWeekday(t *testing.T) { 35 type args struct { 36 xs []types.Date 37 rs []int64 38 } 39 tests := []struct { 40 name string 41 args args 42 want []int64 43 }{ 44 { 45 name: "normal date test", 46 args: args{ 47 xs: []types.Date{ 48 ParseDateCast("2022-01-01"), 49 ParseDateCast("2022-01-02"), 50 ParseDateCast("2022-01-03"), 51 ParseDateCast("2022-01-04"), 52 ParseDateCast("2022-01-05"), 53 ParseDateCast("2022-01-06"), 54 ParseDateCast("2022-01-07"), 55 ParseDateCast("2022-01-08"), 56 }, 57 rs: make([]int64, 8), 58 }, 59 want: []int64{5, 6, 0, 1, 2, 3, 4, 5}, 60 }, 61 } 62 63 for _, tt := range tests { 64 t.Run(tt.name, func(t *testing.T) { 65 if got := DateToWeekday(tt.args.xs, tt.args.rs); !reflect.DeepEqual(got, tt.want) { 66 t.Errorf("DateToWeekday() = %v, want %v", got, tt.want) 67 } 68 }) 69 } 70 } 71 72 func TestDatetimeToWeekday(t *testing.T) { 73 type args struct { 74 xs []types.Datetime 75 rs []int64 76 } 77 tests := []struct { 78 name string 79 args args 80 want []int64 81 }{ 82 { 83 name: "normal datetime test", 84 args: args{ 85 xs: []types.Datetime{ 86 parseDatetime("2022-01-01 22:23:00"), 87 parseDatetime("2022-01-02 22:23:00"), 88 parseDatetime("2022-01-03 22:23:00"), 89 parseDatetime("2022-01-04 22:23:00"), 90 parseDatetime("2022-01-05 22:23:00"), 91 parseDatetime("2022-01-06 22:23:00"), 92 parseDatetime("2022-01-07 22:23:00"), 93 parseDatetime("2022-01-08 22:23:00"), 94 }, 95 rs: make([]int64, 8), 96 }, 97 want: []int64{5, 6, 0, 1, 2, 3, 4, 5}, 98 }, 99 } 100 101 for _, tt := range tests { 102 t.Run(tt.name, func(t *testing.T) { 103 if got := DatetimeToWeekday(tt.args.xs, tt.args.rs); !reflect.DeepEqual(got, tt.want) { 104 t.Errorf("DatetimeToWeekday() = %v, want %v", got, tt.want) 105 } 106 }) 107 } 108 }