Advertisement
Guest User

MazeJUnits

a guest
Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4.  
  5. public class MazeJunits {
  6.  
  7. private Maze m;
  8. //private Maze n;
  9.  
  10. @Before
  11. public void setUp() throws Exception
  12. {
  13. m = new Maze(4, 4);
  14. //n = new Maze(5,5);
  15.  
  16. }
  17.  
  18. @Test
  19. public void TestMazeGeneration()
  20. {
  21. m.contributeMaze();
  22. String s = "";
  23. for (int i=0; i<2*4+1; i++) {
  24. if ( m.maze[1][i] == m.corner )
  25. s = s + "+";
  26. else if ( m.maze[1][i] == m.vWall )
  27. s = s + "|";
  28. else if ( m.maze[1][i] == m.hWall )
  29. s = s + "-";
  30. else if ( m.maze[1][i] == m.path )
  31. s = s + "#";
  32. else
  33. s = s + " ";
  34. }
  35. assertEquals("| | | | |", s);
  36.  
  37. }
  38.  
  39. @Test
  40. public void TestPushWall()
  41. {
  42. m.pushWall(0, 0, 1);
  43. m.pushWall(0, 1, 1);
  44. m.pushWall(0, 2, 1);
  45. m.contributeMaze();
  46.  
  47. String s = "";
  48. for (int i=0; i<2*4+1; i++) {
  49. if ( m.maze[1][i] == m.corner )
  50. s = s + "+";
  51. else if ( m.maze[1][i] == m.vWall )
  52. s = s + "|";
  53. else if ( m.maze[1][i] == m.hWall )
  54. s = s + "-";
  55. else if ( m.maze[1][i] == m.path )
  56. s = s + "#";
  57. else
  58. s = s + " ";
  59. }
  60.  
  61. assertEquals("| |", s);
  62. }
  63.  
  64. @Test
  65. public void TestRandomizeMaze()
  66. {
  67. m.traversalJUnits();
  68. m.contributeMaze();
  69. String s = "";
  70. for (int i=0; i<2*4+1; i++) {
  71. if ( m.maze[1][i] == m.corner )
  72. s = s + "+";
  73. else if ( m.maze[1][i] == m.vWall )
  74. s = s + "|";
  75. else if ( m.maze[1][i] == m.hWall )
  76. s = s + "-";
  77. else if ( m.maze[1][i] == m.path )
  78. s = s + "#";
  79. else
  80. s = s + " ";
  81. }
  82. assertEquals("| | | |", s);
  83. }
  84.  
  85. // @Test
  86. // public void TestDFS()
  87. // {
  88. // m.traversalJUnits();
  89. // m.contributeMaze();
  90. // m.findPathDFS();
  91. // String s = "";
  92. // for (int i=0; i<2*4+1; i++) {
  93. // if ( m.maze[m.maze.length-2][i] == m.corner )
  94. // s = s + "+";
  95. // else if ( m.maze[m.maze.length-2][i] == m.vWall )
  96. // s = s + "|";
  97. // else if ( m.maze[m.maze.length-2][i] == m.hWall )
  98. // s = s + "-";
  99. // else if ( m.maze[m.maze.length-2][i] == m.path )
  100. // s = s + "#";
  101. // else
  102. // s = s + " ";
  103. // }
  104. // assertEquals("|###|###|", s);
  105. // }
  106.  
  107. @Test
  108. public void TestBFS()
  109. {
  110. m.traversalJUnits();
  111. m.contributeMaze();
  112. m.findPathBFS();
  113. String s = "";
  114. for (int i=0; i<2*4+1; i++) {
  115. if ( m.maze[m.maze.length-2][i] == m.corner )
  116. s = s + "+";
  117. else if ( m.maze[m.maze.length-2][i] == m.vWall )
  118. s = s + "|";
  119. else if ( m.maze[m.maze.length-2][i] == m.hWall )
  120. s = s + "-";
  121. else if ( m.maze[m.maze.length-2][i] == m.path )
  122. s = s + "#";
  123. else
  124. s = s + " ";
  125. }
  126. assertEquals("|###|###|", s);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement