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

Function TestHexToDecimal

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

Source from the content-addressed store, hash-verified

5)
6
7func TestHexToDecimal(t *testing.T) {
8 tests := []struct {
9 hex string
10 want int64
11 wantErr bool
12 }{
13 {"", 0, true},
14 {"G123", 0, true},
15 {"123Z", 0, true},
16 {"1", 1, false},
17 {"A", 10, false},
18 {"10", 16, false},
19 {"1A", 26, false},
20 {"aB", 171, false},
21 {"0Ff", 255, false},
22 {" 1A ", 26, false},
23 {"0x1A", 26, false},
24 {"0X1A", 26, false},
25 {"1A", 26, false},
26 {"7FFFFFFFFFFFFFFF", 9223372036854775807, false},
27 {"0001A", 26, false},
28 {"0000007F", 127, false},
29 {"0", 0, false},
30 {"0x0", 0, false},
31 }
32
33 for _, tt := range tests {
34 t.Run(tt.hex, func(t *testing.T) {
35 got, err := hexToDecimal(tt.hex)
36 if (err != nil) != tt.wantErr {
37 t.Errorf("hexToDecimal(%q) error = %v, wantErr %v", tt.hex, err, tt.wantErr)
38 return
39 }
40 if got != tt.want {
41 t.Errorf("hexToDecimal(%q) = %v, want %v", tt.hex, got, tt.want)
42 }
43 })
44 }
45}
46
47func BenchmarkHexToDecimal(b *testing.B) {
48 b.ReportAllocs()

Callers

nothing calls this directly

Calls 1

hexToDecimalFunction · 0.85

Tested by

no test coverage detected