исправление работы CompactedCoords
This commit is contained in:
@@ -67,6 +67,7 @@ subprojects {
|
||||
/* Testing */
|
||||
testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version)
|
||||
testRuntimeOnly(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version)
|
||||
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit_version)
|
||||
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
|
||||
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19')
|
||||
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
|
||||
|
||||
@@ -14,15 +14,9 @@ public class CompactedCoords {
|
||||
}
|
||||
|
||||
public static int[] uncompressXZ(int compactValue) {
|
||||
//TODO не нравится мне такие костыли
|
||||
return new int[]{
|
||||
(int)(short) (compactValue >> 16),
|
||||
(int)(short) (compactValue | 0xFFFF0000)
|
||||
compactValue >> 16,
|
||||
(compactValue & 0x8000) > 0 ? compactValue | 0xFFFF0000 : compactValue & 0xFFFF
|
||||
};
|
||||
}
|
||||
|
||||
private static int floor_double(double value) {
|
||||
int i = (int)value;
|
||||
return value < (double)i ? i - 1 : i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
package mc.core.utils;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class CompactedCoordsTest {
|
||||
@Test
|
||||
void compressXZ() {
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final int x = random.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
|
||||
final int z = random.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
|
||||
private static Stream<Arguments> streamTestParams() {
|
||||
return Stream.of(
|
||||
Arguments.of(Short.MIN_VALUE, Short.MIN_VALUE),
|
||||
Arguments.of(Short.MIN_VALUE, Short.MAX_VALUE),
|
||||
Arguments.of(Short.MAX_VALUE, Short.MAX_VALUE),
|
||||
Arguments.of(Short.MAX_VALUE, Short.MIN_VALUE),
|
||||
Arguments.of(0, 0),
|
||||
Arguments.of(-1, -1),
|
||||
Arguments.of(-1, 1),
|
||||
Arguments.of(1, 1),
|
||||
Arguments.of(1, -1)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("streamTestParams")
|
||||
void testCompress(int x, int z) {
|
||||
final int compressXZ = CompactedCoords.compressXZ(x, z);
|
||||
int[] xz = CompactedCoords.uncompressXZ(compressXZ);
|
||||
|
||||
assertEquals(x, xz[0]);
|
||||
assertEquals(z, xz[1]);
|
||||
}
|
||||
assertTrue(x == xz[0] && z == xz[1],
|
||||
String.format("x = %d, vx = %d; z = %d, vz = %d",
|
||||
x, xz[0],
|
||||
z, xz[1]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user