Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. Board b;
  2. Piece pyr1, pyr2, pyr3, pyr4, s, sRotated, stick, box;
  3.  
  4. // This shows how to build things in setUp() to re-use
  5. // across tests.
  6.  
  7. // In this case, setUp() makes shapes,
  8. // and also a 3X6 board, with pyr placed at the bottom,
  9. // ready to be used by tests.
  10. @Before
  11. public void setUp() throws Exception {
  12. b = new Board(3, 6);
  13.  
  14. pyr1 = new Piece(Piece.PYRAMID_STR);
  15. pyr2 = pyr1.computeNextRotation();
  16. pyr3 = pyr2.computeNextRotation();
  17. pyr4 = pyr3.computeNextRotation();
  18. stick = new Piece(Piece.STICK_STR);
  19. box = new Piece(Piece.SQUARE_STR);
  20. s = new Piece(Piece.S1_STR);
  21. sRotated = s.computeNextRotation();
  22.  
  23. b.place(pyr1, 0, 0);
  24. }
  25.  
  26. // Check the basic width/height/max after the one placement
  27. @Test
  28. public void testSample1() {
  29. assertEquals(1, b.getColumnHeight(0));
  30. assertEquals(2, b.getColumnHeight(1));
  31. assertEquals(2, b.getMaxHeight());
  32. assertEquals(3, b.getRowWidth(0));
  33. assertEquals(1, b.getRowWidth(1));
  34. assertEquals(0, b.getRowWidth(2));
  35. }
  36.  
  37. // Place sRotated into the board, then check some measures
  38. @Test
  39. public void testSample2() {
  40. b.commit();
  41. int result = b.place(sRotated, 1, 1);
  42. assertEquals(Board.PLACE_OK, result);
  43. assertEquals(1, b.getColumnHeight(0));
  44. assertEquals(4, b.getColumnHeight(1));
  45. assertEquals(3, b.getColumnHeight(2));
  46. assertEquals(4, b.getMaxHeight());
  47.  
  48. // clear row test and undo
  49.  
  50. // assertEquals(1,b.clearRows());
  51. b.undo();
  52. assertEquals(1, b.getColumnHeight(0));
  53. assertEquals(2, b.getColumnHeight(1));
  54. assertEquals(2, b.getMaxHeight());
  55. assertEquals(3, b.getRowWidth(0));
  56. assertEquals(1, b.getRowWidth(1));
  57. assertEquals(0, b.getRowWidth(2));
  58. }
  59.  
  60. @Test
  61. public void getGridTest(){
  62. assertTrue(b.getGrid(0, 0));
  63. assertFalse(b.getGrid(1,3));
  64.  
  65. assertTrue(b.getGrid(100, 100));
  66. assertTrue(b.getGrid(-3, -11));//out of bounds
  67. assertTrue(b.getGrid(3, -11));
  68. assertTrue(b.getGrid(2, 6));
  69.  
  70. }
  71.  
  72. @Test
  73. public void justMore(){
  74. b.commit();
  75. assertEquals(b.PLACE_ROW_FILLED, b.place(pyr1, 0, 2));
  76. assertEquals(3, b.getColumnHeight(0));
  77. assertEquals(4, b.getColumnHeight(1));
  78. assertEquals(4, b.getMaxHeight());
  79. assertEquals(3, b.getRowWidth(0));
  80. assertEquals(1, b.getRowWidth(1));
  81. assertEquals(3, b.getRowWidth(2));
  82. assertEquals(1, b.getRowWidth(3));
  83. assertEquals(0, b.getRowWidth(4));
  84.  
  85. //clearing
  86. assertEquals(2,b.clearRows());
  87.  
  88. assertEquals(0, b.getColumnHeight(0));
  89. assertEquals(2, b.getColumnHeight(1));
  90. assertEquals(0, b.getColumnHeight(2));
  91. assertEquals(1, b.getRowWidth(1));
  92. assertEquals(1, b.getRowWidth(0));
  93. assertEquals(0, b.getRowWidth(2));
  94. assertEquals(2, b.getMaxHeight());
  95. }
  96.  
  97. @Test
  98. public void fullClear(){
  99. b = new Board(3,4);
  100. assertEquals(b.PLACE_OK,b.place(box, 0, 0));
  101. b.commit();
  102. assertEquals(b.PLACE_OK,b.place(box, 0,2));
  103. b.commit();
  104. assertEquals(b.PLACE_ROW_FILLED, b.place(stick, 2, 0));
  105. assertEquals(4, b.clearRows());
  106.  
  107. b.commit();
  108. assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 2, 0));
  109. assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, -2, 0));
  110. assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 0, -1));
  111. assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 2, 3));
  112.  
  113. assertEquals(0, b.getColumnHeight(1));
  114.  
  115. b.place(box, 0, 0);
  116. b.commit();
  117.  
  118. assertEquals(b.PLACE_BAD, b.place(box, 1, 1));
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement