-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix round2_32, split round2 tests because they depend on sizeof int a…
…t compile time (#1607)
- Loading branch information
Showing
4 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
package fasthttp | ||
|
||
import "math" | ||
|
||
func roundUpForSliceCap(n int) int { | ||
if n <= 0 { | ||
return 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build !amd64 && !arm64 && !ppc64 && !ppc64le && !s390x | ||
// +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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build amd64 || arm64 || ppc64 || ppc64le || s390x | ||
// +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, 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) | ||
} | ||
} |