MCPcopy
hub / github.com/skip2/go-qrcode / TestOptimiseEncoding

Function TestOptimiseEncoding

encoder_test.go:146–376  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestOptimiseEncoding(t *testing.T) {
147 tests := []struct {
148 dataEncoderType dataEncoderType
149 actual []testModeSegment
150 optimised []testModeSegment
151 }{
152 // Coalescing multiple segments.
153 {
154 dataEncoderType1To9,
155 []testModeSegment{
156 {dataModeAlphanumeric, 1}, // length = 4 + 9 + 6 = 19 bits
157 {dataModeNumeric, 1}, // length = 4 + 10 + 4 = 18 bits
158 {dataModeAlphanumeric, 1}, // 19 bits.
159 {dataModeNumeric, 1}, // 18 bits.
160 {dataModeAlphanumeric, 1}, // 19 bits.
161 // total = 93 bits.
162 },
163 []testModeSegment{
164 {dataModeAlphanumeric, 5}, // length = 4 + 9 + 22 + 6 = 41.
165 },
166 },
167 // Coalesing not necessary.
168 {
169 dataEncoderType1To9,
170 []testModeSegment{
171 {dataModeAlphanumeric, 1},
172 {dataModeNumeric, 20},
173 },
174 []testModeSegment{
175 {dataModeAlphanumeric, 1},
176 {dataModeNumeric, 20},
177 },
178 },
179 // Switch to more general dataMode.
180 {
181 dataEncoderType1To9,
182 []testModeSegment{
183 {dataModeAlphanumeric, 100},
184 {dataModeByte, 1},
185 {dataModeNumeric, 1},
186 },
187 []testModeSegment{
188 {dataModeAlphanumeric, 100},
189 {dataModeByte, 2},
190 },
191 },
192 // Sometimes encoding everything as bytes is more efficient.
193 {
194 dataEncoderType1To9,
195 []testModeSegment{
196 {dataModeAlphanumeric, 1},
197 {dataModeByte, 1},
198 {dataModeNumeric, 1},
199 },
200 []testModeSegment{
201 {dataModeByte, 3},
202 },
203 },

Callers

nothing calls this directly

Calls 4

newDataEncoderFunction · 0.85
segmentsStringFunction · 0.85
testModeSegmentsStringFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…