Test Failed
Push — master ( 2f8cd9...4364b8 )
by iLex
01:33
created

hkid_test.go   A

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 37
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hkid.getCorrectData 0 9 1
A hkid.TestCheckPartTrue 0 10 5
A hkid.TestCheckStringTrue 0 10 5
A hkid.newCorrectData 0 2 1
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
		})
41
	}
42
}
43
44
func TestCheckPartTrue(t *testing.T) {
45
	data := getCorrectData()
46
	for _, v := range data {
47
		t.Run(v.input, func(t *testing.T) {
48
			hkidResult := CheckPart(v.part1, v.part2, v.part3)
49
			if hkidResult.Valid == false {
50
				t.Errorf("%s should true", v.output)
51
			}
52
			if hkidResult.Format() != v.output {
53
				t.Errorf("%s should Equals", v.output)
54
			}
55
		})
56
	}
57
}
58