(t *testing.T)
| 476 | } |
| 477 | |
| 478 | func TestExtendReuseSlice(t *testing.T) { |
| 479 | tcs := []struct { |
| 480 | sz int |
| 481 | in []int |
| 482 | expected []int |
| 483 | }{ |
| 484 | { |
| 485 | sz: 0, |
| 486 | in: []int{1, 2, 3}, |
| 487 | expected: []int{}, |
| 488 | }, |
| 489 | { |
| 490 | sz: 2, |
| 491 | in: []int{1, 2, 3}, |
| 492 | expected: []int{1, 2}, |
| 493 | }, |
| 494 | { |
| 495 | sz: 5, |
| 496 | in: []int{1, 2, 3}, |
| 497 | expected: []int{1, 2, 3, 0, 0}, |
| 498 | }, |
| 499 | { |
| 500 | // len < cap < sz: slice was shrunk then grown past cap |
| 501 | sz: 6, |
| 502 | in: append(make([]int, 0, 4), 1, 2), |
| 503 | expected: []int{1, 2, 0, 0, 0, 0}, |
| 504 | }, |
| 505 | } |
| 506 | |
| 507 | for _, tc := range tcs { |
| 508 | t.Run(fmt.Sprintf("%v", tc.sz), func(t *testing.T) { |
| 509 | out := extendReuseSlice(tc.sz, tc.in) |
| 510 | assert.Equal(t, tc.expected, out) |
| 511 | }) |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | func BenchmarkExtendReuseSlice(b *testing.B) { |
| 516 | in := []int{1, 2, 3} |
nothing calls this directly
no test coverage detected