(t *testing.T)
| 907 | } |
| 908 | |
| 909 | func TestExtendReuseSlice(t *testing.T) { |
| 910 | tcs := []struct { |
| 911 | sz int |
| 912 | in []int |
| 913 | expected []int |
| 914 | }{ |
| 915 | { |
| 916 | sz: 0, |
| 917 | in: []int{1, 2, 3}, |
| 918 | expected: []int{}, |
| 919 | }, |
| 920 | { |
| 921 | sz: 2, |
| 922 | in: []int{1, 2, 3}, |
| 923 | expected: []int{1, 2}, |
| 924 | }, |
| 925 | { |
| 926 | sz: 5, |
| 927 | in: []int{1, 2, 3}, |
| 928 | expected: []int{1, 2, 3, 0, 0}, |
| 929 | }, |
| 930 | { |
| 931 | // len < cap < sz: slice was shrunk then grown past cap |
| 932 | sz: 6, |
| 933 | in: append(make([]int, 0, 4), 1, 2), |
| 934 | expected: []int{1, 2, 0, 0, 0, 0}, |
| 935 | }, |
| 936 | } |
| 937 | |
| 938 | for _, tc := range tcs { |
| 939 | t.Run(fmt.Sprintf("%v", tc.sz), func(t *testing.T) { |
| 940 | out := extendReuseSlice(tc.sz, tc.in) |
| 941 | assert.Equal(t, tc.expected, out) |
| 942 | }) |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | func BenchmarkExtendReuseSlice(b *testing.B) { |
| 947 | sizes := []int{5, 20, 8, 50, 12, 100, 30, 200, 15, 80, 3, 150, 10, 40, 7, 300, 25, 60, 90, 10} |
nothing calls this directly
no test coverage detected