File: round2_64_test.go

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (32 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
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
32
//go:build amd64 || arm64 || ppc64 || ppc64le || riscv64 || 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, math.MaxInt32)
	testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-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)
	}
}