This commit is contained in:
		
							parent
							
								
									49725fe7df
								
							
						
					
					
						commit
						b18e7fba9e
					
				
					 3 changed files with 26 additions and 28 deletions
				
			
		|  | @ -35,18 +35,18 @@ public class Tile { | ||||||
|     private Tile(@NotNull final EnumSet<Direction> walls, final boolean solution) { |     private Tile(@NotNull final EnumSet<Direction> walls, final boolean solution) { | ||||||
|         for (final Direction direction : walls) { |         for (final Direction direction : walls) { | ||||||
|             this.walls.set(direction); |             this.walls.set(direction); | ||||||
|             this.walls.harden(direction); |             this.walls.seal(direction); | ||||||
|         } |         } | ||||||
|         this.visited = true; |         this.visited = true; | ||||||
|         this.solution = solution; |         this.solution = solution; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void preventDiggingToOrFrom(@NotNull final Direction direction) { |     public void preventDiggingToOrFrom(@NotNull final Direction direction) { | ||||||
|         this.walls.harden(direction); |         this.walls.seal(direction); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void enableDiggingToOrFrom(@NotNull final Direction direction) { |     public void enableDiggingToOrFrom(@NotNull final Direction direction) { | ||||||
|         this.walls.unharden(direction); |         this.walls.unseal(direction); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public boolean digFrom(@NotNull final Direction direction) { |     public boolean digFrom(@NotNull final Direction direction) { | ||||||
|  | @ -66,7 +66,7 @@ public class Tile { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Option<Direction> getRandomAvailableDirection(@NotNull final Random random) { |     public Option<Direction> getRandomAvailableDirection(@NotNull final Random random) { | ||||||
|         final Stream<Direction> availableDirections = this.walls.getUnhardenedSet(); |         final Stream<Direction> availableDirections = this.walls.getUnsealedSet(); | ||||||
|         if (availableDirections.isEmpty()) { |         if (availableDirections.isEmpty()) { | ||||||
|             return Option.none(); |             return Option.none(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ import java.util.TreeSet; | ||||||
| @ToString | @ToString | ||||||
| public class Walls { | public class Walls { | ||||||
|     private final SortedSet<Direction> directions = new TreeSet<>(); |     private final SortedSet<Direction> directions = new TreeSet<>(); | ||||||
|     private final Set<Direction> hardened = new HashSet<>(); |     private final Set<Direction> sealed = new HashSet<>(); | ||||||
| 
 | 
 | ||||||
|     public void set(@NotNull final Direction direction) { |     public void set(@NotNull final Direction direction) { | ||||||
|         this.directions.add(direction); |         this.directions.add(direction); | ||||||
|  | @ -26,7 +26,7 @@ public class Walls { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public boolean clear(@NotNull final Direction direction) { |     public boolean clear(@NotNull final Direction direction) { | ||||||
|         if (this.hardened.contains(direction)) { |         if (this.sealed.contains(direction)) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|         return this.directions.remove(direction); |         return this.directions.remove(direction); | ||||||
|  | @ -36,19 +36,19 @@ public class Walls { | ||||||
|         return this.directions.contains(direction); |         return this.directions.contains(direction); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Stream<Direction> getUnhardenedSet() { |     public Stream<Direction> getUnsealedSet() { | ||||||
|         return Stream.ofAll(this.directions) |         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)) { |         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) { |     public void unseal(@NotNull final Direction direction) { | ||||||
|         this.hardened.remove(direction); |         this.sealed.remove(direction); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,5 @@ | ||||||
| package ch.fritteli.maze.generator.model; | 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 io.vavr.collection.Stream; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| 
 | 
 | ||||||
|  | @ -65,14 +63,14 @@ class WallsTest { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void testHarden() { |     void testSeal() { | ||||||
|         // arrange |         // arrange | ||||||
|         final Walls sut = new Walls(); |         final Walls sut = new Walls(); | ||||||
|         sut.set(Direction.TOP); |         sut.set(Direction.TOP); | ||||||
|         sut.set(Direction.RIGHT); |         sut.set(Direction.RIGHT); | ||||||
| 
 | 
 | ||||||
|         // act |         // act | ||||||
|         sut.harden(Direction.TOP); |         sut.seal(Direction.TOP); | ||||||
| 
 | 
 | ||||||
|         // assert |         // assert | ||||||
|         assertThat(sut) |         assertThat(sut) | ||||||
|  | @ -88,34 +86,34 @@ class WallsTest { | ||||||
|         assertThat(result).isFalse(); |         assertThat(result).isFalse(); | ||||||
|         assertThat(sut.isSet(Direction.TOP)).isTrue(); |         assertThat(sut.isSet(Direction.TOP)).isTrue(); | ||||||
| 
 | 
 | ||||||
|         // act / assert: try to harden un-set wall |         // act / assert: try to seal un-set wall | ||||||
|         assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> sut.harden(Direction.LEFT)); |         assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> sut.seal(Direction.LEFT)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void testUnharden() { |     void testUnseal() { | ||||||
|         // arrange |         // arrange | ||||||
|         final Walls sut = new Walls(); |         final Walls sut = new Walls(); | ||||||
|         sut.setAll(); |         sut.setAll(); | ||||||
|         sut.harden(Direction.TOP); |         sut.seal(Direction.TOP); | ||||||
| 
 | 
 | ||||||
|         // pre-assert: TOP can't be cleared while hardened |         // pre-assert: TOP can't be cleared while hardened | ||||||
|         assertThat(sut.clear(Direction.TOP)).isFalse(); |         assertThat(sut.clear(Direction.TOP)).isFalse(); | ||||||
| 
 | 
 | ||||||
|         // act |         // act | ||||||
|         sut.unharden(Direction.TOP); |         sut.unseal(Direction.TOP); | ||||||
| 
 | 
 | ||||||
|         // assert: TOP can be cleared |         // assert: TOP can be cleared | ||||||
|         assertThat(sut.clear(Direction.TOP)).isTrue(); |         assertThat(sut.clear(Direction.TOP)).isTrue(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void testGetUnhardenedSet() { |     void testGetUnsealedSet() { | ||||||
|         // arrange |         // arrange | ||||||
|         final Walls sut = new Walls(); |         final Walls sut = new Walls(); | ||||||
| 
 | 
 | ||||||
|         // act |         // act | ||||||
|         Stream<Direction> result = sut.getUnhardenedSet(); |         Stream<Direction> result = sut.getUnsealedSet(); | ||||||
| 
 | 
 | ||||||
|         // assert |         // assert | ||||||
|         assertThat(result).isEmpty(); |         assertThat(result).isEmpty(); | ||||||
|  | @ -125,16 +123,16 @@ class WallsTest { | ||||||
|         sut.set(Direction.LEFT); |         sut.set(Direction.LEFT); | ||||||
| 
 | 
 | ||||||
|         // act |         // act | ||||||
|         result = sut.getUnhardenedSet(); |         result = sut.getUnsealedSet(); | ||||||
| 
 | 
 | ||||||
|         // assert |         // assert | ||||||
|         assertThat(result).containsExactly(Direction.TOP, Direction.LEFT); |         assertThat(result).containsExactly(Direction.TOP, Direction.LEFT); | ||||||
| 
 | 
 | ||||||
|         // arrange: harden a direction |         // arrange: seal a direction | ||||||
|         sut.harden(Direction.TOP); |         sut.seal(Direction.TOP); | ||||||
| 
 | 
 | ||||||
|         // act |         // act | ||||||
|         result = sut.getUnhardenedSet(); |         result = sut.getUnsealedSet(); | ||||||
| 
 | 
 | ||||||
|         // assert |         // assert | ||||||
|         assertThat(result).containsExactly(Direction.LEFT); |         assertThat(result).containsExactly(Direction.LEFT); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue