|
1
|
|
|
package hkid |
|
2
|
|
|
|
|
3
|
|
|
import "testing" |
|
4
|
|
|
|
|
5
|
|
|
type correctData struct { |
|
6
|
|
|
input string |
|
7
|
|
|
part1 string |
|
8
|
|
|
part2 string |
|
9
|
|
|
part3 string |
|
10
|
|
|
output string |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
func newCorrectData(input string, part1 string, part2 string, part3 string, output string) correctData { |
|
14
|
|
|
return correctData{input: input, part1: part1, part2: part2, part3: part3, output: output} |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
func getCorrectData() [7]correctData { |
|
18
|
|
|
return [7]correctData{ |
|
19
|
|
|
newCorrectData("B111111(1)", "B", "111111", "1", "B111111(1)"), |
|
20
|
|
|
newCorrectData("CA182361(1)", "CA", "182361", "1", "CA182361(1)"), |
|
21
|
|
|
newCorrectData("ZA182361(3)", "ZA", "182361", "3", "ZA182361(3)"), |
|
22
|
|
|
newCorrectData("B111112(A)", "B", "111112", "A", "B111112(A)"), |
|
23
|
|
|
newCorrectData("B111117(0)", "B", "111117", "0", "B111117(0)"), |
|
24
|
|
|
newCorrectData(" B111117(0)", " B", "111117", "0", "B111117(0)"), |
|
25
|
|
|
newCorrectData("z109852(8)", "z", "109852", "8", "Z109852(8)"), |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
func TestCheckStringTrue(t *testing.T) { |
|
30
|
|
|
data := getCorrectData() |
|
31
|
|
|
for _, v := range data { |
|
32
|
|
|
t.Run(v.input, func(t *testing.T) { |
|
33
|
|
|
hkidResult := CheckString(v.input) |
|
34
|
|
|
if hkidResult.Valid == false { |
|
35
|
|
|
t.Errorf("%s should true", v.output) |
|
36
|
|
|
} |
|
37
|
|
|
if hkidResult.Format() != v.output { |
|
38
|
|
|
t.Errorf("%s should Equals", v.output) |
|
39
|
|
|
} |
|
40
|
|
|
if hkidResult.GetPart1() != clearString(v.part1) { |
|
41
|
|
|
t.Errorf("%s should Equals", v.part1) |
|
42
|
|
|
} |
|
43
|
|
|
if hkidResult.GetPart2() != clearString(v.part2) { |
|
44
|
|
|
t.Errorf("%s should Equals", v.part2) |
|
45
|
|
|
} |
|
46
|
|
|
if hkidResult.GetPart3() != clearString(v.part3) { |
|
47
|
|
|
t.Errorf("%s should Equals", v.part3) |
|
48
|
|
|
} |
|
49
|
|
|
}) |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
func TestCheckPartTrue(t *testing.T) { |
|
54
|
|
|
data := getCorrectData() |
|
55
|
|
|
for _, v := range data { |
|
56
|
|
|
t.Run(v.input, func(t *testing.T) { |
|
57
|
|
|
hkidResult := CheckPart(v.part1, v.part2, v.part3) |
|
58
|
|
|
if hkidResult.Valid == false { |
|
59
|
|
|
t.Errorf("%s should true", v.output) |
|
60
|
|
|
} |
|
61
|
|
|
if hkidResult.Format() != v.output { |
|
62
|
|
|
t.Errorf("%s should Equals", v.output) |
|
63
|
|
|
} |
|
64
|
|
|
}) |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|