...
1
2
3
4
5 package test
6
7 import (
8 "math/bits"
9 "testing"
10 )
11
12 func TestBitLen64(t *testing.T) {
13 for i := 0; i <= 64; i++ {
14 got := bits.Len64(1 << i)
15 want := i + 1
16 if want == 65 {
17 want = 0
18 }
19 if got != want {
20 t.Errorf("Len64(1<<%d) = %d, want %d", i, got, want)
21 }
22 }
23 }
24
25 func TestBitLen32(t *testing.T) {
26 for i := 0; i <= 32; i++ {
27 got := bits.Len32(1 << i)
28 want := i + 1
29 if want == 33 {
30 want = 0
31 }
32 if got != want {
33 t.Errorf("Len32(1<<%d) = %d, want %d", i, got, want)
34 }
35 }
36 }
37
38 func TestBitLen16(t *testing.T) {
39 for i := 0; i <= 16; i++ {
40 got := bits.Len16(1 << i)
41 want := i + 1
42 if want == 17 {
43 want = 0
44 }
45 if got != want {
46 t.Errorf("Len16(1<<%d) = %d, want %d", i, got, want)
47 }
48 }
49 }
50
51 func TestBitLen8(t *testing.T) {
52 for i := 0; i <= 8; i++ {
53 got := bits.Len8(1 << i)
54 want := i + 1
55 if want == 9 {
56 want = 0
57 }
58 if got != want {
59 t.Errorf("Len8(1<<%d) = %d, want %d", i, got, want)
60 }
61 }
62 }
63
View as plain text