aboutsummaryrefslogtreecommitdiff
path: root/round2_32_test.go
blob: 51dc2f5a9937a3df45556f9fbc0c17fc66371a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build !amd64 && !arm64 && !ppc64 && !ppc64le && !s390x

package fasthttp

import (
	"math"
	"testing"
)

func TestRound2ForSliceCap(t *testing.T) {
	t.Parallel()

	testRound2ForSliceCap(t, 0, 0)
	testRound2ForSliceCap(t, 1, 1)
	testRound2ForSliceCap(t, 2, 2)
	testRound2ForSliceCap(t, 3, 4)
	testRound2ForSliceCap(t, 4, 4)
	testRound2ForSliceCap(t, 5, 8)
	testRound2ForSliceCap(t, 7, 8)
	testRound2ForSliceCap(t, 8, 8)
	testRound2ForSliceCap(t, 9, 16)
	testRound2ForSliceCap(t, 0x10001, 0x20000)

	testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32-1)
}

func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) {
	if roundUpForSliceCap(n) != expectedRound2 {
		t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2)
	}
}