added random_compress.nim to tests/
This commit is contained in:
parent
f5f70c8611
commit
51d140df5f
|
@ -449,7 +449,8 @@ func deflate*(src: seq[uint8]): seq[uint8] =
|
|||
b.data.setLen(
|
||||
b.data.len +
|
||||
(((hclen.int + 4) * 3 + 7) div 8) + # hclen rle
|
||||
bitLensRle.len * 2
|
||||
bitLensRle.len * 2 +
|
||||
encoded.len
|
||||
)
|
||||
|
||||
b.addBit(1)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import random, zippy
|
||||
|
||||
randomize()
|
||||
|
||||
# Generate random blobs of data containing runs of random lengths. Ensure
|
||||
# we can always compress this blob and that uncompressing the compressed
|
||||
# data matches the original blob.
|
||||
|
||||
for i in 0 ..< 10000:
|
||||
echo i
|
||||
|
||||
var
|
||||
data: seq[uint8]
|
||||
length = rand(100000)
|
||||
i: int
|
||||
data.setLen(length)
|
||||
while i < length:
|
||||
let
|
||||
v = rand(255).uint8
|
||||
runLength = min(rand(255), length - i)
|
||||
for j in 0 ..< runLength:
|
||||
data[i + j] = v
|
||||
inc(i, runLength)
|
||||
|
||||
let
|
||||
compressed = compress(data, dfGzip)
|
||||
uncompressed = uncompress(compressed)
|
||||
doAssert uncompressed == data
|
Loading…
Reference in New Issue