(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestRTrimSlice(t *testing.T) { |
| 146 | tests := []struct { |
| 147 | name string |
| 148 | input []int |
| 149 | trimLen int |
| 150 | expected []int |
| 151 | }{ |
| 152 | { |
| 153 | name: "Trim two elements from end", |
| 154 | input: []int{1, 2, 3, 4, 5}, |
| 155 | trimLen: 2, |
| 156 | expected: []int{1, 2, 3}, |
| 157 | }, |
| 158 | { |
| 159 | name: "Trim entire slice", |
| 160 | input: []int{1, 2, 3}, |
| 161 | trimLen: 3, |
| 162 | expected: []int{}, |
| 163 | }, |
| 164 | { |
| 165 | name: "Trim length greater than slice length", |
| 166 | input: []int{1, 2, 3}, |
| 167 | trimLen: 5, |
| 168 | expected: []int{}, |
| 169 | }, |
| 170 | { |
| 171 | name: "Zero trim length", |
| 172 | input: []int{1, 2, 3}, |
| 173 | trimLen: 0, |
| 174 | expected: []int{1, 2, 3}, |
| 175 | }, |
| 176 | { |
| 177 | name: "Trim one element from end", |
| 178 | input: []int{1, 2, 3}, |
| 179 | trimLen: 1, |
| 180 | expected: []int{1, 2}, |
| 181 | }, |
| 182 | { |
| 183 | name: "Empty slice", |
| 184 | input: []int{}, |
| 185 | trimLen: 2, |
| 186 | expected: []int{}, |
| 187 | }, |
| 188 | { |
| 189 | name: "Negative trim length (should be treated as zero)", |
| 190 | input: []int{1, 2, 3}, |
| 191 | trimLen: -1, |
| 192 | expected: []int{1, 2, 3}, |
| 193 | }, |
| 194 | } |
| 195 | |
| 196 | for _, testcase := range tests { |
| 197 | t.Run(testcase.name, func(t *testing.T) { |
| 198 | result := RTrimSlice(testcase.input, testcase.trimLen) |
| 199 | if !AssertEqual(result, testcase.expected) { |
| 200 | t.Errorf("RTrimSlice(%v, %d) = %v; want %v", testcase.input, testcase.trimLen, result, testcase.expected) |
| 201 | } |
| 202 | }) |
nothing calls this directly
no test coverage detected