MCPcopy Create free account
hub / github.com/github/gh-aw / TestAny

Function TestAny

pkg/sliceutil/sliceutil_test.go:216–274  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestAny(t *testing.T) {
217 tests := []struct {
218 name string
219 slice []int
220 predicate func(int) bool
221 expected bool
222 }{
223 {
224 name: "at least one element matches",
225 slice: []int{1, 2, 3, 4, 5},
226 predicate: func(x int) bool { return x > 3 },
227 expected: true,
228 },
229 {
230 name: "no element matches",
231 slice: []int{1, 2, 3},
232 predicate: func(x int) bool { return x > 10 },
233 expected: false,
234 },
235 {
236 name: "empty slice returns false",
237 slice: []int{},
238 predicate: func(x int) bool { return true },
239 expected: false,
240 },
241 {
242 name: "nil slice returns false",
243 slice: nil,
244 predicate: func(x int) bool { return true },
245 expected: false,
246 },
247 {
248 name: "single element matches",
249 slice: []int{42},
250 predicate: func(x int) bool { return x == 42 },
251 expected: true,
252 },
253 {
254 name: "single element does not match",
255 slice: []int{42},
256 predicate: func(x int) bool { return x == 0 },
257 expected: false,
258 },
259 {
260 name: "all elements match",
261 slice: []int{2, 4, 6, 8},
262 predicate: func(x int) bool { return x%2 == 0 },
263 expected: true,
264 },
265 }
266
267 for _, tt := range tests {
268 t.Run(tt.name, func(t *testing.T) {
269 result := Any(tt.slice, tt.predicate)
270 assert.Equal(t, tt.expected, result,
271 "Any should return %v for slice %v", tt.expected, tt.slice)
272 })
273 }

Callers

nothing calls this directly

Calls 2

AnyFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected