github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/instr/instr_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 instr 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/nulls" 19 "testing" 20 ) 21 22 func TestInstr(t *testing.T) { 23 s1 := []string{"abc"} 24 s2 := []string{"bc"} 25 rs := make([]int64, 3) 26 nsp := nulls.NewWithSize(3) 27 snasp := []*nulls.Nulls{nulls.NewWithSize(3), nulls.NewWithSize(3)} 28 Instr(s1, s2, snasp, rs, nsp) 29 nsp.Set(0) 30 Instr(s1, s2, snasp, rs, nsp) 31 s1 = append(s1, "abc") 32 Instr(s1, s2, snasp, rs, nsp) 33 s2 = append(s2, "bc") 34 Instr(s1, s2, snasp, rs, nsp) 35 s1 = s1[:1] 36 Instr(s1, s2, snasp, rs, nsp) 37 } 38 39 func TestSingle(t *testing.T) { 40 kases := []struct { 41 str string 42 sub string 43 ret int64 44 }{ 45 {"abc", "bc", 2}, 46 {"abc", "b", 2}, 47 {"abc", "abc", 1}, 48 {"abc", "a", 1}, 49 {"abc", "dca", 0}, 50 {"abc", "", 1}, 51 {"", "abc", 0}, 52 {"", "", 1}, 53 {"abc", "abcabc", 0}, 54 {"abcabc", "abc", 1}, 55 {"abcabc", "bc", 2}, 56 {"啊撒撒撒撒", "啊", 1}, 57 {"啊撒撒撒撒", "撒", 2}, 58 {"啊撒撒撒撒", "撒撒", 2}, 59 {"啊撒撒撒撒x的q", "x", 6}, 60 {"啊撒撒撒撒x的q", "x的", 6}, 61 {"啊撒撒撒撒x的q", "x的q", 6}, 62 {"啊撒撒撒撒x的q", "x的q啊", 0}, 63 {"啊撒撒撒撒x的q", "的", 7}, 64 {"啊撒撒撒撒x的q", "的q", 7}, 65 {"啊撒撒撒撒x的q", "的q啊", 0}, 66 {"啊撒撒撒撒x的q", "q", 8}, 67 } 68 for _, kase := range kases { 69 ret := Single(kase.str, kase.sub) 70 if ret != kase.ret { 71 t.Fatalf("str: %s, sub: %s, ret: %d, want: %d", kase.str, kase.sub, ret, kase.ret) 72 } 73 } 74 }