-
Notifications
You must be signed in to change notification settings - Fork 344
/
version_test.go
158 lines (137 loc) · 2.07 KB
/
version_test.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// go-qrcode
// Copyright 2014 Tom Harwood
package qrcode
import (
"testing"
bitset "github.com/skip2/go-qrcode/bitset"
)
func TestFormatInfo(t *testing.T) {
tests := []struct {
level RecoveryLevel
maskPattern int
expected uint32
}{
{ // L=01 M=00 Q=11 H=10
Low,
1,
0x72f3,
},
{
Medium,
2,
0x5e7c,
},
{
High,
3,
0x3a06,
},
{
Highest,
4,
0x0762,
},
{
Low,
5,
0x6318,
},
{
Medium,
6,
0x4f97,
},
{
High,
7,
0x2bed,
},
}
for i, test := range tests {
v := getQRCodeVersion(test.level, 1)
result := v.formatInfo(test.maskPattern)
expected := bitset.New()
expected.AppendUint32(test.expected, formatInfoLengthBits)
if !expected.Equals(result) {
t.Errorf("formatInfo test #%d got %s, expected %s", i, result.String(),
expected.String())
}
}
}
func TestVersionInfo(t *testing.T) {
tests := []struct {
version int
expected uint32
}{
{
7,
0x007c94,
},
{
10,
0x00a4d3,
},
{
20,
0x0149a6,
},
{
30,
0x01ed75,
},
{
40,
0x028c69,
},
}
for i, test := range tests {
var v *qrCodeVersion
v = getQRCodeVersion(Low, test.version)
result := v.versionInfo()
expected := bitset.New()
expected.AppendUint32(test.expected, versionInfoLengthBits)
if !expected.Equals(result) {
t.Errorf("versionInfo test #%d got %s, expected %s", i, result.String(),
expected.String())
}
}
}
func TestNumBitsToPadToCodeoword(t *testing.T) {
tests := []struct {
level RecoveryLevel
version int
numDataBits int
expected int
}{
{
Low,
1,
0,
0,
}, {
Low,
1,
1,
7,
}, {
Low,
1,
7,
1,
}, {
Low,
1,
8,
0,
},
}
for i, test := range tests {
var v *qrCodeVersion
v = getQRCodeVersion(test.level, test.version)
result := v.numBitsToPadToCodeword(test.numDataBits)
if result != test.expected {
t.Errorf("numBitsToPadToCodeword test %d (version=%d numDataBits=%d), got %d, expected %d",
i, test.version, test.numDataBits, result, test.expected)
}
}
}