forked from yeqown/go-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_type_test.go
200 lines (177 loc) · 4.37 KB
/
matrix_type_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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package qrcode
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_qrtype(t *testing.T) {
assert.Equal(t, uint8(0b00000010), uint8(QRType_INIT)) // 1 << 1
assert.Equal(t, uint8(0b00000100), uint8(QRType_DATA)) // 2 << 1
assert.Equal(t, uint8(0b00000110), uint8(QRType_VERSION)) // 3 << 1
assert.Equal(t, uint8(0b00001000), uint8(QRType_FORMAT)) // 4 << 1
assert.Equal(t, uint8(0b00001010), uint8(QRType_FINDER)) // 5 << 1
assert.Equal(t, uint8(0b00001100), uint8(QRType_DARK)) // 6 << 1
assert.Equal(t, uint8(0b00001110), uint8(QRType_SPLITTER)) // 7 << 1
assert.Equal(t, uint8(0b00010000), uint8(QRType_TIMING)) // 8 << 1
}
func Test_qrvalue(t *testing.T) {
// QRValue_INIT_V0
assert.Equal(t, QRType_INIT, QRValue_INIT_V0.qrtype())
assert.False(t, QRValue_INIT_V0.qrbool())
// QRValue_DATA_V1
assert.Equal(t, QRType_DATA, QRValue_DATA_V1.qrtype())
assert.True(t, QRValue_DATA_V1.qrbool())
// QRValue_DATA_V0
assert.Equal(t, QRType_DATA, QRValue_DATA_V0.qrtype())
assert.False(t, QRValue_DATA_V0.qrbool())
// QRValue_VERSION_V0
assert.Equal(t, QRType_VERSION, QRValue_VERSION_V0.qrtype())
assert.False(t, QRValue_VERSION_V0.qrbool())
// QRValue_VERSION_V1
assert.Equal(t, QRType_VERSION, QRValue_VERSION_V1.qrtype())
assert.True(t, QRValue_VERSION_V1.qrbool())
// QRValue_FORMAT_V0
assert.Equal(t, QRType_FORMAT, QRValue_FORMAT_V0.qrtype())
assert.False(t, QRValue_FORMAT_V0.qrbool())
// QRValue_FORMAT_V1
assert.Equal(t, QRType_FORMAT, QRValue_FORMAT_V1.qrtype())
assert.True(t, QRValue_FORMAT_V1.qrbool())
// QRValue_FINDER_V0
assert.Equal(t, QRType_FINDER, QRValue_FINDER_V0.qrtype())
assert.False(t, QRValue_FINDER_V0.qrbool())
// QRValue_FINDER_V1
assert.Equal(t, QRType_FINDER, QRValue_FINDER_V1.qrtype())
assert.True(t, QRValue_FINDER_V1.qrbool())
// QRValue_DARK_V0
assert.Equal(t, QRType_DARK, QRValue_DARK_V0.qrtype())
assert.False(t, QRValue_DARK_V0.qrbool())
// QRValue_DARK_V1
assert.Equal(t, QRType_DARK, QRValue_DARK_V1.qrtype())
assert.True(t, QRValue_DARK_V1.qrbool())
// QRValue_SPLITTER_V0
assert.Equal(t, QRType_SPLITTER, QRValue_SPLITTER_V0.qrtype())
assert.False(t, QRValue_SPLITTER_V0.qrbool())
// QRValue_SPLITTER_V1
assert.Equal(t, QRType_SPLITTER, QRValue_SPLITTER_V1.qrtype())
assert.True(t, QRValue_SPLITTER_V1.qrbool())
// QRValue_TIMING_V0
assert.Equal(t, QRType_TIMING, QRValue_TIMING_V0.qrtype())
assert.False(t, QRValue_TIMING_V0.qrbool())
// QRValue_TIMING_V1
assert.Equal(t, QRType_TIMING, QRValue_TIMING_V1.qrtype())
assert.True(t, QRValue_TIMING_V1.qrbool())
}
func Test_qrvalue_xor(t *testing.T) {
type args struct {
s1 qrvalue
s2 qrvalue
}
tests := []struct {
name string
args args
want qrvalue
}{
{
name: "case1",
args: args{
s1: QRValue_DATA_V0,
s2: QRValue_DATA_V0,
},
want: QRValue_DATA_V0,
},
{
name: "case1",
args: args{
s1: QRValue_DATA_V1,
s2: QRValue_DATA_V0,
},
want: QRValue_DATA_V1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.args.s1.xor(tt.args.s2); got != tt.want {
t.Errorf("XOR() = %v, want %v", got, tt.want)
}
})
}
}
func Test_qrtype_String(t *testing.T) {
tests := []struct {
name string
t qrtype
want string
}{
{
name: "case1",
t: QRType_INIT,
want: "I",
},
{
name: "case2",
t: QRType_DATA,
want: "d",
},
{
name: "case3",
t: QRType_VERSION,
want: "V",
},
{
name: "case4",
t: QRType_FORMAT,
want: "f",
},
{
name: "case5",
t: QRType_FINDER,
want: "F",
},
{
name: "case6",
t: QRType_DARK,
want: "D",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.String(); got != tt.want {
t.Errorf("qrtype.String() = %v, want %v", got, tt.want)
}
})
}
}
func Test_qrvalue_String(t *testing.T) {
tests := []struct {
name string
s qrvalue
want string
}{
{
name: "data 0",
s: QRValue_DATA_V0,
want: "d0",
},
{
name: "data 1",
s: QRValue_DATA_V1,
want: "d1",
},
{
name: "version 0",
s: QRValue_VERSION_V0,
want: "V0",
},
{
name: "version 1",
s: QRValue_VERSION_V1,
want: "V1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.String(); got != tt.want {
t.Errorf("qrvalue.String() = %v, want %v", got, tt.want)
}
})
}
}