github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/unary/bin_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 unary 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/container/vector" 21 "github.com/matrixorigin/matrixone/pkg/testutil" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestBinUint8(t *testing.T) { 26 procs := testutil.NewProc() 27 28 as := []uint8{2, 4, 6, 8, 16, 32, 64, 128} 29 vecs := make([]*vector.Vector, 1) 30 vecs[0] = testutil.MakeUint8Vector(as, nil) 31 32 resultV, err := Bin[uint8](vecs, procs) 33 vecLen := int64(vector.Length(resultV)) 34 if err != nil { 35 panic(err) 36 } 37 tempC := make([]string, 8) 38 39 i := int64(0) 40 for ; i < vecLen; i++ { 41 tempC[i] = resultV.GetString(i) 42 } 43 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 44 } 45 46 func TestBinUint16(t *testing.T) { 47 procs := testutil.NewProc() 48 49 as := []uint16{2, 4, 6, 8, 16, 32, 64, 128} 50 vecs := make([]*vector.Vector, 1) 51 vecs[0] = testutil.MakeUint16Vector(as, nil) 52 53 resultV, err := Bin[uint16](vecs, procs) 54 vecLen := int64(vector.Length(resultV)) 55 if err != nil { 56 panic(err) 57 } 58 tempC := make([]string, 8) 59 60 i := int64(0) 61 for ; i < vecLen; i++ { 62 tempC[i] = resultV.GetString(i) 63 } 64 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 65 } 66 67 func TestBinUint32(t *testing.T) { 68 procs := testutil.NewProc() 69 70 as := []uint32{2, 4, 6, 8, 16, 32, 64, 128} 71 vecs := make([]*vector.Vector, 1) 72 vecs[0] = testutil.MakeUint32Vector(as, nil) 73 74 resultV, err := Bin[uint32](vecs, procs) 75 vecLen := int64(vector.Length(resultV)) 76 if err != nil { 77 panic(err) 78 } 79 tempC := make([]string, 8) 80 81 i := int64(0) 82 for ; i < vecLen; i++ { 83 tempC[i] = resultV.GetString(i) 84 } 85 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 86 } 87 func TestBinUint64(t *testing.T) { 88 procs := testutil.NewProc() 89 90 as := []uint64{2, 4, 6, 8, 16, 32, 64, 128} 91 vecs := make([]*vector.Vector, 1) 92 vecs[0] = testutil.MakeUint64Vector(as, nil) 93 94 resultV, err := Bin[uint64](vecs, procs) 95 vecLen := int64(vector.Length(resultV)) 96 if err != nil { 97 panic(err) 98 } 99 tempC := make([]string, 8) 100 101 i := int64(0) 102 for ; i < vecLen; i++ { 103 tempC[i] = resultV.GetString(i) 104 } 105 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 106 } 107 108 func TestBinInt8(t *testing.T) { 109 procs := testutil.NewProc() 110 111 as := []int8{2, 4, 6, 8, 16, 32, 64} 112 vecs := make([]*vector.Vector, 1) 113 vecs[0] = testutil.MakeInt8Vector(as, nil) 114 115 resultV, err := Bin[int8](vecs, procs) 116 vecLen := int64(vector.Length(resultV)) 117 if err != nil { 118 panic(err) 119 } 120 tempC := make([]string, 7) 121 122 i := int64(0) 123 for ; i < vecLen; i++ { 124 tempC[i] = resultV.GetString(i) 125 } 126 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000"}, tempC) 127 } 128 129 func TestBinInt16(t *testing.T) { 130 procs := testutil.NewProc() 131 132 as := []int16{2, 4, 6, 8, 16, 32, 64, 128} 133 vecs := make([]*vector.Vector, 1) 134 vecs[0] = testutil.MakeInt16Vector(as, nil) 135 136 resultV, err := Bin[int16](vecs, procs) 137 vecLen := int64(vector.Length(resultV)) 138 if err != nil { 139 panic(err) 140 } 141 tempC := make([]string, 8) 142 143 i := int64(0) 144 for ; i < vecLen; i++ { 145 tempC[i] = resultV.GetString(i) 146 } 147 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 148 } 149 150 func TestBinInt32(t *testing.T) { 151 procs := testutil.NewProc() 152 153 as := []int32{2, 4, 6, 8, 16, 32, 64, 128} 154 vecs := make([]*vector.Vector, 1) 155 vecs[0] = testutil.MakeInt32Vector(as, nil) 156 157 resultV, err := Bin[int32](vecs, procs) 158 vecLen := int64(vector.Length(resultV)) 159 if err != nil { 160 panic(err) 161 } 162 tempC := make([]string, 8) 163 164 i := int64(0) 165 for ; i < vecLen; i++ { 166 tempC[i] = resultV.GetString(i) 167 } 168 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 169 } 170 171 func TestBinInt64(t *testing.T) { 172 procs := testutil.NewProc() 173 174 as := []int64{2, 4, 6, 8, 16, 32, 64, 128} 175 vecs := make([]*vector.Vector, 1) 176 vecs[0] = testutil.MakeInt64Vector(as, nil) 177 178 resultV, err := Bin[int64](vecs, procs) 179 vecLen := int64(vector.Length(resultV)) 180 if err != nil { 181 panic(err) 182 } 183 tempC := make([]string, 8) 184 185 i := int64(0) 186 for ; i < vecLen; i++ { 187 tempC[i] = resultV.GetString(i) 188 } 189 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 190 } 191 192 func TestBinFloat32(t *testing.T) { 193 procs := testutil.NewProc() 194 195 as := []float32{2.1111, 4.4261264, 6.1151275, 8.48484, 16.266, 32.3338787, 64.0000000, 128.26454} 196 vecs := make([]*vector.Vector, 1) 197 vecs[0] = testutil.MakeFloat32Vector(as, nil) 198 199 resultV, err := BinFloat[float32](vecs, procs) 200 vecLen := int64(vector.Length(resultV)) 201 if err != nil { 202 panic(err) 203 } 204 tempC := make([]string, 8) 205 206 i := int64(0) 207 for ; i < vecLen; i++ { 208 tempC[i] = resultV.GetString(i) 209 } 210 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 211 } 212 func TestBinFloat64(t *testing.T) { 213 procs := testutil.NewProc() 214 215 as := []float64{2.1111, 4.4261264, 6.1151275, 8.48484, 16.266, 32.3338787, 64.0000000, 128.26454} 216 vecs := make([]*vector.Vector, 1) 217 vecs[0] = testutil.MakeFloat64Vector(as, nil) 218 219 resultV, err := BinFloat[float64](vecs, procs) 220 vecLen := int64(vector.Length(resultV)) 221 if err != nil { 222 panic(err) 223 } 224 tempC := make([]string, 8) 225 226 i := int64(0) 227 for ; i < vecLen; i++ { 228 tempC[i] = resultV.GetString(i) 229 } 230 require.Equal(t, []string{"10", "100", "110", "1000", "10000", "100000", "1000000", "10000000"}, tempC) 231 } 232 233 func TestBinNegativeInt(t *testing.T) { 234 procs := testutil.NewProc() 235 236 as := []int64{-2, -4, -6, -8, -16, -32, -64, -128} 237 vecs := make([]*vector.Vector, 1) 238 vecs[0] = testutil.MakeInt64Vector(as, nil) 239 240 resultV, err := Bin[int64](vecs, procs) 241 vecLen := int64(vector.Length(resultV)) 242 if err != nil { 243 panic(err) 244 } 245 tempC := make([]string, 8) 246 247 i := int64(0) 248 for ; i < vecLen; i++ { 249 tempC[i] = resultV.GetString(i) 250 } 251 require.Equal(t, []string{"1111111111111111111111111111111111111111111111111111111111111110", 252 "1111111111111111111111111111111111111111111111111111111111111100", 253 "1111111111111111111111111111111111111111111111111111111111111010", 254 "1111111111111111111111111111111111111111111111111111111111111000", 255 "1111111111111111111111111111111111111111111111111111111111110000", 256 "1111111111111111111111111111111111111111111111111111111111100000", 257 "1111111111111111111111111111111111111111111111111111111111000000", 258 "1111111111111111111111111111111111111111111111111111111110000000"}, tempC) 259 }