From b18e7fba9ebe2e0f7b14ba095b45cfe55aab5bde Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 18 May 2024 02:18:06 +0200 Subject: [PATCH] Reword some stuff. --- .../fritteli/maze/generator/model/Tile.java | 8 +++--- .../fritteli/maze/generator/model/Walls.java | 18 ++++++------ .../maze/generator/model/WallsTest.java | 28 +++++++++---------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/main/java/ch/fritteli/maze/generator/model/Tile.java b/src/main/java/ch/fritteli/maze/generator/model/Tile.java index c6f9367..c18ef5d 100644 --- a/src/main/java/ch/fritteli/maze/generator/model/Tile.java +++ b/src/main/java/ch/fritteli/maze/generator/model/Tile.java @@ -35,18 +35,18 @@ public class Tile { private Tile(@NotNull final EnumSet walls, final boolean solution) { for (final Direction direction : walls) { this.walls.set(direction); - this.walls.harden(direction); + this.walls.seal(direction); } this.visited = true; this.solution = solution; } public void preventDiggingToOrFrom(@NotNull final Direction direction) { - this.walls.harden(direction); + this.walls.seal(direction); } public void enableDiggingToOrFrom(@NotNull final Direction direction) { - this.walls.unharden(direction); + this.walls.unseal(direction); } public boolean digFrom(@NotNull final Direction direction) { @@ -66,7 +66,7 @@ public class Tile { } public Option getRandomAvailableDirection(@NotNull final Random random) { - final Stream availableDirections = this.walls.getUnhardenedSet(); + final Stream availableDirections = this.walls.getUnsealedSet(); if (availableDirections.isEmpty()) { return Option.none(); } diff --git a/src/main/java/ch/fritteli/maze/generator/model/Walls.java b/src/main/java/ch/fritteli/maze/generator/model/Walls.java index f77ceaa..8a4b340 100644 --- a/src/main/java/ch/fritteli/maze/generator/model/Walls.java +++ b/src/main/java/ch/fritteli/maze/generator/model/Walls.java @@ -15,7 +15,7 @@ import java.util.TreeSet; @ToString public class Walls { private final SortedSet directions = new TreeSet<>(); - private final Set hardened = new HashSet<>(); + private final Set sealed = new HashSet<>(); public void set(@NotNull final Direction direction) { this.directions.add(direction); @@ -26,7 +26,7 @@ public class Walls { } public boolean clear(@NotNull final Direction direction) { - if (this.hardened.contains(direction)) { + if (this.sealed.contains(direction)) { return false; } return this.directions.remove(direction); @@ -36,19 +36,19 @@ public class Walls { return this.directions.contains(direction); } - public Stream getUnhardenedSet() { + public Stream getUnsealedSet() { return Stream.ofAll(this.directions) - .removeAll(this.hardened); + .removeAll(this.sealed); } - public void harden(@NotNull final Direction direction) { + public void seal(@NotNull final Direction direction) { if (!this.directions.contains(direction)) { - throw new IllegalStateException("Trying to harden cleared Direction: " + direction); + throw new IllegalStateException("Trying to seal cleared Direction: " + direction); } - this.hardened.add(direction); + this.sealed.add(direction); } - public void unharden(@NotNull final Direction direction) { - this.hardened.remove(direction); + public void unseal(@NotNull final Direction direction) { + this.sealed.remove(direction); } } diff --git a/src/test/java/ch/fritteli/maze/generator/model/WallsTest.java b/src/test/java/ch/fritteli/maze/generator/model/WallsTest.java index 1b4f2ce..7be7269 100644 --- a/src/test/java/ch/fritteli/maze/generator/model/WallsTest.java +++ b/src/test/java/ch/fritteli/maze/generator/model/WallsTest.java @@ -1,7 +1,5 @@ package ch.fritteli.maze.generator.model; -import ch.fritteli.maze.generator.model.Direction; -import ch.fritteli.maze.generator.model.Walls; import io.vavr.collection.Stream; import org.junit.jupiter.api.Test; @@ -65,14 +63,14 @@ class WallsTest { } @Test - void testHarden() { + void testSeal() { // arrange final Walls sut = new Walls(); sut.set(Direction.TOP); sut.set(Direction.RIGHT); // act - sut.harden(Direction.TOP); + sut.seal(Direction.TOP); // assert assertThat(sut) @@ -88,34 +86,34 @@ class WallsTest { assertThat(result).isFalse(); assertThat(sut.isSet(Direction.TOP)).isTrue(); - // act / assert: try to harden un-set wall - assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> sut.harden(Direction.LEFT)); + // act / assert: try to seal un-set wall + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> sut.seal(Direction.LEFT)); } @Test - void testUnharden() { + void testUnseal() { // arrange final Walls sut = new Walls(); sut.setAll(); - sut.harden(Direction.TOP); + sut.seal(Direction.TOP); // pre-assert: TOP can't be cleared while hardened assertThat(sut.clear(Direction.TOP)).isFalse(); // act - sut.unharden(Direction.TOP); + sut.unseal(Direction.TOP); // assert: TOP can be cleared assertThat(sut.clear(Direction.TOP)).isTrue(); } @Test - void testGetUnhardenedSet() { + void testGetUnsealedSet() { // arrange final Walls sut = new Walls(); // act - Stream result = sut.getUnhardenedSet(); + Stream result = sut.getUnsealedSet(); // assert assertThat(result).isEmpty(); @@ -125,16 +123,16 @@ class WallsTest { sut.set(Direction.LEFT); // act - result = sut.getUnhardenedSet(); + result = sut.getUnsealedSet(); // assert assertThat(result).containsExactly(Direction.TOP, Direction.LEFT); - // arrange: harden a direction - sut.harden(Direction.TOP); + // arrange: seal a direction + sut.seal(Direction.TOP); // act - result = sut.getUnhardenedSet(); + result = sut.getUnsealedSet(); // assert assertThat(result).containsExactly(Direction.LEFT);