From 3ce26796a8ee12799247133b93af4ddbffcbde57 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Wed, 29 Mar 2023 10:13:34 +0200 Subject: [PATCH] Fixing BuildMatrixFromByte Finish Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/Parsers/BinaryParser.java | 5 +++-- .../test/java/school_project/Parsers/BinaryParserTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 9e2f64e..019daf7 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -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; } } @@ -215,4 +216,4 @@ public class BinaryParser implements FileParser { } return ret; } -} \ No newline at end of file +} diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index a8db7a9..defc63a 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -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)); }