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

Function TestBitCounter

math/binary/bitcounter_test.go:10–33  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8import "testing"
9
10func TestBitCounter(t *testing.T) {
11 tests := []struct {
12 name string
13 number uint
14 want int
15 }{
16 {"Number of bits in a number 0", 0, 0},
17 {"Number of bits in a number 1", 1, 1},
18 {"Number of bits in a number 255", 255, 8},
19 {"Number of bits in a number 7", 7, 3},
20 {"Number of bits in a number 8", 8, 1},
21 {"Number of bits in a number 9223372036854775807", 9223372036854775807, 63},
22 {"Number of bits in a number 2147483647", 2147483647, 31},
23 {"Number of bits in a number 15", 15, 4},
24 {"Number of bits in a number 16", 16, 1},
25 }
26 for _, test := range tests {
27 t.Run(test.name, func(t *testing.T) {
28 if got := BitCounter(test.number); got != test.want {
29 t.Errorf("BitCounter() = %v, want %v", got, test.want)
30 }
31 })
32 }
33}

Callers

nothing calls this directly

Calls 1

BitCounterFunction · 0.85

Tested by

no test coverage detected