Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.dfa1.zstd.it;

import io.github.dfa1.zstd.Zstd;

import java.util.Random;

final class ItTestSupport {

static final int[] LEVELS = {
Zstd.minCompressionLevel(), 1, Zstd.defaultCompressionLevel(), Zstd.maxCompressionLevel()
};

static byte[] random(Random r, int size) {
byte[] b = new byte[size];
r.nextBytes(b);
return b;
}

static byte[] compressible(Random r, int size) {
byte[] b = new byte[size];
for (int i = 0; i < size; i++) {
b[i] = (byte) ((i % 13 == 0) ? r.nextInt(256) : 'a' + (i % 8));
}
return b;
}

private ItTestSupport() {
// no instances
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Random;
import java.util.stream.Stream;

import static io.github.dfa1.zstd.it.ItTestSupport.random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -294,11 +295,5 @@ private static void writeInChunks(java.io.OutputStream out, byte[] data) throws
out.flush();
}
}

private static byte[] random(Random r, int size) {
byte[] b = new byte[size];
r.nextBytes(b);
return b;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Random;
import java.util.stream.Stream;

import static io.github.dfa1.zstd.it.ItTestSupport.LEVELS;
import static io.github.dfa1.zstd.it.ItTestSupport.compressible;
import static io.github.dfa1.zstd.it.ItTestSupport.random;
import static org.assertj.core.api.Assertions.assertThat;

/// Format-compatibility tests: frames produced by the reference zstd-jni binding
Expand All @@ -35,10 +38,9 @@ static Stream<Arguments> payloadsAndLevels() {
Random r = new Random(0xABCD);
List<Arguments> cases = new ArrayList<>();
int[] sizes = {0, 1, 1024, 64 * 1024, 1024 * 1024};
int[] levels = {Zstd.minCompressionLevel(), 1, Zstd.defaultCompressionLevel(), Zstd.maxCompressionLevel()};
for (int size : sizes) {
byte[] data = size % 2 == 0 ? compressible(r, size) : random(r, size);
for (int level : levels) {
for (int level : LEVELS) {
cases.add(Arguments.of(level, data));
}
}
Expand Down Expand Up @@ -171,18 +173,4 @@ private byte[] sample(int i) {
.getBytes(StandardCharsets.UTF_8);
}
}

private static byte[] random(Random r, int size) {
byte[] b = new byte[size];
r.nextBytes(b);
return b;
}

private static byte[] compressible(Random r, int size) {
byte[] b = new byte[size];
for (int i = 0; i < size; i++) {
b[i] = (byte) ((i % 13 == 0) ? r.nextInt(256) : 'a' + (i % 8));
}
return b;
}
}
Loading