Fixing BuildMatrixFromByte Finish
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing

Signed-off-by: Anthony Debucquoy <debucquoy.anthony@gmail.com>
This commit is contained in:
Debucquoy Anthony 2023-03-29 10:13:34 +02:00
parent 4a14c5d2e6
commit 3ce26796a8
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 5 additions and 4 deletions

View File

@ -140,6 +140,7 @@ public class BinaryParser implements FileParser {
* @return byte array with each element compiled for file format * @return byte array with each element compiled for file format
*/ */
static byte[] BuildByteFromMatrix(boolean[][] shape){ static byte[] BuildByteFromMatrix(boolean[][] shape){
// TODO: 3/27/23 Problem with this function to investigate
int width = shape[0].length , height = shape.length; int width = shape[0].length , height = shape.length;
boolean[] list = new boolean[width * height]; boolean[] list = new boolean[width * height];
for (int x = 0; x < shape.length; x++) { 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 for (int i = 0; i < 8; i++) { // because 8 bit in a byte
b_array[index] = Bitwise.IsBitSetAt(b, i); b_array[index] = Bitwise.IsBitSetAt(b, i);
index++; index++;
if(index <= matrix_height * matrix_width) if(index >= matrix_height * matrix_width)
break; break;
} }
} }
@ -215,4 +216,4 @@ public class BinaryParser implements FileParser {
} }
return ret; return ret;
} }
} }

View File

@ -78,7 +78,7 @@ class BinaryParserTest {
{true, true, false, false, true, true}, {true, true, false, false, true, true},
{true, true, true, true, 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 @Test
@ -107,7 +107,7 @@ class BinaryParserTest {
byte[] piece3_data = Arrays.copyOfRange(file_data, 16, 17); byte[] piece3_data = Arrays.copyOfRange(file_data, 16, 17);
boolean[][] piece3_shape = { boolean[][] piece3_shape = {
{false, true, true}, {false, true, true},
{true, true, false}, {true, true, true},
}; };
assertArrayEquals(piece3_shape, BinaryParser.BuildMatrixFromBytes(3, 2, piece3_data)); assertArrayEquals(piece3_shape, BinaryParser.BuildMatrixFromBytes(3, 2, piece3_data));
} }