blob: d238504c51a9c631e95bc317f30c1f3553e3a261 (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.compress;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
*/
class ZstdCompressorTest {
@Test
void compresses_and_decompresses_input() {
byte[] inputData = "The quick brown fox jumps over the lazy dog".getBytes();
ZstdCompressor compressor = new ZstdCompressor();
byte[] compressedData = compressor.compress(inputData, 0, inputData.length);
byte[] decompressedData = compressor.decompress(compressedData, 0, compressedData.length);
assertArrayEquals(inputData, decompressedData);
}
@Test
void compressed_size_is_less_than_uncompressed() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 100; i++) {
builder.append("The quick brown fox jumps over the lazy dog").append('\n');
}
byte[] inputData = builder.toString().getBytes();
ZstdCompressor compressor = new ZstdCompressor();
byte[] compressedData = compressor.compress(inputData, 0, inputData.length);
assertTrue(
compressedData.length < inputData.length,
() -> "Compressed size is " + compressedData.length + " while uncompressed size is " + inputData.length);
}
}
|