File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments