github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/day/day_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 day 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestDateToDay(t *testing.T) { 25 cases := []struct { 26 name string 27 inputDate []types.Date 28 expected []uint8 29 }{ 30 { 31 name: "Date to day test", 32 inputDate: []types.Date{ 33 types.DateFromCalendar(2022, 1, 1), 34 types.DateFromCalendar(2022, 2, 28), 35 types.DateFromCalendar(2022, 3, 3), 36 types.DateFromCalendar(2022, 4, 11), 37 types.DateFromCalendar(2022, 6, 18), 38 types.DateFromCalendar(2022, 8, 22), 39 types.DateFromCalendar(2022, 9, 25), 40 types.DateFromCalendar(2022, 12, 31), 41 }, 42 expected: []uint8{1, 28, 03, 11, 18, 22, 25, 31}, 43 }, 44 } 45 46 for _, c := range cases { 47 t.Run(c.name, func(t *testing.T) { 48 result := make([]uint8, len(c.inputDate)) 49 require.Equal(t, c.expected, DateToDay(c.inputDate, result)) 50 }) 51 } 52 } 53 54 func TestDatetimeToDay(t *testing.T) { 55 cases := []struct { 56 name string 57 inputDatetime []types.Datetime 58 expected []uint8 59 }{ 60 { 61 name: "Datetime to day test", 62 inputDatetime: []types.Datetime{ 63 types.DatetimeFromClock(2022, 1, 1, 0, 0, 0, 0), 64 types.DatetimeFromClock(2022, 2, 28, 0, 0, 0, 0), 65 types.DatetimeFromClock(2022, 3, 3, 0, 0, 0, 0), 66 types.DatetimeFromClock(2022, 4, 11, 0, 0, 0, 0), 67 types.DatetimeFromClock(2022, 6, 18, 0, 0, 0, 0), 68 types.DatetimeFromClock(2022, 8, 22, 0, 0, 0, 0), 69 types.DatetimeFromClock(2022, 9, 25, 0, 0, 0, 0), 70 types.DatetimeFromClock(2022, 12, 31, 0, 0, 0, 0), 71 }, 72 expected: []uint8{1, 28, 03, 11, 18, 22, 25, 31}, 73 }, 74 } 75 76 for _, c := range cases { 77 t.Run(c.name, func(t *testing.T) { 78 result := make([]uint8, len(c.inputDatetime)) 79 require.Equal(t, c.expected, DatetimeToDay(c.inputDatetime, result)) 80 }) 81 } 82 }