(t *testing.T)
| 8 | import "testing" |
| 9 | |
| 10 | func 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 | } |
nothing calls this directly
no test coverage detected