github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/bit_length/bit_length_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 bit_length 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func makeBytes(strs []string) [][]byte { 24 ret := make([][]byte, len(strs)) 25 for i, s := range strs { 26 ret[i] = []byte(s) 27 } 28 return ret 29 } 30 31 func TestEmpty(t *testing.T) { 32 tt := []struct { 33 name string 34 xs [][]byte 35 rs []int64 36 want []int64 37 }{ 38 { 39 name: "Empty", 40 xs: makeBytes([]string{""}), 41 rs: make([]int64, 1), 42 want: []int64{0}, 43 }, 44 { 45 name: "Simple condition", 46 xs: makeBytes([]string{"a", "boy", " ", "\t", "\n", "dead"}), 47 rs: make([]int64, 6), 48 want: []int64{8, 24, 8, 8, 8, 32}, 49 }, 50 } 51 for _, tc := range tt { 52 require.Equal(t, tc.want, StrBitLength(tc.xs, tc.rs)) 53 } 54 }