github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/date/date_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 date
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  )
    22  
    23  func TestDateTimeToDate(t *testing.T) {
    24  	testCases := []struct {
    25  		name string
    26  		args []types.Datetime
    27  		want []types.Date
    28  	}{
    29  		{
    30  			args: []types.Datetime{types.DatetimeFromClock(2022, 3, 30, 20, 20, 20, 20)},
    31  			want: []types.Date{types.DateFromCalendar(2022, 3, 30)},
    32  		},
    33  	}
    34  
    35  	for _, v := range testCases {
    36  		reply := make([]types.Date, len(v.args))
    37  		actual := DatetimeToDate(v.args, reply)
    38  
    39  		if !isEqual(actual, v.want) {
    40  			t.Errorf("expect the %v, but got %v", v.want, actual)
    41  		}
    42  	}
    43  }
    44  
    45  func isEqual(a, b []types.Date) bool {
    46  
    47  	if len(a) != len(b) {
    48  		return false
    49  	}
    50  
    51  	for i := 0; i < len(a); i++ {
    52  		if a[i] != b[i] {
    53  			return false
    54  		}
    55  	}
    56  	return true
    57  }