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

Function TestCompress1XMustReuse

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

Source from the content-addressed store, hash-verified

270}
271
272func TestCompress1XMustReuse(t *testing.T) {
273 for _, test := range testfiles {
274 t.Run(test.name, func(t *testing.T) {
275 var s Scratch
276 buf0, err := test.fn()
277 if err != nil {
278 t.Fatal(err)
279 }
280 if len(buf0) > BlockSizeMax {
281 buf0 = buf0[:BlockSizeMax]
282 }
283 b, re, err := Compress1X(buf0, &s)
284 if err != test.err1X {
285 t.Errorf("want error %v (%T), got %v (%T)", test.err1X, test.err1X, err, err)
286 }
287 if err != nil {
288 t.Log(test.name, err.Error())
289 return
290 }
291 if b == nil {
292 t.Error("got no output")
293 return
294 }
295
296 min := s.minSize(len(buf0))
297 if len(s.OutData) < min {
298 t.Errorf("output data length (%d) below shannon limit (%d)", len(s.OutData), min)
299 }
300 if len(s.OutTable) == 0 {
301 t.Error("got no table definition")
302 }
303 if re {
304 t.Error("claimed to have re-used.")
305 }
306 if len(s.OutData) == 0 {
307 t.Error("got no data output")
308 }
309 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))
310 table := s.OutTable
311 prevTable := s.prevTable
312 for i, v := range prevTable {
313 // Clear unused sections for comparison
314 if v.nBits == 0 {
315 prevTable[i].val = 0
316 }
317 }
318 b = s.OutData
319 actl := s.actualTableLog
320
321 // Use only the table data to recompress.
322 s = Scratch{}
323 s2 := &s
324 s.Reuse = ReusePolicyMust
325 s2, _, err = ReadTable(table, s2)
326 if err != nil {
327 t.Error("Could not read table", err)
328 return
329 }

Callers

nothing calls this directly

Calls 5

minSizeMethod · 0.95
Compress1XFunction · 0.85
ReadTableFunction · 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…