(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestSafeAllocationCapacity(t *testing.T) { |
| 13 | t.Run("handles zero inputs", func(t *testing.T) { |
| 14 | assert.Zero(t, safeAllocationCapacity()) |
| 15 | assert.Zero(t, safeAllocationCapacity(0, 0)) |
| 16 | assert.Equal(t, 5, safeAllocationCapacity(0, 5)) |
| 17 | assert.Equal(t, 5, safeAllocationCapacity(5, 0)) |
| 18 | }) |
| 19 | |
| 20 | t.Run("sums sizes when the result fits in int", func(t *testing.T) { |
| 21 | assert.Equal(t, 5, safeAllocationCapacity(2, 3)) |
| 22 | assert.Equal(t, 6000, safeAllocationCapacity(1000, 5000)) |
| 23 | assert.Equal(t, math.MaxInt, safeAllocationCapacity(math.MaxInt-1, 1)) |
| 24 | assert.Equal(t, math.MaxInt, safeAllocationCapacity(math.MaxInt-2, 1, 1)) |
| 25 | }) |
| 26 | |
| 27 | t.Run("returns zero when the sum would overflow int", func(t *testing.T) { |
| 28 | assert.Zero(t, safeAllocationCapacity(math.MaxInt, 1)) |
| 29 | assert.Zero(t, safeAllocationCapacity(math.MaxInt-1, 2)) |
| 30 | assert.Zero(t, safeAllocationCapacity(math.MaxInt-2, 2, 1)) |
| 31 | }) |
| 32 | |
| 33 | t.Run("returns zero for negative parts", func(t *testing.T) { |
| 34 | assert.Zero(t, safeAllocationCapacity(-1)) |
| 35 | assert.Zero(t, safeAllocationCapacity(2, -1)) |
| 36 | }) |
| 37 | } |
nothing calls this directly
no test coverage detected