From c88783b60e93fd28b5ce892f26688e7c462ba3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sun, 17 Sep 2023 17:48:03 +0300 Subject: [PATCH 01/29] Add MazeGenerator exercise and related tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces a new MazeGenerator class along with related Units Tests. It also adds the `Dimensions` record to represent the size of the maze. Both MazeGenerator and Dimensions classes are incorporated into the build.gradle file. For testing purposes, MazeGeneratorTest along with its configuration file and a test reference were incorporated. This change allows generating perfect mazes of a specified size with a single correct path, ideal for maze navigation tasks. Can produce random mazes or reproducible ones when provided with a seed. The mazes are represented using box-drawing characters and the entrances/exits are denoted by an arrow symbol(⇨). --- exercises/practice/mazy-mice/.docs/hints.md | 23 +++ .../practice/mazy-mice/.docs/instructions.md | 48 +++++ .../practice/mazy-mice/.docs/introduction.md | 3 + .../practice/mazy-mice/.meta/config.json | 19 ++ .../.meta/src/reference/java/Dimensions.java | 25 +++ .../src/reference/java/MazeGenerator.java | 177 ++++++++++++++++ exercises/practice/mazy-mice/.meta/version | 1 + exercises/practice/mazy-mice/build.gradle | 24 +++ .../mazy-mice/src/main/java/Dimensions.java | 25 +++ .../src/main/java/MazeGenerator.java | 10 + .../src/test/java/MazeGeneratorTest.java | 193 ++++++++++++++++++ 11 files changed, 548 insertions(+) create mode 100644 exercises/practice/mazy-mice/.docs/hints.md create mode 100644 exercises/practice/mazy-mice/.docs/instructions.md create mode 100644 exercises/practice/mazy-mice/.docs/introduction.md create mode 100644 exercises/practice/mazy-mice/.meta/config.json create mode 100644 exercises/practice/mazy-mice/.meta/src/reference/java/Dimensions.java create mode 100644 exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java create mode 100644 exercises/practice/mazy-mice/.meta/version create mode 100644 exercises/practice/mazy-mice/build.gradle create mode 100644 exercises/practice/mazy-mice/src/main/java/Dimensions.java create mode 100644 exercises/practice/mazy-mice/src/main/java/MazeGenerator.java create mode 100644 exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java diff --git a/exercises/practice/mazy-mice/.docs/hints.md b/exercises/practice/mazy-mice/.docs/hints.md new file mode 100644 index 000000000..7732e065d --- /dev/null +++ b/exercises/practice/mazy-mice/.docs/hints.md @@ -0,0 +1,23 @@ +# placeholder + +## Maze generation + +You can use any algorithm to generate a perfect maze. The [recursive backtracker][recursive-backtracker] is a good choice. + +## Box drawing characters + +| Character | Name | Unicode | +|:---------:|:--------------------------------------|:--------| +| ┌ | box drawings light down and right | U+250C | +| ─ | box drawings light horizontal | U+2500 | +| ┬ | box drawings light down and horizontal| U+252C | +| ┐ | box drawings light down and left | U+2510 | +| │ | box drawings light vertical | U+2502 | +| └ | box drawings light up and right | U+2514 | +| ┴ | box drawings light up and horizontal | U+2534 | +| ┘ | box drawings light up and left | U+2518 | +| ├ | box drawings light vertical and right | U+2520 | +| ⇨ | rightwards white arrow | U+21E8 | + + +[recursive-backtracker]: https://en.wikipedia.org/wiki/Maze_generation_algorithm diff --git a/exercises/practice/mazy-mice/.docs/instructions.md b/exercises/practice/mazy-mice/.docs/instructions.md new file mode 100644 index 000000000..b0227ad93 --- /dev/null +++ b/exercises/practice/mazy-mice/.docs/instructions.md @@ -0,0 +1,48 @@ +## Instructions + +Your task is to generate the perfect mazes for Mickey and Minerva — those with only one solution and no isolated sections. +Here's what you need to know: + +- The maze has a rectangular shape with an opening at the start and end. +- The maze has rooms and passages, which intersect at right angles. +- The program should accept two parameters: rows and columns. The maze should be between 5 and 100 cells in size. +- A maze which is `x` columns wide and `y` rows high should be `2x + 1` characters wide and `2y + 1` characters high. +- If no seed is provided, generate a random maze. If the same seed is provided multiple times, the resulting maze should be the same each time. +- Use [box-drawing][Box-drawing] characters to draw walls, and an arrow symbol (⇨) for the entrance on the left and exit on the right. + +It's time to create some perfect mazes for these adventurous mice! + +### Examples + +1. The small square maze 5x5 cells (or 11x11 characters) +```text + ┌───────┬─┐ + │ │ │ + │ ┌─┬── │ │ + │ │ │ │ ⇨ + │ │ │ ──┤ │ + ⇨ │ │ │ │ + ┌─┤ └── │ │ + │ │ │ │ + │ │ ────┘ │ + │ │ + └─────────┘ +``` +2. The rectangular maze 6x18 cells +```text + ┌───────────┬─────────┬───────────┬─┐ + │ │ │ │ │ + │ ┌───────┐ │ ┌─┐ ──┐ └───┐ ┌───┐ │ │ + │ │ │ │ │ │ │ │ │ │ ⇨ + │ └─┐ ┌─┐ │ │ │ ├── ├───┐ │ │ ──┼── │ + │ │ │ │ │ │ │ │ │ │ │ │ + └── │ │ ├───┴───┤ ┌─┘ ┌─┘ │ ├── │ ──┤ + ⇨ │ │ │ │ │ │ │ │ │ + ┌─┬─┴─┐ └─┐ ┌─┐ │ └─┐ │ ┌─┘ │ ──┴─┐ │ + │ │ │ │ │ │ │ │ │ │ │ │ + │ │ │ └── │ │ │ └── │ ──┘ ┌─┘ ──┐ │ │ + │ │ │ │ │ │ │ + └───┴───────┴───────┴─────┴─────┴───┘ +``` + +[Box-drawing]: https://en.wikipedia.org/wiki/Box-drawing_character diff --git a/exercises/practice/mazy-mice/.docs/introduction.md b/exercises/practice/mazy-mice/.docs/introduction.md new file mode 100644 index 000000000..96eee810c --- /dev/null +++ b/exercises/practice/mazy-mice/.docs/introduction.md @@ -0,0 +1,3 @@ +# Introduction + +Meet Mickey and Minerva, two clever mice who love to navigate their way through a maze to find cheese. They enjoy a good challenge, but with only their tiny mouse brains, they prefer if there is only one correct path to the cheese. diff --git a/exercises/practice/mazy-mice/.meta/config.json b/exercises/practice/mazy-mice/.meta/config.json new file mode 100644 index 000000000..285df5739 --- /dev/null +++ b/exercises/practice/mazy-mice/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "rabestro" + ], + "files": { + "solution": [ + "src/main/java/MazeGenerator.java" + ], + "test": [ + "src/test/java/MazeGeneratorTest.java" + ], + "example": [ + ".meta/src/reference/java/MazeGenerator.java" + ] + }, + "blurb": "Meet Mickey and Minerva, two clever mice who love to navigate their way through a maze to find cheese. They enjoy a good challenge, but with only their tiny mouse brains, they prefer if there is only one correct path to the cheese.", + "source": "Inspired by the 'Maze Generator' created by Jan Boström at Alance AB.", + "source_url": "https://mazegenerator.net/" +} diff --git a/exercises/practice/mazy-mice/.meta/src/reference/java/Dimensions.java b/exercises/practice/mazy-mice/.meta/src/reference/java/Dimensions.java new file mode 100644 index 000000000..f7e178c10 --- /dev/null +++ b/exercises/practice/mazy-mice/.meta/src/reference/java/Dimensions.java @@ -0,0 +1,25 @@ +/** + * Represents the dimensions of a maze. + *

