Testing + Wip
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Signed-off-by: Anthony Debucquoy <debucquoy.anthony@gmail.com>
This commit is contained in:
Debucquoy Anthony 2023-03-21 23:58:59 +01:00
parent 26b1fb6308
commit 1771fd1d42
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
4 changed files with 39 additions and 2 deletions

View File

@ -42,6 +42,8 @@ public class Map extends Shape{
} }
for (Piece p : pieces) { for (Piece p : pieces) {
if(p.getPosition() == null)
continue;
for(int x = 0; x < p.height; x++){ for(int x = 0; x < p.height; x++){
for(int y = 0; y < p.width; y++){ for(int y = 0; y < p.width; y++){
if (p.getShape()[x][y]){ if (p.getShape()[x][y]){

View File

@ -22,7 +22,6 @@ public class JsonParser implements FileParser{
* @return true if it is a text File * @return true if it is a text File
*/ */
public static boolean isJsonFile(File file) throws IOException { public static boolean isJsonFile(File file) throws IOException {
System.out.println(Files.probeContentType(file.toPath()));
return Files.probeContentType(file.toPath()).equals("application/json"); return Files.probeContentType(file.toPath()).equals("application/json");
} }

View File

@ -1,11 +1,13 @@
package school_project; package school_project;
import java.io.Serializable;
/** /**
* Base class for everything that is a shape kind, like map and pieces * Base class for everything that is a shape kind, like map and pieces
* it contain a matrix of boolean where the shape is defined by the true's * it contain a matrix of boolean where the shape is defined by the true's
*/ */
public class Shape { public class Shape implements Serializable {
protected boolean[][] matrix; protected boolean[][] matrix;
protected int height, width; protected int height, width;

View File

@ -0,0 +1,34 @@
package school_project.Parsers;
import org.junit.jupiter.api.Test;
import school_project.Map;
import school_project.Piece;
import java.io.File;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
class JsonParserTest {
@Test
void saveLevelData() throws IOException {
boolean[][] map_matrix = {
{true, true, true},
{false, true, false},
{true, true, true},
};
Map map = new Map(map_matrix);
boolean[][] piece1 = {{true, true, true}};
boolean[][] piece2 = {{false, true, false}, {true, true, true}};
map.addPiece(new Piece(piece1));
map.addPiece(new Piece(piece2));
JsonParser parser = new JsonParser();
parser.saveLevelData(new File("test.json"), map);
FileParser p2 = FileParserFactory.createParser(new File("test.json"));
Map map2 = p2.getLevel(new File("test.json"));
assertArrayEquals(map2.getShape(), map.getShape());
assertArrayEquals(map2.getUsedSpace(), map.getUsedSpace());
}
}