github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/function/func_compare_test.go (about) 1 // Copyright 2021 - 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 function 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 "github.com/matrixorigin/matrixone/pkg/testutil" 20 "github.com/stretchr/testify/require" 21 "testing" 22 ) 23 24 func TestOperatorOpBitAndInt64Fn(t *testing.T) { 25 // 1 & 2 = 0 26 // -1 & 2 = 2 27 // null & 2 = null 28 tc := tcTemp{ 29 info: "& test", 30 inputs: []testutil.FunctionTestInput{ 31 testutil.NewFunctionTestInput(types.T_int64.ToType(), 32 []int64{1, -1, 0}, []bool{false, false, true}), 33 testutil.NewFunctionTestInput(types.T_int64.ToType(), 34 []int64{2, 2, 2}, []bool{false, false, false}), 35 }, 36 expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false, 37 []int64{0, 2, 0}, []bool{false, false, true}), 38 } 39 40 proc := testutil.NewProcess() 41 fcTC := testutil.NewFunctionTestCase(proc, 42 tc.inputs, tc.expect, operatorOpBitAndInt64Fn) 43 s, info := fcTC.Run() 44 require.True(t, s, info) 45 } 46 47 func TestOperatorOpBitOrInt64Fn(t *testing.T) { 48 // 1 | 2 = 3 49 // -1 | 2 = -1 50 // null | 2 = null 51 tc := tcTemp{ 52 info: "| test", 53 inputs: []testutil.FunctionTestInput{ 54 testutil.NewFunctionTestInput(types.T_int64.ToType(), 55 []int64{1, -1, 0}, []bool{false, false, true}), 56 testutil.NewFunctionTestInput(types.T_int64.ToType(), 57 []int64{2, 2, 2}, []bool{false, false, false}), 58 }, 59 expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false, 60 []int64{3, -1, 0}, []bool{false, false, true}), 61 } 62 63 proc := testutil.NewProcess() 64 fcTC := testutil.NewFunctionTestCase(proc, 65 tc.inputs, tc.expect, operatorOpBitOrInt64Fn) 66 s, info := fcTC.Run() 67 require.True(t, s, info) 68 } 69 70 func TestOperatorOpBitXorInt64Fn(t *testing.T) { 71 // 1 ^ 2 = 3 72 // -1 ^ 2 = -3 73 // null ^ 2 = null 74 tc := tcTemp{ 75 info: "^ test", 76 inputs: []testutil.FunctionTestInput{ 77 testutil.NewFunctionTestInput(types.T_int64.ToType(), 78 []int64{1, -1, 0}, []bool{false, false, true}), 79 testutil.NewFunctionTestInput(types.T_int64.ToType(), 80 []int64{2, 2, 2}, []bool{false, false, false}), 81 }, 82 expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false, 83 []int64{3, -3, 0}, []bool{false, false, true}), 84 } 85 86 proc := testutil.NewProcess() 87 fcTC := testutil.NewFunctionTestCase(proc, 88 tc.inputs, tc.expect, operatorOpBitXorInt64Fn) 89 s, info := fcTC.Run() 90 require.True(t, s, info) 91 } 92 93 func TestOperatorOpBitRightShiftInt64Fn(t *testing.T) { 94 // 1024 >> 2 = 256 95 // -5 >> 2 = -2 96 // 2 >> -2 = 0 97 // null >> 2 = null 98 tc := tcTemp{ 99 info: ">> test", 100 inputs: []testutil.FunctionTestInput{ 101 testutil.NewFunctionTestInput(types.T_int64.ToType(), 102 []int64{1024, -5, 2, 0}, []bool{false, false, false, true}), 103 testutil.NewFunctionTestInput(types.T_int64.ToType(), 104 []int64{2, 2, -2, 2}, []bool{false, false, false, true}), 105 }, 106 expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false, 107 []int64{256, -2, 0, 0}, []bool{false, false, false, true}), 108 } 109 110 proc := testutil.NewProcess() 111 fcTC := testutil.NewFunctionTestCase(proc, 112 tc.inputs, tc.expect, operatorOpBitShiftRightInt64Fn) 113 s, info := fcTC.Run() 114 require.True(t, s, info) 115 } 116 117 func TestOperatorOpBitLeftShiftInt64Fn(t *testing.T) { 118 // -1 << 2 = 4 119 // -1 << 2 = -4 120 // 2 << -2 = 0 121 // null << 2 = null 122 tc := tcTemp{ 123 info: ">> test", 124 inputs: []testutil.FunctionTestInput{ 125 testutil.NewFunctionTestInput(types.T_int64.ToType(), 126 []int64{1, -1, 2, 0}, []bool{false, false, false, true}), 127 testutil.NewFunctionTestInput(types.T_int64.ToType(), 128 []int64{2, 2, -2, 2}, []bool{false, false, false, true}), 129 }, 130 expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false, 131 []int64{4, -4, 0, 0}, []bool{false, false, false, true}), 132 } 133 134 proc := testutil.NewProcess() 135 fcTC := testutil.NewFunctionTestCase(proc, 136 tc.inputs, tc.expect, operatorOpBitShiftLeftInt64Fn) 137 s, info := fcTC.Run() 138 require.True(t, s, info) 139 }