+ * Dimensions of a grid can be represented in cells or characters. + * Rows and columns are used for cells, while width and height are used for characters. + */ +public record Dimensions(int rows, int columns) { + /** + * Returns the width of the maze in characters. + * + * @return the width of the maze + */ + int width() { + return 2 * columns + 1; + } + + /** + * Returns the height of the maze in characters. + * + * @return the height of the maze + */ + int height() { + return 2 * rows + 1; + } +} diff --git a/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java new file mode 100644 index 000000000..dc7cbb2f0 --- /dev/null +++ b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java @@ -0,0 +1,177 @@ +import java.util.Random; +import java.util.random.RandomGenerator; +import java.util.BitSet; +import java.util.EnumSet; +import java.util.Set; + +import static java.util.stream.IntStream.range; + +public class MazeGenerator { + + public char[][] generatePerfectMaze(Dimensions dimensions) { + return new Grid(dimensions, RandomGenerator.getDefault()) + .generateMaze() + .placeDoors() + .print(); + } + + public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { + return new Grid(dimensions, new Random(seed)) + .generateMaze() + .placeDoors() + .print(); + } +} + +enum Direction { + NORTH(0, 1), + EAST(1, 0), + SOUTH(0, -1), + WEST(-1, 0); + private final int dx; + private final int dy; + + Direction(int dx, int dy) { + this.dx = dx; + this.dy = dy; + } + + public int dx() { + return dx; + } + + public int dy() { + return dy; + } +} + +final class Grid { + private final Dimensions dimensions; + private final BitSet grid; + private final RandomGenerator randomGenerator; + + Grid(Dimensions dimensions, RandomGenerator randomGenerator) { + this.dimensions = dimensions; + this.grid = new BitSet(dimensions.width() * dimensions.height()); + this.randomGenerator = randomGenerator; + } + + Grid generateMaze() { + generate(new Cell(1, 1)); + return this; + } + + private int random(int bound) { + return randomGenerator.nextInt(bound); + } + + private Direction pickRandomDirection(Set directions) { + int size = directions.size(); + int itemIndex = random(size); + var direction = directions.toArray(new Direction[size])[itemIndex]; + directions.remove(direction); + return direction; + } + + Grid placeDoors() { + new Cell(1 + 2 * random(dimensions.rows()), 0).erase(); + new Cell(1 + 2 * random(dimensions.rows()), dimensions.width() - 1).erase(); + return this; + } + + private void generate(Cell cell) { + cell.erase(); + + var directions = EnumSet.allOf(Direction.class); + do { + var direction = pickRandomDirection(directions); + var wall = cell.move(direction); + var next = wall.move(direction); + if (next.isValid() && next.isNotEmpty()) { + wall.erase(); + generate(next); + } + } while (!directions.isEmpty()); + } + + char[][] print() { + return range(0, dimensions.height()) + .mapToObj(this::line) + .toArray(char[][]::new); + } + + private char[] line(int x) { + return range(0, dimensions.width()) + .map(y -> new Cell(x, y).symbol()) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString() + .toCharArray(); + } + + private final class Cell { + final int x; + final int y; + + private Cell(int x, int y) { + this.x = x; + this.y = y; + } + + boolean isValid() { + return x > 0 && x < dimensions.height() && y > 0 && y < dimensions.width(); + } + + void erase() { + grid.set(index()); + } + + boolean isNotEmpty() { + return !isEmpty(); + } + + boolean isEmpty() { + return grid.get(index()); + } + + int index() { + return x * dimensions.width() + y; + } + + boolean isDoor() { + return isEmpty() && (y == 0 || y == dimensions.width() - 1); + } + + Cell move(Direction direction) { + return new Cell(x + direction.dx(), y + direction.dy()); + } + + char symbol() { + if (isDoor()) { + return '⇨'; + } + if (isEmpty()) { + return ' '; + } + var n = x > 0 && new Cell(x - 1, y).isNotEmpty() ? 1 : 0; + var e = y < dimensions.width() - 1 && new Cell(x, y + 1).isNotEmpty() ? 1 : 0; + var s = x < dimensions.height() - 1 && new Cell(x + 1, y).isNotEmpty() ? 1 : 0; + var w = y > 0 && new Cell(x, y - 1).isNotEmpty() ? 1 : 0; + var i = n + 2 * e + 4 * s + 8 * w; + return switch (i) { + case 0 -> ' '; + case 1, 5, 4 -> '│'; + case 2, 8, 10 -> '─'; + case 3 -> '└'; + case 6 -> '┌'; + case 7 -> '├'; + case 9 -> '┘'; + case 11 -> '┴'; + case 12 -> '┐'; + case 13 -> '┤'; + case 14 -> '┬'; + case 15 -> '┼'; + default -> throw new IllegalStateException("Unexpected value: " + i); + }; + } + } +} diff --git a/exercises/practice/mazy-mice/.meta/version b/exercises/practice/mazy-mice/.meta/version new file mode 100644 index 000000000..3eefcb9dd --- /dev/null +++ b/exercises/practice/mazy-mice/.meta/version @@ -0,0 +1 @@ +1.0.0 diff --git a/exercises/practice/mazy-mice/build.gradle b/exercises/practice/mazy-mice/build.gradle new file mode 100644 index 000000000..8bd005d42 --- /dev/null +++ b/exercises/practice/mazy-mice/build.gradle @@ -0,0 +1,24 @@ +apply plugin: "java" +apply plugin: "eclipse" +apply plugin: "idea" + +// set default encoding to UTF-8 +compileJava.options.encoding = "UTF-8" +compileTestJava.options.encoding = "UTF-8" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation "junit:junit:4.13" + testImplementation "org.assertj:assertj-core:3.15.0" +} + +test { + testLogging { + exceptionFormat = 'full' + showStandardStreams = true + events = ["passed", "failed", "skipped"] + } +} diff --git a/exercises/practice/mazy-mice/src/main/java/Dimensions.java b/exercises/practice/mazy-mice/src/main/java/Dimensions.java new file mode 100644 index 000000000..f7e178c10 --- /dev/null +++ b/exercises/practice/mazy-mice/src/main/java/Dimensions.java @@ -0,0 +1,25 @@ +/** + * Represents the dimensions of a maze. + *

