Archived
0

обновлен тест CompactedCoords

This commit is contained in:
2018-09-08 02:17:27 +03:00
parent 1a2ebcfa0a
commit 6808ae34f9

View File

@@ -3,40 +3,21 @@ package mc.core.utils;
import org.junit.Test;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertEquals;
public class TestCompactedCoords {
@Test
public void testXZSimple() {
for (int z = -100; z <= 100; z++) {
for (int x = -100; x <= 100; x++) {
int compressXZ = CompactedCoords.compressXZ(x, z);
int[] xz = CompactedCoords.uncompressXZ(compressXZ);
assertEquals(x, xz[0]);
assertEquals(z, xz[1]);
}
}
}
@Test
public void testXZRandom() {
Random random = new Random();
int x,z;
public void testXZ() {
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < 100; i++) {
do {
x = random.nextInt();
} while (x < Short.MIN_VALUE || x > Short.MAX_VALUE);
final int x = random.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
final int z = random.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
do {
z = random.nextInt();
} while (z < Short.MIN_VALUE || z > Short.MAX_VALUE);
int compressXZ = CompactedCoords.compressXZ(x, z);
final int compressXZ = CompactedCoords.compressXZ(x, z);
int[] xz = CompactedCoords.uncompressXZ(compressXZ);
assertEquals(x, xz[0]);