Moved some test classes to the test folder
This commit is contained in:
parent
6c81d79332
commit
ccead35ee7
3 changed files with 15 additions and 5 deletions
|
|
@ -59,11 +59,11 @@ public class Converter {
|
||||||
* @return a byte array of four bytes
|
* @return a byte array of four bytes
|
||||||
*/
|
*/
|
||||||
public static byte[] toBytes(int num){
|
public static byte[] toBytes(int num){
|
||||||
return new byte[]{
|
return new byte[]{
|
||||||
(byte)(num & 0xff),
|
(byte)((num >> 24)& 0xff),
|
||||||
(byte)((num >> 8)& 0xff),
|
(byte)((num >> 16)& 0xff),
|
||||||
(byte)((num >> 16)& 0xff),
|
(byte)((num >> 8)& 0xff),
|
||||||
(byte)((num >> 24)& 0xff)};
|
(byte)(num & 0xff)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -90,4 +90,14 @@ public class ConverterTest {
|
||||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void intToByteArray(){
|
||||||
|
assertArrayEquals(new byte[]{0x00,0x00,0x00,0x00}, Converter.toBytes(0));
|
||||||
|
assertArrayEquals(new byte[]{0x00,0x00,0x00,0x01}, Converter.toBytes(1));
|
||||||
|
assertArrayEquals(new byte[]{0x00,0x00,0x01,0x00}, Converter.toBytes(256));
|
||||||
|
assertArrayEquals(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}, Converter.toBytes(-1));
|
||||||
|
assertArrayEquals(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF}, Converter.toBytes(Integer.MAX_VALUE));
|
||||||
|
assertArrayEquals(new byte[]{(byte)0x80,(byte)0x00,(byte)0x00,(byte)0x00}, Converter.toBytes(Integer.MIN_VALUE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue