MCPcopy Create free account
hub / github.com/sourcegraph/conc / TestMap

Function TestMap

iter/map_test.go:23–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func TestMap(t *testing.T) {
24 t.Parallel()
25
26 t.Run("empty", func(t *testing.T) {
27 t.Parallel()
28 f := func() {
29 ints := []int{}
30 Map(ints, func(val *int) int {
31 panic("this should never be called")
32 })
33 }
34 require.NotPanics(t, f)
35 })
36
37 t.Run("panic is propagated", func(t *testing.T) {
38 t.Parallel()
39 f := func() {
40 ints := []int{1}
41 Map(ints, func(val *int) int {
42 panic("super bad thing happened")
43 })
44 }
45 require.Panics(t, f)
46 })
47
48 t.Run("mutating inputs is fine, though not recommended", func(t *testing.T) {
49 t.Parallel()
50 ints := []int{1, 2, 3, 4, 5}
51 Map(ints, func(val *int) int {
52 *val += 1
53 return 0
54 })
55 require.Equal(t, []int{2, 3, 4, 5, 6}, ints)
56 })
57
58 t.Run("basic increment", func(t *testing.T) {
59 t.Parallel()
60 ints := []int{1, 2, 3, 4, 5}
61 res := Map(ints, func(val *int) int {
62 return *val + 1
63 })
64 require.Equal(t, []int{2, 3, 4, 5, 6}, res)
65 require.Equal(t, []int{1, 2, 3, 4, 5}, ints)
66 })
67
68 t.Run("huge inputs", func(t *testing.T) {
69 t.Parallel()
70 ints := make([]int, 10000)
71 res := Map(ints, func(val *int) int {
72 return 1
73 })
74 expected := make([]int, 10000)
75 for i := 0; i < 10000; i++ {
76 expected[i] = 1
77 }
78 require.Equal(t, expected, res)
79 })
80}

Callers

nothing calls this directly

Calls 1

MapFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…