github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/unaryops_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 operator 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/testutil" 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestUnary(t *testing.T) { 27 input := testutil.MakeInt64Vector([]int64{5, -5, 0}, []uint64{2}) 28 testProc := testutil.NewProc() 29 output, err := UnaryTilde[int64]([]*vector.Vector{input}, testProc) 30 require.NoError(t, err) 31 expected := testutil.MakeUint64Vector([]uint64{18446744073709551610, 4, 0}, []uint64{2}) 32 require.True(t, testutil.CompareVectors(expected, output), "got vector is different with expected") 33 } 34 35 func TestUnaryMinus(t *testing.T) { 36 input := testutil.MakeInt64Vector([]int64{123, 234, 345, 0}, []uint64{3}) 37 testProc := testutil.NewProc() 38 output, err := UnaryMinus[int64]([]*vector.Vector{input}, testProc) 39 require.NoError(t, err) 40 expected := testutil.MakeInt64Vector([]int64{-123, -234, -345, 0}, []uint64{3}) 41 require.True(t, testutil.CompareVectors(expected, output), "got vector is different with expected") 42 } 43 44 func TestUnaryMinusDecimal64(t *testing.T) { 45 input := testutil.MakeDecimal64Vector([]int64{123, 234, 345, 0}, []uint64{3}, testutil.MakeDecimal64Type(6, 2)) 46 testProc := testutil.NewProc() 47 output, err := UnaryMinusDecimal64([]*vector.Vector{input}, testProc) 48 require.NoError(t, err) 49 outputCol := vector.MustTCols[types.Decimal64](output) 50 expectedCol := []types.Decimal64{types.Decimal64FromInt32(-123), types.Decimal64FromInt32(-234), types.Decimal64FromInt32(-345), types.Decimal64_Zero} 51 for i, c := range outputCol { 52 require.True(t, c.Eq(expectedCol[i])) 53 } 54 } 55 56 func TestUnaryMinusDecimal128(t *testing.T) { 57 input := testutil.MakeDecimal128Vector([]int64{123, 234, 345, 0}, []uint64{3}, testutil.MakeDecimal128Type(38, 10)) 58 testProc := testutil.NewProc() 59 output, err := UnaryMinusDecimal128([]*vector.Vector{input}, testProc) 60 require.NoError(t, err) 61 outputCol := vector.MustTCols[types.Decimal128](output) 62 expectedCol := []types.Decimal128{types.Decimal128FromInt32(-123), types.Decimal128FromInt32(-234), types.Decimal128FromInt32(-345), types.Decimal128_Zero} 63 for i, c := range outputCol { 64 require.True(t, c.Eq(expectedCol[i])) 65 } 66 }