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

Function TestMap

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

Source from the content-addressed store, hash-verified

60}
61
62func TestMap(t *testing.T) {
63 tests := []struct {
64 name string
65 slice []string
66 transform func(string) int
67 expected []int
68 }{
69 {
70 name: "nil slice returns empty slice",
71 slice: nil,
72 transform: func(s string) int { return len(s) },
73 expected: []int{},
74 },
75 {
76 name: "empty slice returns empty slice",
77 slice: []string{},
78 transform: func(s string) int { return len(s) },
79 expected: []int{},
80 },
81 {
82 name: "transforms each element",
83 slice: []string{"apple", "fig", "banana"},
84 transform: func(s string) int { return len(s) },
85 expected: []int{5, 3, 6},
86 },
87 {
88 name: "single element",
89 slice: []string{"hello"},
90 transform: func(s string) int { return len(s) },
91 expected: []int{5},
92 },
93 }
94
95 for _, tt := range tests {
96 t.Run(tt.name, func(t *testing.T) {
97 result := Map(tt.slice, tt.transform)
98 assert.Equal(t, tt.expected, result,
99 "Map should transform all elements in slice %v", tt.slice)
100 })
101 }
102}
103
104func TestDeduplicate(t *testing.T) {
105 tests := []struct {

Callers

nothing calls this directly

Calls 2

MapFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected