Exemple #1
0
 @Test
 public void testWallRemoval() {
   testEachMaze(
       m -> {
         Position p = new Position(1, 1);
         for (Direction d : Direction.values()) m.addWallAt(p, d);
         int nbOfNeighbours = 0;
         assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         for (Direction d : Direction.values()) {
           assertTrue(m.hasWallAt(p, d));
           m.removeWallAt(p, d);
           assertFalse(m.hasWallAt(p, d));
           nbOfNeighbours++;
           assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         }
         p = new Position(2, 2);
         for (Direction d : Direction.values()) m.addWallAt(p, d);
         nbOfNeighbours = 0;
         assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         for (Direction d : Direction.values()) {
           Position adjacent = p.neighbour(d);
           assertTrue(m.hasWallBetween(p, adjacent));
           m.removeWallBetween(p, adjacent);
           assertFalse(m.hasWallBetween(p, adjacent));
           nbOfNeighbours++;
           assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         }
       });
 }
Exemple #2
0
 @Test
 public void testWallAddition() {
   testEachMaze(
       m -> {
         Position p = new Position(1, 1);
         int nbOfNeighbours = 4;
         assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         for (Direction d : Direction.values()) {
           assertFalse(m.hasWallAt(p, d));
           m.addWallAt(p, d);
           assertTrue(m.hasWallAt(p, d));
           nbOfNeighbours--;
           assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         }
         p = new Position(2, 2);
         nbOfNeighbours = 4;
         for (Direction d : Direction.values()) {
           Position q = p.neighbour(d);
           assertFalse(m.hasWallBetween(p, q));
           m.addWallBetween(p, q);
           assertTrue(m.hasWallBetween(p, q));
           nbOfNeighbours--;
           assertEquals(nbOfNeighbours, m.neighboursOf(m.vertexAt(p)).size());
         }
       });
 }
Exemple #3
0
 @Test
 public void testWallCheck() {
   testEachMaze(
       m -> {
         Position p = new Position(1, 1);
         Arrays.stream(Direction.values())
             .forEach(
                 d -> {
                   assertFalse(m.hasWallAt(p, d));
                 });
         Position q = new Position(0, 0);
         assertTrue(m.hasWallAt(q, Direction.DOWN));
         assertTrue(m.hasWallAt(q, Direction.LEFT));
         assertFalse(m.hasWallAt(q, Direction.UP));
         assertFalse(m.hasWallAt(q, Direction.RIGHT));
       });
 }
Exemple #4
0
 private static void benchAddition() {
   System.out.println("Adding walls:");
   Maze<MazeNode> matrix = MazeBuilder.square(BENCH_SIZE, MazeNode::new).build();
   MappedMaze<MazeNode> mapped = MazeBuilder.square(BENCH_SIZE, MazeNode::new).mapped();
   Function<Maze<MazeNode>, Duration> f =
       m ->
           durationOf(
               () -> {
                 m.getVertices()
                     .forEach(
                         v -> {
                           Arrays.stream(Direction.values())
                               .forEach(
                                   d -> {
                                     m.addWallAt(v.getPosition(), d);
                                   });
                         });
               });
   System.out.println(" MatrixMaze: " + f.apply(matrix).toMillis() + "ms");
   System.out.println(" MappedMaze: " + f.apply(mapped).toMillis() + "ms");
 }