github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/endswith/endswith_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 endswith 16 17 import ( 18 "reflect" 19 "testing" 20 ) 21 22 func TestEndsWith(t *testing.T) { 23 tests := []struct { 24 name string 25 lv []string 26 rv []string 27 want []uint8 28 rs []uint8 29 }{ 30 { 31 name: "English Match", 32 lv: []string{"Hello", "World", "Hello", "world"}, 33 rv: []string{"o", "ld", "llo", "world"}, 34 rs: make([]uint8, 4), 35 want: []uint8{1, 1, 1, 1}, 36 }, 37 { 38 name: "English Mismatch", 39 lv: []string{"Hello", "World", "Hello", "world"}, 40 rv: []string{"oll", "dl", "Helloo", "abc"}, 41 rs: make([]uint8, 4), 42 want: []uint8{0, 0, 0, 0}, 43 }, 44 { 45 name: "Chinese Match", 46 lv: []string{"你好世界", "世界你好", "你好 世界", "你好,世界"}, 47 rv: []string{"世界", "你好", "世界", "你好,世界"}, 48 rs: make([]uint8, 4), 49 want: []uint8{1, 1, 1, 1}, 50 }, 51 { 52 name: "Chinese Mismatch", 53 lv: []string{"你好世界", "世界你好", "你好 世界", "你好,世界"}, 54 rv: []string{"你好", "你 好", "你好 界 ", "你好"}, 55 rs: make([]uint8, 4), 56 want: []uint8{0, 0, 0, 0}, 57 }, 58 { 59 name: "Chinese + English", 60 lv: []string{"你好World", "Hello世界", "你好World", "Hello世界"}, 61 rv: []string{"好World", "lo世界", "你好world", "Hello界世"}, 62 rs: make([]uint8, 4), 63 want: []uint8{1, 1, 0, 0}, 64 }, 65 { 66 name: "Special Match", 67 lv: []string{"Hello", " ", " 你好", ""}, 68 rv: []string{"", " ", "好", ""}, 69 rs: make([]uint8, 4), 70 want: []uint8{1, 1, 1, 1}, 71 }, 72 } 73 74 for _, tt := range tests { 75 t.Run(tt.name, func(t *testing.T) { 76 if got := EndsWith(tt.lv, tt.rv, tt.rs); !reflect.DeepEqual(got, tt.want) { 77 t.Errorf("EndsWith() = %v, want %v", got, tt.want) 78 } 79 }) 80 } 81 } 82 83 func TestEndsWithRightConst(t *testing.T) { 84 tests := []struct { 85 name string 86 lv []string 87 rv []string 88 want []uint8 89 rs []uint8 90 }{ 91 { 92 name: "Right Const", 93 lv: []string{"H", "He", "Hello", "world"}, 94 rv: []string{"He"}, 95 rs: make([]uint8, 4), 96 want: []uint8{0, 1, 0, 0}, 97 }, 98 } 99 100 for _, tt := range tests { 101 t.Run(tt.name, func(t *testing.T) { 102 if got := EndsWithRightConst(tt.lv, tt.rv, tt.rs); !reflect.DeepEqual(got, tt.want) { 103 t.Errorf("EndsWithRightConst() = %v, want %v", got, tt.want) 104 } 105 }) 106 } 107 } 108 109 func TestEndsWithLeftConst(t *testing.T) { 110 tests := []struct { 111 name string 112 lv []string 113 rv []string 114 want []uint8 115 rs []uint8 116 }{ 117 { 118 name: "Left Const", 119 lv: []string{"Hello"}, 120 rv: []string{"lo", "Hello", "", "HHello"}, 121 rs: make([]uint8, 4), 122 want: []uint8{1, 1, 1, 0}, 123 }, 124 } 125 126 for _, tt := range tests { 127 t.Run(tt.name, func(t *testing.T) { 128 if got := EndsWithLeftConst(tt.lv, tt.rv, tt.rs); !reflect.DeepEqual(got, tt.want) { 129 t.Errorf("EndsWithLeftConst() = %v, want %v", got, tt.want) 130 } 131 }) 132 } 133 } 134 135 func TestEndsWithAllConst(t *testing.T) { 136 tests := []struct { 137 name string 138 lv []string 139 rv []string 140 want []uint8 141 rs []uint8 142 }{ 143 { 144 name: "All Const", 145 lv: []string{"Hello"}, 146 rv: []string{"llo"}, 147 rs: make([]uint8, 1), 148 want: []uint8{1}, 149 }, 150 { 151 name: "All Const2", 152 lv: []string{"Hello"}, 153 rv: []string{"World"}, 154 rs: make([]uint8, 1), 155 want: []uint8{0}, 156 }, 157 } 158 159 for _, tt := range tests { 160 t.Run(tt.name, func(t *testing.T) { 161 if got := EndsWithAllConst(tt.lv, tt.rv, tt.rs); !reflect.DeepEqual(got, tt.want) { 162 t.Errorf("EndsWithAllConst() = %v, want %v", got, tt.want) 163 } 164 }) 165 } 166 }