MCPcopy
hub / github.com/go-gorm/gorm / TestRTrimSlice

Function TestRTrimSlice

utils/utils_test.go:145–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func 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 })

Callers

nothing calls this directly

Calls 2

RTrimSliceFunction · 0.85
AssertEqualFunction · 0.70

Tested by

no test coverage detected