MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestHexToBinary

Function TestHexToBinary

conversion/hexadecimaltobinary_test.go:7–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestHexToBinary(t *testing.T) {
8 tests := []struct {
9 hex string
10 want string
11 wantErr bool
12 }{
13 {"", "", true},
14 {"G123", "", true},
15 {"12XZ", "", true},
16 {"1", "1", false},
17 {"A", "1010", false},
18 {"10", "10000", false},
19 {"1A", "11010", false},
20 {"aB", "10101011", false},
21 {"0Ff", "11111111", false},
22 {" 1A ", "11010", false},
23 {"0001A", "11010", false},
24 {"7FFFFFFFFFFFFFFF", "111111111111111111111111111111111111111111111111111111111111111", false},
25 }
26
27 for _, tt := range tests {
28 t.Run(tt.hex, func(t *testing.T) {
29 got, err := hexToBinary(tt.hex)
30 if (err != nil) != tt.wantErr {
31 t.Errorf("hexToBinary(%q) error = %v, wantErr %v", tt.hex, err, tt.wantErr)
32 return
33 }
34 if got != tt.want {
35 t.Errorf("hexToBinary(%q) = %v, want %v", tt.hex, got, tt.want)
36 }
37 })
38 }
39}
40
41func BenchmarkHexToBinary(b *testing.B) {
42 b.ReportAllocs()

Callers

nothing calls this directly

Calls 1

hexToBinaryFunction · 0.85

Tested by

no test coverage detected