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

Function TestSafeAllocationCapacity

pkg/workflow/allocation_helpers_test.go:12–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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}

Callers

nothing calls this directly

Calls 2

safeAllocationCapacityFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected