MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestLogBase2

Function TestLogBase2

math/binary/logarithm_test.go:13–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestLogBase2(t *testing.T) {
14 tests := []struct {
15 name string
16 n uint32
17 want uint32
18 }{
19 {"log2(1) = 0", 1, 0},
20 {"log2(2) = 1", 2, 1},
21 {"log2(4) = 2", 4, 2},
22 {"log2(8) = 3", 8, 3},
23 {"log2(16) = 4", 16, 4},
24 {"log2(32) = 5", 32, 5},
25 {"log2(64) = 6", 64, 6},
26 {"log2(128) = 7", 128, 7},
27 {"log2(256) = 8", 256, 8},
28 }
29 for _, test := range tests {
30 t.Run(test.name, func(t *testing.T) {
31 if got := LogBase2(test.n); got != test.want {
32 t.Errorf("LogBase2() = %v, want %v", got, test.want)
33 }
34 })
35 }
36}
37
38func BenchmarkBitwiseLogBase2(b *testing.B) {
39 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

LogBase2Function · 0.85

Tested by

no test coverage detected