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

Function TestReverseBits

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

Source from the content-addressed store, hash-verified

8import "testing"
9
10func TestReverseBits(t *testing.T) {
11 var tests = []struct {
12 name string
13 number uint
14 result uint
15 }{
16 {"43261596 (00000010100101000001111010011100) to 964176192 (00111001011110000010100101000000)", 43261596, 964176192},
17 {"3758096384 (11100000000000000000000000000000) to 7 (00000000000000000000000000000111)", 3758096384, 7},
18 {"7 (00000000000000000000000000000111) to 3758096384 (11100000000000000000000000000000)", 7, 3758096384},
19 {"2684354560 (10100000000000000000000000000000) to 5 (00000000000000000000000000000101)", 2684354560, 5},
20 {"2684354561 (10100000000000000000000000000001) to 5 (10000000000000000000000000000101)", 2684354561, 2147483653},
21 }
22 for _, tv := range tests {
23 t.Run(tv.name, func(t *testing.T) {
24 result := ReverseBits(tv.number)
25 t.Log(result)
26 if result != tv.result {
27 t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
28 }
29 })
30 }
31}
32
33func BenchmarkReverseBits(b *testing.B) {
34 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

ReverseBitsFunction · 0.85

Tested by

no test coverage detected