mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
发现两处新错误
This commit is contained in:
1 parent
8f75fad759
commit
e4c549fdb8
1 file changed
+36
-16
@@ -44,51 +44,71 @@ public class VlIntTest {
|
||||
public void getVlIntValue2Int() {
|
||||
//vlint(int)的size小于4时,测试是否能准确转为int输出
|
||||
int a = 222;
|
||||
int b = 22222222;
|
||||
int a2 = 22222222;
|
||||
byte[] b1 = new byte[]{0x00,0x7f, (byte) 0xff}; //32767
|
||||
byte[] b2 = new byte[]{0x00,(byte) 0x80, 0x00}; //32768
|
||||
byte[] b3 = new byte[]{0x00,(byte) 0xff, (byte) 0xff};//65535
|
||||
VlInt vlInt_int1 = new VlInt(a);
|
||||
VlInt vlInt_int2 = new VlInt(b);
|
||||
VlInt vlInt_int2 = new VlInt(a2);
|
||||
VlInt vlInt_b1 = new VlInt(b1);
|
||||
VlInt vlInt_b2 = new VlInt(b2);
|
||||
VlInt vlInt_b3 = new VlInt(b3);
|
||||
//测试size大小
|
||||
assertTrue(vlInt_int1.size()<4);
|
||||
assertFalse(vlInt_int2.size()<4);
|
||||
//测试VlIntValue是否转为int
|
||||
assertEquals(vlInt_int1.getVlIntValue2Int(),a);
|
||||
assertEquals(vlInt_b1.getVlIntValue2Int(),32767);
|
||||
assertEquals(vlInt_b2.getVlIntValue2Int(),32768);
|
||||
assertEquals(vlInt_b3.getVlIntValue2Int(),65535);
|
||||
}
|
||||
|
||||
|
||||
//error:以bytes[]形式构造的VlInt,2^31-1 到 2^32-1之间的数会出错
|
||||
@Test
|
||||
public void getVlIntValue2Long() {
|
||||
long l1 = new Long(0);
|
||||
long l2 = new Long(1);
|
||||
long l3 = new Long(4294967295L); //2^32-1
|
||||
long l4 = new Long(4294967296L); //2^32
|
||||
byte[] b1 = new byte[]{0x00,0x7f,(byte) 0xff,(byte) 0xff,(byte) 0xff};//2^31-1
|
||||
byte[] b2= new byte[]{0x00,(byte) 0x80,0x00,0x00,0x00};//2^31
|
||||
|
||||
VlInt vlInt_long1 = new VlInt(l1); // size = 1
|
||||
VlInt vlInt_long2 = new VlInt(l2); // size = 1
|
||||
VlInt vlInt_long3 = new VlInt(l3); // size = 5
|
||||
VlInt vlInt_long4 = new VlInt(l4); // size = 9
|
||||
|
||||
assertTrue(vlInt_long3.size()<8);
|
||||
assertFalse(vlInt_long4.size()<8);
|
||||
VlInt vlInt_long4 = new VlInt(b1);
|
||||
VlInt vlInt_long5 = new VlInt(b2);
|
||||
//以VlInt(long)形式构造的VlInt
|
||||
assertEquals(vlInt_long1.getVlIntValue2Long(),l1);
|
||||
assertEquals(vlInt_long2.getVlIntValue2Long(),l2);
|
||||
assertEquals(vlInt_long3.getVlIntValue2Long(),l3);
|
||||
///以VlInt(bytes[])形式构造的VlInt
|
||||
assertEquals(vlInt_long4.getVlIntValue2Long(),2147483647L);//2^31-1
|
||||
assertEquals(vlInt_long5.getVlIntValue2Long(),2147483648L);//2^31
|
||||
}
|
||||
|
||||
//error:以bytes[]形式构造的VlInt,在大于2^31-1的数会出错
|
||||
@Test
|
||||
public void getVlIntValue() {
|
||||
long l1 = new Long(4294967295L); //2^32-1
|
||||
long l2 = new Long(4294967296L); //2^32
|
||||
BigInteger b_0 = BigInteger.valueOf(2147483647L);//2^31-1
|
||||
BigInteger b_1 = BigInteger.valueOf(2147483648L);//2^31
|
||||
BigInteger b = BigInteger.valueOf(4294967296L);//2^32
|
||||
//2^31-1
|
||||
byte[] b0 = new byte[]{0x00,0x00,0x00,0x00,0x00,0x7f,(byte) 0xff,(byte) 0xff,(byte) 0xff};//2147483647
|
||||
byte[] b1 = new byte[]{0x00,0x00,0x00,0x00,0x00,(byte) 0x80,0x00,0x00,0x00};
|
||||
//2^32-1
|
||||
byte[] b2 = new byte[]{0x00,0x00,0x00,0x00,0x00,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff};
|
||||
byte[] b3 = new byte[]{0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};//2^32
|
||||
|
||||
VlInt vlInt_long = new VlInt(l1);
|
||||
VlInt vlInt_long2 = new VlInt(l2);
|
||||
VlInt vlInt_bigInteger = new VlInt(b);
|
||||
//判断size
|
||||
assertFalse(vlInt_long.size()>=9);
|
||||
assertTrue(vlInt_long2.size()>=9);
|
||||
assertTrue(vlInt_bigInteger.size()>=9);
|
||||
//判断值是否相等
|
||||
VlInt vlInt_b0 = new VlInt(b0);
|
||||
VlInt vlInt_b1 = new VlInt(b1);
|
||||
//以VlInt(BigInteger)形式构造的VlInt
|
||||
assertEquals(vlInt_bigInteger.getVlIntValue(),b);
|
||||
///以VlInt(bytes[])形式构造的VlInt
|
||||
assertEquals(vlInt_b0.getVlIntValue(),b_0);
|
||||
assertEquals(vlInt_b1.getVlIntValue(),b_1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user