mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Add extra test and benchmark for count bits
This commit is contained in:
parent
c46d84b991
commit
125312a8cf
@ -22,12 +22,18 @@ import (
|
||||
)
|
||||
|
||||
func TestCountBits(t *testing.T) {
|
||||
// bigN is an integer that occupies more than one big.Word.
|
||||
bigN, ok := big.NewInt(0).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16)
|
||||
if !ok {
|
||||
t.Fatal("Failed to set bigN")
|
||||
}
|
||||
tests := []struct {
|
||||
n *big.Int
|
||||
expected int
|
||||
}{
|
||||
{n: big.NewInt(int64(0)), expected: 0},
|
||||
{n: big.NewInt(int64(0xffffffffff)), expected: 40},
|
||||
{n: bigN, expected: 1},
|
||||
}
|
||||
for _, test := range tests {
|
||||
actual := countBits(test.n)
|
||||
@ -36,3 +42,13 @@ func TestCountBits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCountBits(b *testing.B) {
|
||||
bigN, ok := big.NewInt(0).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16)
|
||||
if !ok {
|
||||
b.Fatal("Failed to set bigN")
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
countBits(bigN)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user