|
16 | 16 | import java.nio.file.Path; |
17 | 17 | import java.util.Arrays; |
18 | 18 | import java.util.List; |
| 19 | +import java.util.stream.IntStream; |
19 | 20 |
|
20 | 21 | import static java.nio.file.Files.deleteIfExists; |
21 | 22 | import static org.assertj.core.api.BDDAssertions.then; |
@@ -313,31 +314,35 @@ ExitHandler defaultExitHandler() { |
313 | 314 | * Represents expected positions in the test grid. |
314 | 315 | */ |
315 | 316 | @Test |
316 | | - void a_new_level_is_created_with_all_tiles_set_to_outside() throws Exception { |
| 317 | + void a_new_level_is_created_with_walls_and_floor_spaces() throws Exception { |
317 | 318 | // Given |
318 | 319 | int testRows = 7; |
319 | | - int testCols = 10; |
| 320 | + int testCols = 7; |
320 | 321 | String testLevelName = "emptyGridTest"; |
321 | 322 | Path testLevelPath = Path.of("levels", testLevelName + ".txt"); |
322 | 323 |
|
323 | 324 | try { |
324 | 325 | // When |
325 | | - Editor emptyEditor = new Editor(testRows, testCols, testLevelName); |
| 326 | + Editor newEditor = new Editor(testRows, testCols, testLevelName); |
326 | 327 |
|
327 | | - // Then - Verify the file was created with correct dimensions and content |
328 | 328 | then(testLevelPath).exists(); |
329 | 329 | List<String> lines = Files.readAllLines(testLevelPath); |
330 | 330 |
|
331 | 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 |
| 332 | + |
| 333 | + // First and last row should be all walls |
| 334 | + String wallRow = TileType.WALL.codeAsString().repeat(testCols); |
| 335 | + then(lines.getFirst()).isEqualTo(wallRow); |
| 336 | + then(lines.getLast()).isEqualTo(wallRow); |
| 337 | + |
| 338 | + // Middle rows should have walls on the sides |
| 339 | + String middleRow = "%s%s%s".formatted( |
| 340 | + TileType.WALL.codeAsString(), |
| 341 | + TileType.FLOOR.codeAsString().repeat(testCols - 2), |
| 342 | + TileType.WALL.codeAsString()); |
| 343 | + then(lines.subList(1, testRows - 1)).allSatisfy(line -> then(line).isEqualTo(middleRow)); |
| 344 | + } |
| 345 | + finally { |
341 | 346 | Files.deleteIfExists(testLevelPath); |
342 | 347 | } |
343 | 348 | } |
|
0 commit comments