+ * Dimensions of a grid can be represented in cells or characters. + * Rows and columns are used for cells, while width and height are used for characters. + */ +public record Dimensions(int rows, int columns) { + /** + * Returns the width of the maze in characters. + * + * @return the width of the maze + */ + int width() { + return 2 * columns + 1; + } + + /** + * Returns the height of the maze in characters. + * + * @return the height of the maze + */ + int height() { + return 2 * rows + 1; + } +} diff --git a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java new file mode 100644 index 000000000..609b84715 --- /dev/null +++ b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java @@ -0,0 +1,10 @@ +public class MazeGenerator { + + public char[][] generatePerfectMaze(Dimensions dimensions) { + return null; + } + + public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { + return null; + } +} diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java new file mode 100644 index 000000000..9238640ce --- /dev/null +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -0,0 +1,193 @@ +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; + +import java.util.Arrays; +import java.util.Set; + +import static org.assertj.core.api.Assertions.assertThat; + +class MazeGeneratorTest { + private static final char EMPTY_CELL = ' '; + private static final Set ALLOWED_SYMBOLS = Set.of( + EMPTY_CELL, // space + '┌', // box drawings light down and right + '─', // box drawings light horizontal + '┬', // box drawings light down and horizontal + '┐', // box drawings light down and left + '│', // box drawings light vertical + '└', // box drawings light up and right + '┴', // box drawings light up and horizontal + '┘', // box drawings light up and left + '├', // box drawings light vertical and right + '┤', // box drawings light vertical and left + '┼', // box drawings light vertical and horizontal + '⇨' // rightwards white arrow + ); + private static final char VISITED_CELL = '.'; + private static final Dimensions RECTANGLE = new Dimensions(6, 18); + private MazeGenerator sut; + + @Before + void SetUp() { + sut = new MazeGenerator(); + } + + @Test + void mazeIsNotNull() { + var maze = sut.generatePerfectMaze(RECTANGLE); + + assertThat(maze) + .as("The maze is not null.") + .isNotNull(); + + Arrays.stream(maze) + .map(String::new) + .forEach(System.out::println); + } + + @Ignore("Remove to run test") + @Test + void the_dimensions_are_correct() { + var maze = sut.generatePerfectMaze(RECTANGLE); + + assertThat(maze) + .as("The dimensions of the maze are correct.") + .hasDimensions(RECTANGLE.height(), RECTANGLE.width()); + } + + @Ignore("Remove to run test") + @Test + void twoMazesShouldNotBeEqual() { + var maze1 = sut.generatePerfectMaze(RECTANGLE); + var maze2 = sut.generatePerfectMaze(RECTANGLE); + + assertThat(maze1) + .as("Two mazes should not be equal") + .isNotEqualTo(maze2); + } + + @Ignore("Remove to run test") + @Test + void twoMazesWithSameSeedShouldBeEqual() { + var maze1 = sut.generatePerfectMaze(RECTANGLE, 42); + var maze2 = sut.generatePerfectMaze(RECTANGLE, 42); + + assertThat(maze1) + .as("Two mazes with the same seed should be equal") + .isEqualTo(maze2); + } + + @Ignore("Remove to run test") + @Test + void twoMazesWithDifferentSeedsShouldNotBeEqual() { + var maze1 = sut.generatePerfectMaze(RECTANGLE, 42); + var maze2 = sut.generatePerfectMaze(RECTANGLE, 43); + + assertThat(maze1) + .as("Two mazes with different seeds should not be equal") + .isNotEqualTo(maze2); + } + + @Ignore("Remove to run test") + @Test + void theMazeContainsOnlyValidCharacters() { + var maze = sut.generatePerfectMaze(RECTANGLE); + + for (var row : maze) { + for (var cell : row) { + assertThat(cell) + .as("The maze contains only valid characters") + .isIn(ALLOWED_SYMBOLS); + } + } + } + + @Ignore("Remove to run test") + @Test + void theMazeHasOnlyOneEntranceOnTheLeftSide() { + var maze = sut.generatePerfectMaze(RECTANGLE); + int entranceCount = countEntrances(maze); + + assertThat(entranceCount) + .as("The maze has only one entrance on the left side") + .isOne(); + } + + @Ignore("Remove to run test") + @Test + void theMazeHasASingleExitOnTheRightSideOfTheMaze() { + var maze = sut.generatePerfectMaze(RECTANGLE); + int exitCount = countExits(maze); + + assertThat(exitCount) + .as("The maze has a single exit on the right side of the maze") + .isOne(); + } + + @Ignore("Remove to run test") + @Test + void theMazeIsPerfect() { + var maze = sut.generatePerfectMaze(RECTANGLE); + + assertThat(maze) + .as("The dimensions of the maze are correct.") + .hasDimensions(RECTANGLE.height(), RECTANGLE.width()); + + assertThatMazeHasSinglePath(maze); + assertThatMazeHasNoIsolatedSections(maze); + } + + private void assertThatMazeHasSinglePath(char[][] maze) { + assertMazeHasSinglePath(maze, 1, 1); + } + + private void assertMazeHasSinglePath(char[][] maze, int x, int y) { + var isEmptyCell = maze[x][y] == EMPTY_CELL; + + assertThat(isEmptyCell) + .as("The maze has only one path") + .withFailMessage("an extra passage detected at (%d, %d)", x, y) + .isTrue(); + + maze[x][y] = VISITED_CELL; + + for (var direction : Direction.values()) { + if (maze[x + direction.dx()][y + direction.dy()] == EMPTY_CELL) { + maze[x + direction.dx()][y + direction.dy()] = VISITED_CELL; + assertMazeHasSinglePath(maze, x + 2 * direction.dx(), y + 2 * direction.dy()); + } + } + } + + private void assertThatMazeHasNoIsolatedSections(char[][] maze) { + for (int row = 1; row < maze.length; row += 2) { + for (int col = 1; col < maze[row].length; col += 2) { + assertThat(maze[row][col]) + .as("The maze has no isolated sections") + .withFailMessage("an isolated section detected at (%d, %d)", row, col) + .isEqualTo(VISITED_CELL); + } + } + } + + private int countExits(char[][] maze) { + int exitCount = 0; + for (char[] row : maze) { + if (row[row.length - 1] == '⇨') { + exitCount++; + } + } + return exitCount; + } + + private int countEntrances(char[][] maze) { + int entranceCount = 0; + for (char[] row : maze) { + if (row[0] == '⇨') { + entranceCount++; + } + } + return entranceCount; + } +} From 1e1765a7f443ac7337cc9d3f52e734192a730822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Mon, 18 Sep 2023 11:04:43 +0300 Subject: [PATCH 02/29] Update exercises/practice/mazy-mice/src/main/java/MazeGenerator.java Co-authored-by: Sander Ploegsma --- exercises/practice/mazy-mice/src/main/java/MazeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java index 609b84715..651d0c757 100644 --- a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java +++ b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java @@ -1,7 +1,7 @@ public class MazeGenerator { public char[][] generatePerfectMaze(Dimensions dimensions) { - return null; + throw new UnsupportedOperationException("Delete this statement and write your own implementation."); } public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { From 0b9ef447a8350b2b86f16d7ab0c02bdb7573290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Mon, 18 Sep 2023 11:17:37 +0300 Subject: [PATCH 03/29] Update exercises/practice/mazy-mice/src/main/java/MazeGenerator.java Co-authored-by: Sander Ploegsma --- exercises/practice/mazy-mice/src/main/java/MazeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java index 651d0c757..fc4c57176 100644 --- a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java +++ b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java @@ -5,6 +5,6 @@ public char[][] generatePerfectMaze(Dimensions dimensions) { } public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { - return null; + throw new UnsupportedOperationException("Delete this statement and write your own implementation."); } } From 01bc92eb99d81e0cf211cfb2d6c972eb02327c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 19 Sep 2023 11:02:38 +0300 Subject: [PATCH 04/29] Update mazy-mice exercise metadata configuration The config.json file for the mazy-mice exercise has been improved to include the new 'invalidator' field. This field references the build.gradle file which is used for the construction and testing of the 'MazeGenerator' example. With this addition, users are now able to work with the MazeGenerator class and its related unit tests in their local environment with ease. --- exercises/practice/mazy-mice/.meta/config.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises/practice/mazy-mice/.meta/config.json b/exercises/practice/mazy-mice/.meta/config.json index 285df5739..d717f2cc7 100644 --- a/exercises/practice/mazy-mice/.meta/config.json +++ b/exercises/practice/mazy-mice/.meta/config.json @@ -11,6 +11,9 @@ ], "example": [ ".meta/src/reference/java/MazeGenerator.java" + ], + "invalidator": [ + "build.gradle" ] }, "blurb": "Meet Mickey and Minerva, two clever mice who love to navigate their way through a maze to find cheese. They enjoy a good challenge, but with only their tiny mouse brains, they prefer if there is only one correct path to the cheese.", From 7d7348ea4204ca5ca116ef5d38539ec81c4259a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 19 Sep 2023 11:04:42 +0300 Subject: [PATCH 05/29] Improve grammar in mazy-mice exercise instructions Minor grammatical correction has been made in the mazy-mice exercise documentation. Prior sentences were changed from "The small square maze" and "The rectangular maze" to "A small square maze" and "A rectangular maze" respectively, to improve sentence flow and clarity for users. --- exercises/practice/mazy-mice/.docs/instructions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/mazy-mice/.docs/instructions.md b/exercises/practice/mazy-mice/.docs/instructions.md index b0227ad93..e745cda8c 100644 --- a/exercises/practice/mazy-mice/.docs/instructions.md +++ b/exercises/practice/mazy-mice/.docs/instructions.md @@ -14,7 +14,7 @@ It's time to create some perfect mazes for these adventurous mice! ### Examples -1. The small square maze 5x5 cells (or 11x11 characters) +1. A small square maze 5x5 cells (or 11x11 characters) ```text ┌───────┬─┐ │ │ │ @@ -28,7 +28,7 @@ It's time to create some perfect mazes for these adventurous mice! │ │ └─────────┘ ``` -2. The rectangular maze 6x18 cells +2. A rectangular maze 6x18 cells ```text ┌───────────┬─────────┬───────────┬─┐ │ │ │ │ │ From ccbbcd728daccff22fd51491952e9faf7d56a4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 19 Sep 2023 11:06:59 +0300 Subject: [PATCH 06/29] Update placeholder in hints.md The placeholder comment in the 'hints.md' file for the mazy-mice exercise has been replaced with the 'Hints' header. This change is essential for creating a more meaningful start to the document and improving the clarity for users trying to understand maze generation. --- exercises/practice/mazy-mice/.docs/hints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/.docs/hints.md b/exercises/practice/mazy-mice/.docs/hints.md index 7732e065d..9d859df4d 100644 --- a/exercises/practice/mazy-mice/.docs/hints.md +++ b/exercises/practice/mazy-mice/.docs/hints.md @@ -1,4 +1,4 @@ -# placeholder +# Hints ## Maze generation From 11fe1d05f9e3717ec2f74b12da86852a361de9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 30 Sep 2023 20:48:16 +0300 Subject: [PATCH 07/29] Refactor test method name for clarity The test method name 'the_dimensions_are_correct' in MazeGeneratorTest has been refactored to 'theDimensionsAreCorrect'. This is in line with Java's camelCase naming convention, improving readability and maintaining a consistent code style. --- .../practice/mazy-mice/src/test/java/MazeGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 9238640ce..21ee51765 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -48,7 +48,7 @@ void mazeIsNotNull() { @Ignore("Remove to run test") @Test - void the_dimensions_are_correct() { + void theDimensionsAreCorrect() { var maze = sut.generatePerfectMaze(RECTANGLE); assertThat(maze) From 2ef9ca6d71903cf29975f522f64271e43d0c8a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 30 Sep 2023 20:52:13 +0300 Subject: [PATCH 08/29] Update test method name to reflect logical assertion Updated the name of the test method in MazeGeneratorTest from 'twoMazesShouldNotBeEqual' to 'aMazeIsDifferentEachTimeItIsGenerated'. The new name better indicates the purpose of the test, which is to check that every maze generated is unique. --- .../practice/mazy-mice/src/test/java/MazeGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 21ee51765..2e1424989 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -58,7 +58,7 @@ void theDimensionsAreCorrect() { @Ignore("Remove to run test") @Test - void twoMazesShouldNotBeEqual() { + void aMazeIsDifferentEachTimeItIsGenerated() { var maze1 = sut.generatePerfectMaze(RECTANGLE); var maze2 = sut.generatePerfectMaze(RECTANGLE); From 4071a73adbf5e008d85dcb59ba83a847625bb235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 30 Sep 2023 20:55:47 +0300 Subject: [PATCH 09/29] Add 'mazy-mice' to settings.gradle Included 'practice:mazy-mice' in the settings.gradle to extend the diversity of exercises. This step is necessary for building and running the 'mazy-mice' exercise. --- exercises/settings.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/settings.gradle b/exercises/settings.gradle index 37a4f5b88..f4677c33d 100644 --- a/exercises/settings.gradle +++ b/exercises/settings.gradle @@ -78,6 +78,7 @@ include 'practice:luhn' include 'practice:markdown' include 'practice:matching-brackets' include 'practice:matrix' +include 'practice:mazy-mice' include 'practice:meetup' include 'practice:micro-blog' include 'practice:minesweeper' From f33e267ffc381ab93c759ee4ae51fef09c44aa9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 7 Oct 2023 17:43:45 +0300 Subject: [PATCH 10/29] Add new "mazy-mice" exercise to config.json A new exercise named "mazy-mice" has been added to config.json. This exercise, which involves character arrays and string handling with for-loops, is intended to diversify the exercise list and give users more exercise choices. The difficulty of this exercise has been set to 8. --- config.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config.json b/config.json index 23829da5b..9697221b2 100644 --- a/config.json +++ b/config.json @@ -1955,6 +1955,20 @@ "practices": ["numbers"], "prerequisites": ["numbers"], "difficulty": 5 + }, + { + "slug": "mazy-mice", + "name": "Mazy Mice", + "uuid": "1bac7473-9ee8-4cfc-928b-77792102ffc1", + "practices": [ + "chars", + "arrays" + ], + "prerequisites": [ + "strings", + "for-loops" + ], + "difficulty": 8 } ], "foregone": [] From 88106d683369c55b200202586dd0631bc1f28d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 28 Oct 2023 12:18:09 +0300 Subject: [PATCH 11/29] Refactor maze generation and test methods for readability The methods for maze generation have been refactored to directly accept individual parameters for 'rows' and 'columns' instead of a 'Dimensions' object. This change simplifies the method calls and enhances code readability. Also, updated the corresponding test cases to adhere to the new method signature. Additionally, added enumeration for directions at the end of the test class to improve code organization and readability. --- .../src/reference/java/MazeGenerator.java | 8 +-- .../src/main/java/MazeGenerator.java | 4 +- .../src/test/java/MazeGeneratorTest.java | 63 +++++++++++++------ 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java index dc7cbb2f0..f562b627f 100644 --- a/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java +++ b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java @@ -8,15 +8,15 @@ public class MazeGenerator { - public char[][] generatePerfectMaze(Dimensions dimensions) { - return new Grid(dimensions, RandomGenerator.getDefault()) + public char[][] generatePerfectMaze(int rows, int columns) { + return new Grid(new Dimensions(rows, columns), RandomGenerator.getDefault()) .generateMaze() .placeDoors() .print(); } - public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { - return new Grid(dimensions, new Random(seed)) + public char[][] generatePerfectMaze(int rows, int columns, int seed) { + return new Grid(new Dimensions(rows, columns), new Random(seed)) .generateMaze() .placeDoors() .print(); diff --git a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java index fc4c57176..48c0bdafc 100644 --- a/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java +++ b/exercises/practice/mazy-mice/src/main/java/MazeGenerator.java @@ -1,10 +1,10 @@ public class MazeGenerator { - public char[][] generatePerfectMaze(Dimensions dimensions) { + public char[][] generatePerfectMaze(int rows, int columns) { throw new UnsupportedOperationException("Delete this statement and write your own implementation."); } - public char[][] generatePerfectMaze(Dimensions dimensions, int seed) { + public char[][] generatePerfectMaze(int rows, int columns, int seed) { throw new UnsupportedOperationException("Delete this statement and write your own implementation."); } } diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 2e1424989..40a8cfe71 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -25,7 +25,10 @@ class MazeGeneratorTest { '⇨' // rightwards white arrow ); private static final char VISITED_CELL = '.'; - private static final Dimensions RECTANGLE = new Dimensions(6, 18); + private static final int RECTANGLE_ROWS = 6; + private static final int RECTANGLE_COLUMNS = 18; + private static final int SEED_ONE = 42; + private static final int SEED_TWO = 43; private MazeGenerator sut; @Before @@ -35,7 +38,7 @@ void SetUp() { @Test void mazeIsNotNull() { - var maze = sut.generatePerfectMaze(RECTANGLE); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); assertThat(maze) .as("The maze is not null.") @@ -49,18 +52,24 @@ void mazeIsNotNull() { @Ignore("Remove to run test") @Test void theDimensionsAreCorrect() { - var maze = sut.generatePerfectMaze(RECTANGLE); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); + var expectedWidth = RECTANGLE_COLUMNS * 2 + 1; + var expectedHeight = RECTANGLE_ROWS * 2 + 1; assertThat(maze) .as("The dimensions of the maze are correct.") - .hasDimensions(RECTANGLE.height(), RECTANGLE.width()); + .hasSize(expectedHeight); + + assertThat(maze[0]) + .as("The dimensions of the maze are correct.") + .hasSize(expectedWidth); } @Ignore("Remove to run test") @Test void aMazeIsDifferentEachTimeItIsGenerated() { - var maze1 = sut.generatePerfectMaze(RECTANGLE); - var maze2 = sut.generatePerfectMaze(RECTANGLE); + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); assertThat(maze1) .as("Two mazes should not be equal") @@ -70,8 +79,8 @@ void aMazeIsDifferentEachTimeItIsGenerated() { @Ignore("Remove to run test") @Test void twoMazesWithSameSeedShouldBeEqual() { - var maze1 = sut.generatePerfectMaze(RECTANGLE, 42); - var maze2 = sut.generatePerfectMaze(RECTANGLE, 42); + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); assertThat(maze1) .as("Two mazes with the same seed should be equal") @@ -81,8 +90,8 @@ void twoMazesWithSameSeedShouldBeEqual() { @Ignore("Remove to run test") @Test void twoMazesWithDifferentSeedsShouldNotBeEqual() { - var maze1 = sut.generatePerfectMaze(RECTANGLE, 42); - var maze2 = sut.generatePerfectMaze(RECTANGLE, 43); + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_TWO); assertThat(maze1) .as("Two mazes with different seeds should not be equal") @@ -92,7 +101,7 @@ void twoMazesWithDifferentSeedsShouldNotBeEqual() { @Ignore("Remove to run test") @Test void theMazeContainsOnlyValidCharacters() { - var maze = sut.generatePerfectMaze(RECTANGLE); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); for (var row : maze) { for (var cell : row) { @@ -106,7 +115,7 @@ void theMazeContainsOnlyValidCharacters() { @Ignore("Remove to run test") @Test void theMazeHasOnlyOneEntranceOnTheLeftSide() { - var maze = sut.generatePerfectMaze(RECTANGLE); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); int entranceCount = countEntrances(maze); assertThat(entranceCount) @@ -117,7 +126,7 @@ void theMazeHasOnlyOneEntranceOnTheLeftSide() { @Ignore("Remove to run test") @Test void theMazeHasASingleExitOnTheRightSideOfTheMaze() { - var maze = sut.generatePerfectMaze(RECTANGLE); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); int exitCount = countExits(maze); assertThat(exitCount) @@ -128,11 +137,7 @@ void theMazeHasASingleExitOnTheRightSideOfTheMaze() { @Ignore("Remove to run test") @Test void theMazeIsPerfect() { - var maze = sut.generatePerfectMaze(RECTANGLE); - - assertThat(maze) - .as("The dimensions of the maze are correct.") - .hasDimensions(RECTANGLE.height(), RECTANGLE.width()); + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); assertThatMazeHasSinglePath(maze); assertThatMazeHasNoIsolatedSections(maze); @@ -191,3 +196,25 @@ private int countEntrances(char[][] maze) { return entranceCount; } } + +enum Direction { + NORTH(0, 1), + EAST(1, 0), + SOUTH(0, -1), + WEST(-1, 0); + private final int dx; + private final int dy; + + Direction(int dx, int dy) { + this.dx = dx; + this.dy = dy; + } + + public int dx() { + return dx; + } + + public int dy() { + return dy; + } +} From 1bd5acf3841e3769ee9c85241786192a08c87a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 28 Oct 2023 17:51:13 +0300 Subject: [PATCH 12/29] Add descriptions to auto-generated test cases An auto-generated 'tests.toml' file is introduced. The descriptions added provide information for each test key about the attributes and functionality that is being tested. These include correct dimensions, valid characters, proper locations of entrances and exits, and generation of mazes with or without a seed parameter. These descriptions help developers understand the purpose of the tests and correct functioning of the maze. Also, change method names and orders to make the test easier to follow. This allows the clearer reading of the tests, thus increasing productivity. It helps maintainers to spot and understand the new changes faster and easier. Minor changes, such as capitalisation corrections, are also made for improved readability. --- exercises/practice/mazy-mice/.meta/tests.toml | 21 ++++++ .../src/test/java/MazeGeneratorTest.java | 71 ++++++++++--------- 2 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 exercises/practice/mazy-mice/.meta/tests.toml diff --git a/exercises/practice/mazy-mice/.meta/tests.toml b/exercises/practice/mazy-mice/.meta/tests.toml new file mode 100644 index 000000000..6b84b1f3c --- /dev/null +++ b/exercises/practice/mazy-mice/.meta/tests.toml @@ -0,0 +1,21 @@ +# This is an auto-generated file. Regular comments will be removed when this +# file is regenerated. Regenerating will not touch any manually added keys, +# so comments can be added in a "comment" key. + +[e01f6db6-613c-4b55-9c09-e87edc0b04dd] +description = "The dimensions of the maze are correct" + +[4782cea6-a1e3-48b2-b825-a805890b5118] +description = "The maze contains only valid characters" + +[1433a6ff-d18e-4ade-b37c-40b286218f07] +description = "The maze has a single entrance on the left side" + +[a0be2a1c-4ec1-412a-8a30-36d6b1d96df2] +description = "The maze has a single exit on the right side" + +[9fc2d2e3-af4a-4ab1-8e8f-cf6f6f7eaf04] +description = "if the seed parameter is omitted, random mazes should be generated" + +[a0d3e4f4-b05b-4ac2-8e8a-df7f7f8eaf05] +description = "if the seed parameter is specified, the same maze should be generated" diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 40a8cfe71..5a7a36704 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -32,7 +32,7 @@ class MazeGeneratorTest { private MazeGenerator sut; @Before - void SetUp() { + void setup() { sut = new MazeGenerator(); } @@ -51,7 +51,7 @@ void mazeIsNotNull() { @Ignore("Remove to run test") @Test - void theDimensionsAreCorrect() { + void theDimensionsOfTheMazeAreCorrect() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); var expectedWidth = RECTANGLE_COLUMNS * 2 + 1; var expectedHeight = RECTANGLE_ROWS * 2 + 1; @@ -65,38 +65,6 @@ void theDimensionsAreCorrect() { .hasSize(expectedWidth); } - @Ignore("Remove to run test") - @Test - void aMazeIsDifferentEachTimeItIsGenerated() { - var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); - var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); - - assertThat(maze1) - .as("Two mazes should not be equal") - .isNotEqualTo(maze2); - } - - @Ignore("Remove to run test") - @Test - void twoMazesWithSameSeedShouldBeEqual() { - var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); - var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); - - assertThat(maze1) - .as("Two mazes with the same seed should be equal") - .isEqualTo(maze2); - } - - @Ignore("Remove to run test") - @Test - void twoMazesWithDifferentSeedsShouldNotBeEqual() { - var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); - var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_TWO); - - assertThat(maze1) - .as("Two mazes with different seeds should not be equal") - .isNotEqualTo(maze2); - } @Ignore("Remove to run test") @Test @@ -125,7 +93,7 @@ void theMazeHasOnlyOneEntranceOnTheLeftSide() { @Ignore("Remove to run test") @Test - void theMazeHasASingleExitOnTheRightSideOfTheMaze() { + void theMazeHasSingleExitOnTheRightSideOfTheMaze() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); int exitCount = countExits(maze); @@ -134,6 +102,39 @@ void theMazeHasASingleExitOnTheRightSideOfTheMaze() { .isOne(); } + @Ignore("Remove to run test") + @Test + void aMazeIsDifferentEachTimeItIsGenerated() { + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); + + assertThat(maze1) + .as("Two mazes should not be equal") + .isNotEqualTo(maze2); + } + + @Ignore("Remove to run test") + @Test + void twoMazesWithSameSeedShouldBeEqual() { + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + + assertThat(maze1) + .as("Two mazes with the same seed should be equal") + .isEqualTo(maze2); + } + + @Ignore("Remove to run test") + @Test + void twoMazesWithDifferentSeedsShouldNotBeEqual() { + var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_TWO); + + assertThat(maze1) + .as("Two mazes with different seeds should not be equal") + .isNotEqualTo(maze2); + } + @Ignore("Remove to run test") @Test void theMazeIsPerfect() { From d8585eb5e9bf214047c9493747ea926f047fd07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sat, 28 Oct 2023 17:54:53 +0300 Subject: [PATCH 13/29] Change access modifier for test methods in MazeGeneratorTest This commit changes the access modifier of all test methods in the `MazeGeneratorTest` class from default to public. This necessary change, switching to public, allows JUnit to access the test methods. Previously, due to default access level it could cause issues with the test runner and result in no tests being executed. Access modifiers were also applied to the `setup` method to ensure it properly annotated before each test run. Making these methods public improves test functionality and ensures they are recognized as legitimate JUnit tests. --- .../src/test/java/MazeGeneratorTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 5a7a36704..dbd86d722 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -class MazeGeneratorTest { +public class MazeGeneratorTest { private static final char EMPTY_CELL = ' '; private static final Set ALLOWED_SYMBOLS = Set.of( EMPTY_CELL, // space @@ -32,12 +32,12 @@ class MazeGeneratorTest { private MazeGenerator sut; @Before - void setup() { + public void setup() { sut = new MazeGenerator(); } @Test - void mazeIsNotNull() { + public void mazeIsNotNull() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); assertThat(maze) @@ -51,7 +51,7 @@ void mazeIsNotNull() { @Ignore("Remove to run test") @Test - void theDimensionsOfTheMazeAreCorrect() { + public void theDimensionsOfTheMazeAreCorrect() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); var expectedWidth = RECTANGLE_COLUMNS * 2 + 1; var expectedHeight = RECTANGLE_ROWS * 2 + 1; @@ -68,7 +68,7 @@ void theDimensionsOfTheMazeAreCorrect() { @Ignore("Remove to run test") @Test - void theMazeContainsOnlyValidCharacters() { + public void theMazeContainsOnlyValidCharacters() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); for (var row : maze) { @@ -82,7 +82,7 @@ void theMazeContainsOnlyValidCharacters() { @Ignore("Remove to run test") @Test - void theMazeHasOnlyOneEntranceOnTheLeftSide() { + public void theMazeHasOnlyOneEntranceOnTheLeftSide() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); int entranceCount = countEntrances(maze); @@ -93,7 +93,7 @@ void theMazeHasOnlyOneEntranceOnTheLeftSide() { @Ignore("Remove to run test") @Test - void theMazeHasSingleExitOnTheRightSideOfTheMaze() { + public void theMazeHasSingleExitOnTheRightSideOfTheMaze() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); int exitCount = countExits(maze); @@ -104,7 +104,7 @@ void theMazeHasSingleExitOnTheRightSideOfTheMaze() { @Ignore("Remove to run test") @Test - void aMazeIsDifferentEachTimeItIsGenerated() { + public void aMazeIsDifferentEachTimeItIsGenerated() { var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); @@ -115,7 +115,7 @@ void aMazeIsDifferentEachTimeItIsGenerated() { @Ignore("Remove to run test") @Test - void twoMazesWithSameSeedShouldBeEqual() { + public void twoMazesWithSameSeedShouldBeEqual() { var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); @@ -126,7 +126,7 @@ void twoMazesWithSameSeedShouldBeEqual() { @Ignore("Remove to run test") @Test - void twoMazesWithDifferentSeedsShouldNotBeEqual() { + public void twoMazesWithDifferentSeedsShouldNotBeEqual() { var maze1 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); var maze2 = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_TWO); @@ -137,7 +137,7 @@ void twoMazesWithDifferentSeedsShouldNotBeEqual() { @Ignore("Remove to run test") @Test - void theMazeIsPerfect() { + public void theMazeIsPerfect() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); assertThatMazeHasSinglePath(maze); From 4416e9e1cb5f4800685dcf90b22fcd1286d38b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sun, 29 Oct 2023 13:49:15 +0200 Subject: [PATCH 14/29] Add additional hints for exercise in hints.md This commit adds important hints in the hints.md file for the 'mazy-mice' exercise. It introduces useful general information regarding the generation of random numbers in Java 17 including links to valuable resources. This could help participants to understand better how to deal with random numbers and thus can improve the exercise's learning objectives. --- exercises/practice/mazy-mice/.docs/hints.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exercises/practice/mazy-mice/.docs/hints.md b/exercises/practice/mazy-mice/.docs/hints.md index 9d859df4d..0313b8f52 100644 --- a/exercises/practice/mazy-mice/.docs/hints.md +++ b/exercises/practice/mazy-mice/.docs/hints.md @@ -1,5 +1,10 @@ # Hints +## General + +- You can use the [Random class][random-class] to generate random numbers. +- Read more in article: [Random Number Generators in Java 17][random-number-generators]. + ## Maze generation You can use any algorithm to generate a perfect maze. The [recursive backtracker][recursive-backtracker] is a good choice. @@ -21,3 +26,5 @@ You can use any algorithm to generate a perfect maze. The [recursive backtracker [recursive-backtracker]: https://en.wikipedia.org/wiki/Maze_generation_algorithm +[random-class]: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Random.html +[random-number-generators]: https://www.baeldung.com/java-17-random-number-generators From a25e6b38818cbcabd384b0ba4013dded53929cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sun, 29 Oct 2023 19:13:26 +0200 Subject: [PATCH 15/29] Add a new test for seeded maze generator This commit added a new test case to the MazeGeneratorTest file. The added test, "theMazeIsPerfectWithSeed", simulates a perfect maze generation with a predefined seed. This test aims to help to ensure that the maze generator can correctly use seed to produce the expected unique maze structure. This also enhances the test coverage and further ensures the robustness of the maze generating code. --- .../mazy-mice/src/test/java/MazeGeneratorTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index dbd86d722..d14b5b9cf 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -144,6 +144,15 @@ public void theMazeIsPerfect() { assertThatMazeHasNoIsolatedSections(maze); } + @Ignore("Remove to run test") + @Test + public void theMazeIsPerfectWithSeed() { + var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS, SEED_ONE); + + assertThatMazeHasSinglePath(maze); + assertThatMazeHasNoIsolatedSections(maze); + } + private void assertThatMazeHasSinglePath(char[][] maze) { assertMazeHasSinglePath(maze, 1, 1); } From 473e7355fea10d41276448c15bcc9c367eb09e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sun, 29 Oct 2023 19:18:12 +0200 Subject: [PATCH 16/29] Add tests for maze size validation In this commit, 4 new tests have been added to the MazeGeneratorTest in order to check the validity of size parameters passed to the 'generatePerfectMaze' function. These tests ensure that both rows and columns parameters are within acceptable range (5-100) by throwing an IllegalArgumentException if they are not. --- .../src/test/java/MazeGeneratorTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index d14b5b9cf..20c3c3953 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -6,6 +6,7 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; public class MazeGeneratorTest { private static final char EMPTY_CELL = ' '; @@ -153,6 +154,34 @@ public void theMazeIsPerfectWithSeed() { assertThatMazeHasNoIsolatedSections(maze); } + @Ignore("Remove to run test") + @Test + public void shouldThrowExceptionWhenRowsIsLessThanFive() { + assertThatIllegalArgumentException() + .isThrownBy(() -> sut.generatePerfectMaze(0, RECTANGLE_COLUMNS)); + } + + @Ignore("Remove to run test") + @Test + public void shouldThrowExceptionWhenColumnsIsLessThanFive() { + assertThatIllegalArgumentException() + .isThrownBy(() -> sut.generatePerfectMaze(RECTANGLE_ROWS, 0)); + } + + @Ignore("Remove to run test") + @Test + public void shouldThrowExceptionWhenRowsIsMoreThenHundred() { + assertThatIllegalArgumentException() + .isThrownBy(() -> sut.generatePerfectMaze(101, RECTANGLE_COLUMNS)); + } + + @Ignore("Remove to run test") + @Test + public void shouldThrowExceptionWhenColumnsIsMoreThenHundred() { + assertThatIllegalArgumentException() + .isThrownBy(() -> sut.generatePerfectMaze(RECTANGLE_ROWS, 101)); + } + private void assertThatMazeHasSinglePath(char[][] maze) { assertMazeHasSinglePath(maze, 1, 1); } From ca072f3c48a5d0397721e7d3abce40bdcf7f3fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Sun, 29 Oct 2023 19:21:56 +0200 Subject: [PATCH 17/29] Add maze dimensions validation to the MazeGenerator class Dimension validation methods have been included in the maze generation methods of the MazeGenerator class. This is to ensure that the rows and columns of the maze are within an acceptable range (5-100). If these values fall out of the given range, an IllegalArgumentException is thrown. This was introduced to prevent the generation of mazes that would be too small or too big, which could lead to performance issues or unplayable mazes. --- .../mazy-mice/.meta/src/reference/java/MazeGenerator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java index f562b627f..88b9888b7 100644 --- a/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java +++ b/exercises/practice/mazy-mice/.meta/src/reference/java/MazeGenerator.java @@ -9,6 +9,7 @@ public class MazeGenerator { public char[][] generatePerfectMaze(int rows, int columns) { + validateDimensions(rows, columns); return new Grid(new Dimensions(rows, columns), RandomGenerator.getDefault()) .generateMaze() .placeDoors() @@ -16,11 +17,18 @@ public char[][] generatePerfectMaze(int rows, int columns) { } public char[][] generatePerfectMaze(int rows, int columns, int seed) { + validateDimensions(rows, columns); return new Grid(new Dimensions(rows, columns), new Random(seed)) .generateMaze() .placeDoors() .print(); } + + private void validateDimensions(int rows, int columns) { + if (rows < 5 || columns < 5 || rows > 100 || columns > 100) { + throw new IllegalArgumentException("Dimensions must be in range."); + } + } } enum Direction { From 5b9e2c5862841f356b8fc035dce7e88400da67d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:03:31 +0200 Subject: [PATCH 18/29] Revise header formatting in instructions.md The heading formatting in the instructions.md document within the mazy-mice exercise directory has been revised. The markdown format was adjusted from using "##" to make it a sub-heading, to "#" to make it a top level heading. This change has been implemented for clarity and readability, making it easier for users to understand the structure of the document. --- exercises/practice/mazy-mice/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/.docs/instructions.md b/exercises/practice/mazy-mice/.docs/instructions.md index e745cda8c..b217223a9 100644 --- a/exercises/practice/mazy-mice/.docs/instructions.md +++ b/exercises/practice/mazy-mice/.docs/instructions.md @@ -1,4 +1,4 @@ -## Instructions +# Instructions Your task is to generate the perfect mazes for Mickey and Minerva — those with only one solution and no isolated sections. Here's what you need to know: From 54e1580f70dabca0c0dc781e343f106a7cf71e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:04:55 +0200 Subject: [PATCH 19/29] Remove redundant .meta/tests.toml file --- exercises/practice/mazy-mice/.meta/tests.toml | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 exercises/practice/mazy-mice/.meta/tests.toml diff --git a/exercises/practice/mazy-mice/.meta/tests.toml b/exercises/practice/mazy-mice/.meta/tests.toml deleted file mode 100644 index 6b84b1f3c..000000000 --- a/exercises/practice/mazy-mice/.meta/tests.toml +++ /dev/null @@ -1,21 +0,0 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. - -[e01f6db6-613c-4b55-9c09-e87edc0b04dd] -description = "The dimensions of the maze are correct" - -[4782cea6-a1e3-48b2-b825-a805890b5118] -description = "The maze contains only valid characters" - -[1433a6ff-d18e-4ade-b37c-40b286218f07] -description = "The maze has a single entrance on the left side" - -[a0be2a1c-4ec1-412a-8a30-36d6b1d96df2] -description = "The maze has a single exit on the right side" - -[9fc2d2e3-af4a-4ab1-8e8f-cf6f6f7eaf04] -description = "if the seed parameter is omitted, random mazes should be generated" - -[a0d3e4f4-b05b-4ac2-8e8a-df7f7f8eaf05] -description = "if the seed parameter is specified, the same maze should be generated" From 07777d7942935a873e3e57f048b4e3cd3f49434e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:06:13 +0200 Subject: [PATCH 20/29] delete version file --- exercises/practice/mazy-mice/.meta/version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 exercises/practice/mazy-mice/.meta/version diff --git a/exercises/practice/mazy-mice/.meta/version b/exercises/practice/mazy-mice/.meta/version deleted file mode 100644 index 3eefcb9dd..000000000 --- a/exercises/practice/mazy-mice/.meta/version +++ /dev/null @@ -1 +0,0 @@ -1.0.0 From 7be25c07df1e9c06b772f19dd6ed3a2219408d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:07:13 +0200 Subject: [PATCH 21/29] Remove Dimensions.java as its functionality is redundant The file Dimensions.java was deleted because its purpose - to represent the dimensions of a maze - is already covered by another class in our program. Its functionality including width and height calculations, which were previously done in cells, are now handled elsewhere, making this file unnecessary. --- .../mazy-mice/src/main/java/Dimensions.java | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 exercises/practice/mazy-mice/src/main/java/Dimensions.java diff --git a/exercises/practice/mazy-mice/src/main/java/Dimensions.java b/exercises/practice/mazy-mice/src/main/java/Dimensions.java deleted file mode 100644 index f7e178c10..000000000 --- a/exercises/practice/mazy-mice/src/main/java/Dimensions.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Represents the dimensions of a maze. - *

- * Dimensions of a grid can be represented in cells or characters. - * Rows and columns are used for cells, while width and height are used for characters. - */ -public record Dimensions(int rows, int columns) { - /** - * Returns the width of the maze in characters. - * - * @return the width of the maze - */ - int width() { - return 2 * columns + 1; - } - - /** - * Returns the height of the maze in characters. - * - * @return the height of the maze - */ - int height() { - return 2 * rows + 1; - } -} From 44367ac87965091741f7118916b7701e70a9519a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:08:32 +0200 Subject: [PATCH 22/29] Update exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java Co-authored-by: Sander Ploegsma --- .../practice/mazy-mice/src/test/java/MazeGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 20c3c3953..f088443e0 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -58,7 +58,7 @@ public void theDimensionsOfTheMazeAreCorrect() { var expectedHeight = RECTANGLE_ROWS * 2 + 1; assertThat(maze) - .as("The dimensions of the maze are correct.") + .as("The maze has the correct number of rows") .hasSize(expectedHeight); assertThat(maze[0]) From 0d446b83637e71de0fac6fd07d2d1ec7968f00a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 11:08:47 +0200 Subject: [PATCH 23/29] Update exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java Co-authored-by: Sander Ploegsma --- .../practice/mazy-mice/src/test/java/MazeGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index f088443e0..118e5816c 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -62,7 +62,7 @@ public void theDimensionsOfTheMazeAreCorrect() { .hasSize(expectedHeight); assertThat(maze[0]) - .as("The dimensions of the maze are correct.") + .as("The maze has the correct number of columns") .hasSize(expectedWidth); } From 004b60d501b30b671033fac03eade413fbb55873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 12:42:12 +0200 Subject: [PATCH 24/29] Update config.json to include new practices Added "strings" and "for-loops" to the "practices" array in the config.json file. This change is necessary to ensure all necessary learning concepts are being covered within the curriculum. --- config.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.json b/config.json index efc7694a6..af00440ab 100644 --- a/config.json +++ b/config.json @@ -1978,6 +1978,8 @@ "uuid": "1bac7473-9ee8-4cfc-928b-77792102ffc1", "practices": [ "chars", + "strings", + "for-loops", "arrays" ], "prerequisites": [ From 2f77e5e99deb661e296d3b0da4242c3b7b388d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 12:42:12 +0200 Subject: [PATCH 25/29] Add new game "Mazy Mice" in config.json The new game "Mazy Mice" with corresponding uuid, practices, prerequisites, and difficulty level was added to the config.json. This is essential for including a new game in the curriculum that emphasizes the application of "strings" and "for-loops" practices. --- config.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config.json b/config.json index 62fe8f19e..e1aafd293 100644 --- a/config.json +++ b/config.json @@ -1983,6 +1983,22 @@ "numbers" ], "difficulty": 3 + }, + { + "slug": "mazy-mice", + "name": "Mazy Mice", + "uuid": "1bac7473-9ee8-4cfc-928b-77792102ffc1", + "practices": [ + "chars", + "strings", + "for-loops", + "arrays" + ], + "prerequisites": [ + "strings", + "for-loops" + ], + "difficulty": 8 } ] }, From 4afc2f1dba950855498e0181d2ca25c239749793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 12:49:55 +0200 Subject: [PATCH 26/29] Add Dimensions.java to Mazy Mice example files Included "Dimensions.java" in the example files array for the "Mazy Mice" problem in config.json, as it is needed for the correct generation of the maze. Not including this could lead to errors or incomplete solutions. --- exercises/practice/mazy-mice/.meta/config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/practice/mazy-mice/.meta/config.json b/exercises/practice/mazy-mice/.meta/config.json index d717f2cc7..82cb0e436 100644 --- a/exercises/practice/mazy-mice/.meta/config.json +++ b/exercises/practice/mazy-mice/.meta/config.json @@ -10,7 +10,8 @@ "src/test/java/MazeGeneratorTest.java" ], "example": [ - ".meta/src/reference/java/MazeGenerator.java" + ".meta/src/reference/java/MazeGenerator.java", + ".meta/src/reference/java/Dimensions.java" ], "invalidator": [ "build.gradle" From 0db470a79b71db23546b7a4ac7333ce4d59aa968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Tue, 31 Oct 2023 12:52:05 +0200 Subject: [PATCH 27/29] Remove redundant mazeNotNull test in MazeGeneratorTest class The mazeIsNotNull test in MazeGeneratorTest class was removed as it was deemed unnecessary and redundant. The null check is already implicitly covered in the subsequent dimensions and valid characters tests. --- .../src/test/java/MazeGeneratorTest.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 118e5816c..9f056eb1c 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -37,20 +37,6 @@ public void setup() { sut = new MazeGenerator(); } - @Test - public void mazeIsNotNull() { - var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); - - assertThat(maze) - .as("The maze is not null.") - .isNotNull(); - - Arrays.stream(maze) - .map(String::new) - .forEach(System.out::println); - } - - @Ignore("Remove to run test") @Test public void theDimensionsOfTheMazeAreCorrect() { var maze = sut.generatePerfectMaze(RECTANGLE_ROWS, RECTANGLE_COLUMNS); @@ -66,7 +52,6 @@ public void theDimensionsOfTheMazeAreCorrect() { .hasSize(expectedWidth); } - @Ignore("Remove to run test") @Test public void theMazeContainsOnlyValidCharacters() { From 833a94d0367c9b0ee92180cfbcea89b41067461d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Wed, 1 Nov 2023 09:49:33 +0200 Subject: [PATCH 28/29] Refactor MazeGeneratorTest for better test organization Moved `Direction` enum to the top of the MazeGeneratorTest class to improve code organization and readability. Adjusted dimensions test to use Arrays.stream for enhanced test flow and comprehension. Removed redundant mazeNotNull test. --- .../src/test/java/MazeGeneratorTest.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java index 9f056eb1c..631d0b293 100644 --- a/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java +++ b/exercises/practice/mazy-mice/src/test/java/MazeGeneratorTest.java @@ -8,6 +8,28 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +enum Direction { + NORTH(0, 1), + EAST(1, 0), + SOUTH(0, -1), + WEST(-1, 0); + private final int dx; + private final int dy; + + Direction(int dx, int dy) { + this.dx = dx; + this.dy = dy; + } + + public int dx() { + return dx; + } + + public int dy() { + return dy; + } +} + public class MazeGeneratorTest { private static final char EMPTY_CELL = ' '; private static final Set ALLOWED_SYMBOLS = Set.of( @@ -47,9 +69,11 @@ public void theDimensionsOfTheMazeAreCorrect() { .as("The maze has the correct number of rows") .hasSize(expectedHeight); - assertThat(maze[0]) - .as("The maze has the correct number of columns") - .hasSize(expectedWidth); + Arrays.stream(maze).forEach(row -> + assertThat(row) + .as("The maze has the correct number of columns") + .hasSize(expectedWidth) + ); } @Ignore("Remove to run test") @@ -220,25 +244,3 @@ private int countEntrances(char[][] maze) { return entranceCount; } } - -enum Direction { - NORTH(0, 1), - EAST(1, 0), - SOUTH(0, -1), - WEST(-1, 0); - private final int dx; - private final int dy; - - Direction(int dx, int dy) { - this.dx = dx; - this.dy = dy; - } - - public int dx() { - return dx; - } - - public int dy() { - return dy; - } -} From 69c39aaeff46e79c6c7d86fa0d6ed6b58f3078b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jegors=20=C4=8Cemisovs?= Date: Wed, 1 Nov 2023 11:08:46 +0200 Subject: [PATCH 29/29] Add status field to config.json --- config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index e1aafd293..32dc716eb 100644 --- a/config.json +++ b/config.json @@ -1998,7 +1998,8 @@ "strings", "for-loops" ], - "difficulty": 8 + "difficulty": 8, + "status": "beta" } ] },