-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_test.go
More file actions
58 lines (55 loc) · 1.25 KB
/
Copy pathcode_test.go
File metadata and controls
58 lines (55 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package codeautoradio
import (
"testing"
)
// precodeIsValid checks if the given precode is valid.
func TestPrecodeIsValid(t *testing.T) {
tests := []struct {
precode string
want bool
}{
{"A123", true},
{"B456", true},
{"C789", true},
{"Z999", true},
{"A1234", false},
{"A12", false},
{"A012", false},
{"0123", false},
}
for _, tt := range tests {
t.Run(tt.precode, func(t *testing.T) {
if got := precodeIsValid(tt.precode); got != tt.want {
t.Errorf("precodeIsValid() = %v, want %v", got, tt.want)
}
})
}
}
// GetRadioCode returns the radio code for the given precode.
func TestGetRadioCode(t *testing.T) {
tests := []struct {
precode string
want string
ok bool
}{
{"A123", "0086", true},
{"B456", "0709", true},
{"C789", "1621", true},
{"Z999", "0060", true},
{"A1234", "", false},
{"A12", "", false},
{"A012", "", false},
{"0123", "", false},
}
for _, tt := range tests {
t.Run(tt.precode, func(t *testing.T) {
got, ok := GetRadioCode(tt.precode)
if got != tt.want {
t.Errorf("GetRadioCode() got = %v, want %v", got, tt.want)
}
if ok != tt.ok {
t.Errorf("GetRadioCode() ok = %v, want %v", ok, tt.ok)
}
})
}
}