Skip to content

Commit 182785f

Browse files
author
Arun Prasaad
committed
Verify new level initialisation with all tiles set to OUTSIDE
1 parent fe9907a commit 182785f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/logic/TileType.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ public enum TileType {
2323
public char getCode() {
2424
return code;
2525
}
26+
27+
/**
28+
* Returns the character code used to represent this tile type in level files as a String.
29+
* @return the character code for this tile type as a single-character String
30+
*/
31+
public String codeAsString() {
32+
return String.valueOf(code);
33+
}
34+
2635
}

src/test/java/ihm/EditorTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,36 @@ ExitHandler defaultExitHandler() {
312312
/**
313313
* Represents expected positions in the test grid.
314314
*/
315+
@Test
316+
void a_new_level_is_created_with_all_tiles_set_to_outside() throws Exception {
317+
// Given
318+
int testRows = 7;
319+
int testCols = 10;
320+
String testLevelName = "emptyGridTest";
321+
Path testLevelPath = Path.of("levels", testLevelName + ".txt");
322+
323+
try {
324+
// When
325+
Editor emptyEditor = new Editor(testRows, testCols, testLevelName);
326+
327+
// Then - Verify the file was created with correct dimensions and content
328+
then(testLevelPath).exists();
329+
List<String> lines = Files.readAllLines(testLevelPath);
330+
331+
then(lines).hasSize(testRows);
332+
then(lines).allSatisfy(line -> {
333+
then(line.length()).isEqualTo(testCols);
334+
then(line).isEqualTo(TileType.OUTSIDE.codeAsString().repeat(testCols));
335+
});
336+
337+
// Clean up
338+
emptyEditor.dispose();
339+
} finally {
340+
// Ensure cleanup even if test fails
341+
Files.deleteIfExists(testLevelPath);
342+
}
343+
}
344+
315345
private record ExpectedAt(int x, int y) {
316346
}
317347
}

0 commit comments

Comments
 (0)