Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed May 6, 2023
1 parent a8e28d1 commit 2e3eab5
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/block/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ mod tests {
#[test]
fn test_dict() {
let input: &[u8] = &[
10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18,
10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 14, 16,
18, 10, 12, 14, 16, 18,
];
let dict = input;
let compressed = compress_with_dict(input, dict);
Expand All @@ -841,7 +842,8 @@ mod tests {
#[test]
fn test_dict_match_crossing() {
let input: &[u8] = &[
10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18,
10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12,
14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18,
];
let dict = input;
let compressed = compress_with_dict(input, dict);
Expand Down Expand Up @@ -878,33 +880,33 @@ mod tests {
// so it needs at least one prior byte.
// When a block can reference data from another block, it can start immediately with a match
// and no literal, so a block of 12 bytes can be compressed.
let aaas: &[u8] = b"aaaaaaaaaaaaaaa";
let aaas: &[u8] = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

// uncompressible
let out = compress(&aaas[..12]);
assert_gt!(out.len(), 12);
let out = compress(&aaas[..MFLIMIT]);
assert_gt!(out.len(), MFLIMIT);
// compressible
let out = compress(&aaas[..13]);
assert_le!(out.len(), 13);
let out = compress(&aaas[..14]);
assert_le!(out.len(), 14);
let out = compress(&aaas[..15]);
assert_le!(out.len(), 15);
let out = compress(&aaas[..MFLIMIT + 1]);
assert_le!(out.len(), MFLIMIT + 1);
let out = compress(&aaas[..MFLIMIT + 2]);
assert_le!(out.len(), MFLIMIT + 2);
let out = compress(&aaas[..MFLIMIT + 3]);
assert_le!(out.len(), MFLIMIT + 3);

// dict uncompressible
let out = compress_with_dict(&aaas[..11], aaas);
assert_gt!(out.len(), 11);
let out = compress_with_dict(&aaas[..MFLIMIT - 1], aaas);
assert_gt!(out.len(), MFLIMIT - 1);
// compressible
let out = compress_with_dict(&aaas[..12], aaas);
let out = compress_with_dict(&aaas[..MFLIMIT], aaas);
// According to the spec this _could_ compres, but it doesn't in this lib
// as it aborts compression for any input len < LZ4_MIN_LENGTH
assert_gt!(out.len(), 12);
let out = compress_with_dict(&aaas[..13], aaas);
assert_le!(out.len(), 13);
let out = compress_with_dict(&aaas[..14], aaas);
assert_le!(out.len(), 14);
let out = compress_with_dict(&aaas[..15], aaas);
assert_le!(out.len(), 15);
assert_gt!(out.len(), MFLIMIT);
let out = compress_with_dict(&aaas[..MFLIMIT + 1], aaas);
assert_le!(out.len(), MFLIMIT + 1);
let out = compress_with_dict(&aaas[..MFLIMIT + 2], aaas);
assert_le!(out.len(), MFLIMIT + 2);
let out = compress_with_dict(&aaas[..MFLIMIT + 3], aaas);
assert_le!(out.len(), MFLIMIT + 3);
}

#[test]
Expand Down

0 comments on commit 2e3eab5

Please sign in to comment.