Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.*;
- import org.junit.Before;
- import org.junit.Test;
- public class MazeJunits {
- private Maze m;
- //private Maze n;
- @Before
- public void setUp() throws Exception
- {
- m = new Maze(4, 4);
- //n = new Maze(5,5);
- }
- @Test
- public void TestMazeGeneration()
- {
- m.contributeMaze();
- String s = "";
- for (int i=0; i<2*4+1; i++) {
- if ( m.maze[1][i] == m.corner )
- s = s + "+";
- else if ( m.maze[1][i] == m.vWall )
- s = s + "|";
- else if ( m.maze[1][i] == m.hWall )
- s = s + "-";
- else if ( m.maze[1][i] == m.path )
- s = s + "#";
- else
- s = s + " ";
- }
- assertEquals("| | | | |", s);
- }
- @Test
- public void TestPushWall()
- {
- m.pushWall(0, 0, 1);
- m.pushWall(0, 1, 1);
- m.pushWall(0, 2, 1);
- m.contributeMaze();
- String s = "";
- for (int i=0; i<2*4+1; i++) {
- if ( m.maze[1][i] == m.corner )
- s = s + "+";
- else if ( m.maze[1][i] == m.vWall )
- s = s + "|";
- else if ( m.maze[1][i] == m.hWall )
- s = s + "-";
- else if ( m.maze[1][i] == m.path )
- s = s + "#";
- else
- s = s + " ";
- }
- assertEquals("| |", s);
- }
- @Test
- public void TestRandomizeMaze()
- {
- m.traversalJUnits();
- m.contributeMaze();
- String s = "";
- for (int i=0; i<2*4+1; i++) {
- if ( m.maze[1][i] == m.corner )
- s = s + "+";
- else if ( m.maze[1][i] == m.vWall )
- s = s + "|";
- else if ( m.maze[1][i] == m.hWall )
- s = s + "-";
- else if ( m.maze[1][i] == m.path )
- s = s + "#";
- else
- s = s + " ";
- }
- assertEquals("| | | |", s);
- }
- // @Test
- // public void TestDFS()
- // {
- // m.traversalJUnits();
- // m.contributeMaze();
- // m.findPathDFS();
- // String s = "";
- // for (int i=0; i<2*4+1; i++) {
- // if ( m.maze[m.maze.length-2][i] == m.corner )
- // s = s + "+";
- // else if ( m.maze[m.maze.length-2][i] == m.vWall )
- // s = s + "|";
- // else if ( m.maze[m.maze.length-2][i] == m.hWall )
- // s = s + "-";
- // else if ( m.maze[m.maze.length-2][i] == m.path )
- // s = s + "#";
- // else
- // s = s + " ";
- // }
- // assertEquals("|###|###|", s);
- // }
- @Test
- public void TestBFS()
- {
- m.traversalJUnits();
- m.contributeMaze();
- m.findPathBFS();
- String s = "";
- for (int i=0; i<2*4+1; i++) {
- if ( m.maze[m.maze.length-2][i] == m.corner )
- s = s + "+";
- else if ( m.maze[m.maze.length-2][i] == m.vWall )
- s = s + "|";
- else if ( m.maze[m.maze.length-2][i] == m.hWall )
- s = s + "-";
- else if ( m.maze[m.maze.length-2][i] == m.path )
- s = s + "#";
- else
- s = s + " ";
- }
- assertEquals("|###|###|", s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement