Fixing BuildMatrixFromByte Finish
Signed-off-by: Anthony Debucquoy <debucquoy.anthony@gmail.com>
This commit is contained in:
parent
4a14c5d2e6
commit
3ce26796a8
@ -140,6 +140,7 @@ public class BinaryParser implements FileParser {
|
||||
* @return byte array with each element compiled for file format
|
||||
*/
|
||||
static byte[] BuildByteFromMatrix(boolean[][] shape){
|
||||
// TODO: 3/27/23 Problem with this function to investigate
|
||||
int width = shape[0].length , height = shape.length;
|
||||
boolean[] list = new boolean[width * height];
|
||||
for (int x = 0; x < shape.length; x++) {
|
||||
@ -178,7 +179,7 @@ public class BinaryParser implements FileParser {
|
||||
for (int i = 0; i < 8; i++) { // because 8 bit in a byte
|
||||
b_array[index] = Bitwise.IsBitSetAt(b, i);
|
||||
index++;
|
||||
if(index <= matrix_height * matrix_width)
|
||||
if(index >= matrix_height * matrix_width)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class BinaryParserTest {
|
||||
{true, true, false, false, true, true},
|
||||
{true, true, true, true, true, true},
|
||||
};
|
||||
assertEquals(map_shape, BinaryParser.BuildMatrixFromBytes(6, 5, map_data));
|
||||
assertArrayEquals(map_shape, BinaryParser.BuildMatrixFromBytes(6, 5, map_data));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -107,7 +107,7 @@ class BinaryParserTest {
|
||||
byte[] piece3_data = Arrays.copyOfRange(file_data, 16, 17);
|
||||
boolean[][] piece3_shape = {
|
||||
{false, true, true},
|
||||
{true, true, false},
|
||||
{true, true, true},
|
||||
};
|
||||
assertArrayEquals(piece3_shape, BinaryParser.BuildMatrixFromBytes(3, 2, piece3_data));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user