Fixed failing TCs
This commit is contained in:
parent
3edc220ed8
commit
fffaa64455
2 changed files with 12 additions and 4 deletions
|
|
@ -64,7 +64,7 @@ public class ByteUtil {
|
|||
* @return a new byte containing a sub byte defined by the index and length
|
||||
*/
|
||||
public static byte getBits(byte data, int length){
|
||||
return getBits(data, 0, length);
|
||||
return getBits(data, length-1, length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,9 +119,9 @@ public class ByteUtil {
|
|||
public static byte getBitMask(int index, int length) {
|
||||
--length;
|
||||
if(0 > index || index > 7)
|
||||
throw new IllegalArgumentException("Invalid index argument, allowed value is 0-7");
|
||||
if(length < 0 || 7-index-length < 0)
|
||||
throw new IllegalArgumentException("Invalid length argument: "+length+", allowed values 1-8 depending on index");
|
||||
throw new IllegalArgumentException("Invalid index argument, allowed values: 0-7");
|
||||
if(length < 0 || index-length < 0)
|
||||
throw new IllegalArgumentException("Invalid length argument: "+length+", allowed values: 1 to "+(index+1)+" for index "+index);
|
||||
return (byte) BYTE_MASK[index][length];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,14 @@ public class ByteUtilTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getBits(){
|
||||
assertEquals(0x01, ByteUtil.getBits((byte)0xFF, 1));
|
||||
assertEquals(0x0F, ByteUtil.getBits((byte)0xFF, 4));
|
||||
assertEquals((byte)0xFF, ByteUtil.getBits((byte)0xFF, 8));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBitsArray(){
|
||||
assertArrayEquals(new byte[]{}, ByteUtil.getBits(new byte[]{0x00}, 0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue