удалены тесты
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
package cn.nukkit.test;
|
||||
|
||||
import cn.nukkit.math.Angle;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static cn.nukkit.math.Angle.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Copyright 2017 lmlstarqaq
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
@DisplayName("Angle")
|
||||
class AngleTest {
|
||||
|
||||
@DisplayName("Angle operations")
|
||||
@Test
|
||||
void testAngle() {
|
||||
Angle rd1 = fromRadian(1.0);
|
||||
Angle rf1 = fromRadian(1.0f);
|
||||
Angle dd1 = fromDegree(180.0);
|
||||
Angle df1 = fromDegree(180.0f);
|
||||
|
||||
assertEquals("57.29578\t57.29577951308232\t1.0\t1.0", rd1.asFloatDegree() + "\t" + rd1.asDoubleDegree() + "\t" + rd1.asFloatRadian() + "\t" + rd1.asDoubleRadian());
|
||||
assertEquals("57.295776\t57.29577951308232\t1.0\t1.0", rf1.asFloatDegree() + "\t" + rf1.asDoubleDegree() + "\t" + rf1.asFloatRadian() + "\t" + rf1.asDoubleRadian());
|
||||
assertEquals("180.0\t180.0\t3.1415927\t3.141592653589793", dd1.asFloatDegree() + "\t" + dd1.asDoubleDegree() + "\t" + dd1.asFloatRadian() + "\t" + dd1.asDoubleRadian());
|
||||
assertEquals("180.0\t180.0\t3.1415927\t3.141592653589793", df1.asFloatDegree() + "\t" + df1.asDoubleDegree() + "\t" + df1.asFloatRadian() + "\t" + df1.asDoubleRadian());
|
||||
assertEquals("Angle[Double, 1.000000rad = 57.295780deg] [1072693248]", rd1.toString());
|
||||
assertEquals("Angle[Float, 1.000000rad = 57.295776deg] [1065353216]", rf1.toString());
|
||||
assertEquals("Angle[Double, 180.000000deg = 3.141593rad] [-341077452]", dd1.toString());
|
||||
assertEquals("Angle[Float, 180.000000deg = 3.141593rad] [-386330060]", df1.toString());
|
||||
|
||||
Angle rd2 = fromRadian(200.0);
|
||||
Angle rf2 = fromRadian(200.0f);
|
||||
Angle dd2 = fromDegree(23333.33);
|
||||
Angle df2 = fromDegree(23333.33f);
|
||||
|
||||
assertEquals("11459.156\t11459.155902616465\t200.0\t200.0", rd2.asFloatDegree() + "\t" + rd2.asDoubleDegree() + "\t" + rd2.asFloatRadian() + "\t" + rd2.asDoubleRadian());
|
||||
assertEquals("11459.155\t11459.155902616465\t200.0\t200.0", rf2.asFloatDegree() + "\t" + rf2.asDoubleDegree() + "\t" + rf2.asFloatRadian() + "\t" + rf2.asDoubleRadian());
|
||||
assertEquals("23333.33\t23333.33\t407.24344\t407.24343395436847", dd2.asFloatDegree() + "\t" + dd2.asDoubleDegree() + "\t" + dd2.asFloatRadian() + "\t" + dd2.asDoubleRadian());
|
||||
assertEquals("23333.33\t23333.330078125\t407.24344\t407.243435317907", df2.asFloatDegree() + "\t" + df2.asDoubleDegree() + "\t" + df2.asFloatRadian() + "\t" + df2.asDoubleRadian());
|
||||
|
||||
assertEquals("0.8414709848078965\t0.5403023058681398\t1.5574077246549023", rd1.sin() + "\t" + rd1.cos() + "\t" +rd1.tan());
|
||||
assertEquals("1.2246467991473532E-16\t-1.0\t-1.2246467991473532E-16", dd1.sin() + "\t" + dd1.cos() + "\t" +dd1.tan());
|
||||
|
||||
Angle asin1 = asin(1);
|
||||
Angle asin2 = asin(1.0/2.0);
|
||||
Angle acos1 = acos(1);
|
||||
Angle acos2 = acos(1.0/2.0);
|
||||
Angle atan1 = atan(1);
|
||||
Angle atan2 = atan(1.0/2.0);
|
||||
|
||||
assertEquals("Angle[Double, 1.570796rad = 90.000000deg] [1807551715]\tAngle[Double, 0.000000rad = 0.000000deg] [0]\tAngle[Double, 0.785398rad = 45.000000deg] [1806503139]",
|
||||
asin1.toString() + "\t" + acos1.toString() + "\t" + atan1.toString());
|
||||
assertEquals("Angle[Double, 0.523599rad = 30.000000deg] [130921012]\tAngle[Double, 1.047198rad = 60.000000deg] [131969588]\tAngle[Double, 0.463648rad = 26.565051deg] [985405224]",
|
||||
asin2.toString() + "\t" + acos2.toString() + "\t" + atan2.toString());
|
||||
|
||||
assertEquals(1, compare(asin(2.0/3.0), asin(1.0/2.0)));
|
||||
|
||||
assertEquals("Angle[Double, 22.000000rad = 1260.507149deg] [1077280768]\tAngle[Float, 22.000000rad = 1260.507080deg] [1102053376]",
|
||||
fromRadian(22.0d).toString() + "\t" + fromRadian(22.0f).toString());
|
||||
assertEquals("Angle[Double, 1.000000rad = 57.295780deg] [1072693248]\tAngle[Double, 57.295780deg = 1.000000rad] [-236816880]",
|
||||
fromRadian(1.0d).toString() + "\t" + fromDegree(57.29577951308232d).toString());
|
||||
assertEquals("Angle[Double, 1.000000rad = 57.295780deg] [1072693248]\tAngle[Double, 1.000000deg = 0.017453rad] [-1807936972]",
|
||||
fromRadian(1.0d).toString() + "\t" + fromDegree(1.0d).toString());
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package cn.nukkit.test;
|
||||
|
||||
import cn.nukkit.utils.ClientChainData;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* An example to show how to use ClientChainData
|
||||
* This is also a test for client chain data.
|
||||
*
|
||||
* By lmlstarqaq http://snake1999.com/
|
||||
* Creation time: 2017/6/7 15:07.
|
||||
*/
|
||||
@DisplayName("ClientChainData")
|
||||
class ClientChainDataTest {
|
||||
|
||||
@DisplayName("Getters")
|
||||
@Test
|
||||
void testGetter() throws Exception {
|
||||
InputStream is = ClientChainDataTest.class.getResourceAsStream("chain.dat");
|
||||
ClientChainData data = ClientChainData.of(readStream(is));
|
||||
String got = String.format("userName=%s, clientUUID=%s, " +
|
||||
"identityPublicKey=%s, clientId=%d, " +
|
||||
"serverAddress=%s, deviceModel=%s, " +
|
||||
"deviceOS=%d, gameVersion=%s, " +
|
||||
"guiScale=%d, languageCode=%s, " +
|
||||
"xuid=%s, currentInputMode=%d, " +
|
||||
"defaultInputMode=%d, UIProfile=%d"
|
||||
,
|
||||
data.getUsername(), data.getClientUUID(),
|
||||
data.getIdentityPublicKey(), data.getClientId(),
|
||||
data.getServerAddress(), data.getDeviceModel(),
|
||||
data.getDeviceOS(), data.getGameVersion(),
|
||||
data.getGuiScale(), data.getLanguageCode(),
|
||||
data.getXUID(), data.getCurrentInputMode(),
|
||||
data.getDefaultInputMode(), data.getUIProfile()
|
||||
);
|
||||
String expecting = "userName=lmlstarqaq, clientUUID=8323afe1-641e-3b61-9a92-d5d20b279065, " +
|
||||
"identityPublicKey=MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE4lyvA1iVhV2u3pLQqJAjJnJZSlSjib8mM1uB5h5yqOBSvCHW+nZxDmkOAW6MS1GA7yGHitGmfS4jW/yUISUdWvLzEWJYOzphb3GNh5J1oLJRwESc5278i4MEDk1y21/q, " +
|
||||
"clientId=-6315607246631494544, " +
|
||||
"serverAddress=192.168.1.108:19132, deviceModel=iPhone6,2, " +
|
||||
"deviceOS=2, gameVersion=1.1.0, " +
|
||||
"guiScale=0, languageCode=zh_CN, " +
|
||||
"xuid=2535465134455915, currentInputMode=2, " +
|
||||
"defaultInputMode=2, UIProfile=1";
|
||||
assertEquals(got, expecting);
|
||||
}
|
||||
|
||||
private static byte[] readStream(InputStream inStream) throws Exception {
|
||||
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[65536];
|
||||
int len;
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
outSteam.write(buffer, 0, len);
|
||||
}
|
||||
outSteam.close();
|
||||
inStream.close();
|
||||
return outSteam.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package cn.nukkit.test;
|
||||
|
||||
import cn.nukkit.utils.BinaryStream;
|
||||
import cn.nukkit.utils.VarInt;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* By lmlstarqaq http://snake1999.com/
|
||||
* Creation time: 2017/7/5 23:22.
|
||||
*/
|
||||
@DisplayName("VarInt")
|
||||
class VarIntTest {
|
||||
|
||||
@DisplayName("ZigZag")
|
||||
@Test
|
||||
void testZigZag() {
|
||||
assertAll(
|
||||
() -> assertEquals(0x2468acf0, VarInt.encodeZigZag32(0x12345678)),
|
||||
() -> assertEquals(0x2b826b1d, VarInt.encodeZigZag32(0xea3eca71)),
|
||||
() -> assertEquals(0x12345678, VarInt.decodeZigZag32(0x2468acf0)),
|
||||
() -> assertEquals(0xea3eca71, VarInt.decodeZigZag32(0x2b826b1d)),
|
||||
() -> assertEquals(2623536930346282224L, VarInt.encodeZigZag64(0x1234567812345678L)),
|
||||
() -> assertEquals(3135186066796324391L, VarInt.encodeZigZag64(0xea3eca710becececL)),
|
||||
() -> assertEquals(0x1234567812345678L, VarInt.decodeZigZag64(2623536930346282224L)),
|
||||
() -> assertEquals(0xea3eca710becececL, VarInt.decodeZigZag64(3135186066796324391L))
|
||||
);
|
||||
}
|
||||
|
||||
@DisplayName("Writing")
|
||||
@Test
|
||||
void testWrite() throws IOException {
|
||||
BinaryStream bs = new BinaryStream();
|
||||
VarInt.writeUnsignedVarInt(bs, 237356812);
|
||||
VarInt.writeVarInt(bs, 0xea3eca71);
|
||||
VarInt.writeUnsignedVarLong(bs, 0x1234567812345678L);
|
||||
VarInt.writeVarLong(bs, 0xea3eca710becececL);
|
||||
assertAll(
|
||||
() -> assertEquals(237356812, VarInt.readUnsignedVarInt(bs)),
|
||||
() -> assertEquals(0xea3eca71, VarInt.readVarInt(bs)),
|
||||
() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(bs)),
|
||||
() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(bs))
|
||||
);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
VarInt.writeUnsignedVarInt(os, 237356812);
|
||||
VarInt.writeVarInt(os, 0xea3eca71);
|
||||
VarInt.writeUnsignedVarLong(os, 0x1234567812345678L);
|
||||
VarInt.writeVarLong(os, 0xea3eca710becececL);
|
||||
VarInt.writeVarInt(os, 0x7FFFFFFF);
|
||||
VarInt.writeVarInt(os, -1);
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
assertAll(
|
||||
() -> assertEquals(237356812, VarInt.readUnsignedVarInt(is)),
|
||||
() -> assertEquals(0xea3eca71, VarInt.readVarInt(is)),
|
||||
() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(is)),
|
||||
() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(is)),
|
||||
() -> assertEquals(0x7FFFFFFF, VarInt.readVarInt(is)),
|
||||
() -> assertEquals(-1, VarInt.readVarInt(is))
|
||||
);
|
||||
}
|
||||
|
||||
@DisplayName("Write Sizes")
|
||||
@Test
|
||||
void testSizes() throws IOException {
|
||||
sizeTest(w -> VarInt.writeVarLong(w, 0x7FFFFFFF /* -1 >>> 1 */), 5);
|
||||
sizeTest(w -> VarInt.writeVarInt(w, 0x7FFFFFFF /* -1 >>> 1 */), 5);
|
||||
sizeTest(w -> VarInt.writeVarLong(w, -1), 1);
|
||||
sizeTest(w -> VarInt.writeVarInt(w, -1), 1);
|
||||
}
|
||||
|
||||
@DisplayName("Reading")
|
||||
@Test
|
||||
void testRead() {
|
||||
assertAll(
|
||||
() -> assertEquals(2412, VarInt.readUnsignedVarInt(wrapBinaryStream("EC123EC456"))),
|
||||
() -> assertEquals(583868, VarInt.readUnsignedVarInt(wrapBinaryStream("BCD123EFA0"))),
|
||||
() -> assertEquals(1206, VarInt.readVarInt(wrapBinaryStream("EC123EC456"))),
|
||||
() -> assertEquals(291934, VarInt.readVarInt(wrapBinaryStream("BCD123EFA0"))),
|
||||
() -> assertEquals(6015, VarInt.readUnsignedVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
|
||||
() -> assertEquals(3694, VarInt.readUnsignedVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD"))),
|
||||
() -> assertEquals(-3008, VarInt.readVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
|
||||
() -> assertEquals(1847, VarInt.readVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD")))
|
||||
);
|
||||
}
|
||||
|
||||
private static BinaryStream wrapBinaryStream(String hex) {
|
||||
return new BinaryStream(hexStringToByte(hex));
|
||||
}
|
||||
|
||||
private static byte[] hexStringToByte(String hex) {
|
||||
int len = (hex.length() / 2);
|
||||
byte[] result = new byte[len];
|
||||
char[] aChar = hex.toCharArray();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int pos = i * 2;
|
||||
result[i] = (byte) (toByte(aChar[pos]) << 4 | toByte(aChar[pos + 1]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte toByte(char c) {
|
||||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||||
}
|
||||
|
||||
private interface TestConsumer<T> {
|
||||
void accept(T t) throws IOException;
|
||||
}
|
||||
|
||||
private void sizeTest(TestConsumer<ByteArrayOutputStream> write, int size) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
write.accept(os);
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
assertEquals(size, is.available());
|
||||
};
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package cn.nukkit.test;
|
||||
|
||||
import cn.nukkit.utils.Zlib;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
@DisplayName("Zlib")
|
||||
class ZlibTest {
|
||||
|
||||
@DisplayName("Inflate and Deflate")
|
||||
@Test
|
||||
void testAll() throws Exception {
|
||||
byte[] in = "lmlstarqaq".getBytes();
|
||||
byte[] compressed = Zlib.deflate(in);
|
||||
byte[] out = Zlib.inflate(compressed);
|
||||
assertArrayEquals(in, out);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user