Example #1
0
  @Test
  public void dfsSmall() {
    System.out.println("Depth First Search - small");

    char[][] expectedPath = {
      {
        '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%',
        '%', '%', '%', '%', '%'
      },
      {
        '%', '.', '%', ' ', ' ', ' ', '%', ' ', ' ', ' ', '%', ' ', ' ', ' ', '%', ' ', ' ', ' ',
        '%', ' ', '%', ' ', '%'
      },
      {
        '%', '.', '%', '%', ' ', '%', ' ', '%', '%', '%', '%', '%', ' ', '%', ' ', ' ', ' ', '.',
        '.', '.', ' ', ' ', '%'
      },
      {
        '%', '.', '%', '.', '.', '.', '.', '.', '.', '.', '%', ' ', ' ', ' ', '%', ' ', '%', '.',
        '%', '.', '%', ' ', '%'
      },
      {
        '%', '.', '.', '.', '%', '%', ' ', '%', '%', '.', '%', '%', '%', ' ', '%', '.', '.', '.',
        '%', '.', '%', '%', '%'
      },
      {
        '%', ' ', '%', ' ', '%', ' ', ' ', ' ', '%', '.', '.', '.', '.', '.', '.', '.', '%', ' ',
        '%', '.', '.', 'P', '%'
      },
      {
        '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%', '%',
        '%', '%', '%', '%', '%'
      },
    };

    Search x = new DepthFirstSearch("test-files/smallMaze.txt");
    MazeSolution actual = x.solve();

    System.out.println(actual.toString());
    assertEquals(actual.pathCost, 32);
    assertEquals(actual.numNodesExpanded, 57);
    assertMazesAreEqual(actual, expectedPath);
  }
Example #2
0
  @Test
  public void dfsVsBfs2() {
    System.out.println("Depth First Search - should go long way around to right");

    char[][] expectedPath = {
      {'%', '%', '%', '%', '%', '%', '%'},
      {'%', ' ', ' ', '.', '.', '.', '%'},
      {'%', ' ', 'P', '%', '%', '.', '%'},
      {'%', ' ', '.', '.', '.', '.', '%'},
      {'%', '%', '%', '%', '%', '%', '%'}
    };

    Search x = new DepthFirstSearch("test-files/dfsVsBfs2.txt");
    MazeSolution actual = x.solve();

    System.out.println(actual.toString());

    assertEquals(actual.pathCost, 8);
    assertEquals(actual.numNodesExpanded, 8);
    assertMazesAreEqual(actual, expectedPath);
  }
Example #3
0
  @Test
  public void badGreedy() {
    System.out.println("Depth First Search - does great on bad greedy");

    char[][] expectedPath = {
      {'%', '%', '%', '%', '%', '%'},
      {'%', ' ', ' ', ' ', '%', '%'},
      {'%', 'P', ' ', '%', '.', '%'},
      {'%', '.', '%', ' ', '.', '%'},
      {'%', '.', '.', '.', '.', '%'},
      {'%', '%', '%', '%', '%', '%'}
    };

    Search x = new DepthFirstSearch("test-files/badGreedy.txt");
    MazeSolution actual = x.solve();

    System.out.println(actual.toString());

    assertEquals(actual.pathCost, 7);
    assertEquals(actual.numNodesExpanded, 7);
    assertMazesAreEqual(actual, expectedPath);
  }