MCPcopy
hub / github.com/klauspost/compress / TestCompress1X

Function TestCompress1X

huff0/compress_test.go:224–270  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

222}
223
224func TestCompress1X(t *testing.T) {
225 for _, test := range testfiles {
226 t.Run(test.name, func(t *testing.T) {
227 var s Scratch
228 buf0, err := test.fn()
229 if err != nil {
230 t.Fatal(err)
231 }
232 if len(buf0) > BlockSizeMax {
233 buf0 = buf0[:BlockSizeMax]
234 }
235 tbSz, dSz, reSz, _ := EstimateSizes(buf0, &s)
236 b, re, err := Compress1X(buf0, &s)
237 if err != test.err1X {
238 t.Errorf("want error %v (%T), got %v (%T)", test.err1X, test.err1X, err, err)
239 }
240 if err != nil {
241 t.Log(test.name, err.Error())
242 return
243 }
244 if b == nil {
245 t.Error("got no output")
246 return
247 }
248 min := s.minSize(len(buf0))
249 if len(s.OutData) < min {
250 t.Errorf("output data length (%d) below shannon limit (%d)", len(s.OutData), min)
251 }
252 if len(s.OutTable) == 0 {
253 t.Error("got no table definition")
254 }
255 if re {
256 t.Error("claimed to have re-used.")
257 }
258 if len(s.OutData) == 0 {
259 t.Error("got no data output")
260 }
261 t.Logf("Estimate: table %d, got %d, data %d, got %d, reuse: %d", tbSz, len(s.OutTable), dSz, len(s.OutData), reSz)
262 t.Logf("%s: %d -> %d bytes (%.2f:1) re:%t (table: %d bytes)", test.name, len(buf0), len(b), float64(len(buf0))/float64(len(b)), re, len(s.OutTable))
263 s.Out = nil
264 bRe, _, err := Compress1X(b, &s)
265 if err == nil {
266 t.Log("Could re-compress to", len(bRe))
267 }
268 })
269 }
270}
271
272func TestCompress1XMustReuse(t *testing.T) {
273 for _, test := range testfiles {

Callers

nothing calls this directly

Calls 5

minSizeMethod · 0.95
EstimateSizesFunction · 0.85
Compress1XFunction · 0.85
FatalMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…