-
Notifications
You must be signed in to change notification settings - Fork 0
/
deflate-fast_test.mbt
89 lines (85 loc) · 2.54 KB
/
deflate-fast_test.mbt
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
// This file is based on the Go implementation found here:
// https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/compress/flate/deflate_test.go
// which has the copyright notice:
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TestBestSpeed tests that round-tripping through deflate and then inflate
// recovers the original input. The Write sizes are near the thresholds in the
// compressor.encSpeed method (0, 16, 128), as well as near maxStoreBlockSize
// (65535).
test "TestBestSpeed" {
let abc_len = 128
let abc = Bytes::make(abc_len, b'\x00')
for i = 0; i < abc_len; i = i + 1 {
abc[i] = i.to_byte()
}
let num_copies = 131072 / abc_len
let abcabc = Bytes::new(abc_len * num_copies)
for i = 0; i < num_copies; i = i + 1 {
blit(abcabc, i * abc_len, abc, 0, abc_len)
}
//
let test_cases = [
[65536, 0],
[65536, 1],
[65536, 1, 256],
[65536, 1, 65536],
[65536, 14],
[65536, 15],
[65536, 16],
[65536, 16, 256],
[65536, 16, 65536],
[65536, 127],
[65536, 128],
[65536, 128, 256],
[65536, 128, 65536],
[65536, 129],
[65536, 65536, 256],
[65536, 65536, 65536],
]
//
let mut i = 0
for tc in test_cases {
for first_n in [1, 65534, 65535, 65536, 65537, 131072] {
i += 1
tc[0] = first_n
let buf = @io.Buffer::new()
let want = @io.Buffer::new()
let w : &@io.WriteCloser = @flate.Writer::new(buf)
for n in tc {
let subset = Bytes::new(n)
subset.blit(0, abcabc, 0, n)
guard let (_, None) = want.write_bytes(subset) else {
e =>
abort(
"test #\{i}: want.write_bytes(subset): unexpected error: \{e}",
)
}
guard let (_, None) = w.write(@io.Slice::new(subset.to_array())) else {
e => abort("test #\{i}: w.write(): unexpected error: \{e}")
}
// if not(flush) {
// continue
// }
// w.flush!()
}
let want = want.to_bytes()
guard let None = w.close() else {
e => abort("test #\{i}: w.close(): unexpected error: \{e}")
}
//
let got = @io.Buffer::new()
let r : &@io.ReadCloser = &@flate.Reader::new(buf)
guard let (_, None) = @io.copy(got, r) else {
e => abort("test #\{i}: @io.copy: \{e}")
}
try {
let got = got.to_bytes()
assert_eq!(got, want)
} catch {
_ => abort("test #\{i} FAILED")
}
}
}
}