Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Board b;
- Piece pyr1, pyr2, pyr3, pyr4, s, sRotated, stick, box;
- // This shows how to build things in setUp() to re-use
- // across tests.
- // In this case, setUp() makes shapes,
- // and also a 3X6 board, with pyr placed at the bottom,
- // ready to be used by tests.
- @Before
- public void setUp() throws Exception {
- b = new Board(3, 6);
- pyr1 = new Piece(Piece.PYRAMID_STR);
- pyr2 = pyr1.computeNextRotation();
- pyr3 = pyr2.computeNextRotation();
- pyr4 = pyr3.computeNextRotation();
- stick = new Piece(Piece.STICK_STR);
- box = new Piece(Piece.SQUARE_STR);
- s = new Piece(Piece.S1_STR);
- sRotated = s.computeNextRotation();
- b.place(pyr1, 0, 0);
- }
- // Check the basic width/height/max after the one placement
- @Test
- public void testSample1() {
- assertEquals(1, b.getColumnHeight(0));
- assertEquals(2, b.getColumnHeight(1));
- assertEquals(2, b.getMaxHeight());
- assertEquals(3, b.getRowWidth(0));
- assertEquals(1, b.getRowWidth(1));
- assertEquals(0, b.getRowWidth(2));
- }
- // Place sRotated into the board, then check some measures
- @Test
- public void testSample2() {
- b.commit();
- int result = b.place(sRotated, 1, 1);
- assertEquals(Board.PLACE_OK, result);
- assertEquals(1, b.getColumnHeight(0));
- assertEquals(4, b.getColumnHeight(1));
- assertEquals(3, b.getColumnHeight(2));
- assertEquals(4, b.getMaxHeight());
- // clear row test and undo
- // assertEquals(1,b.clearRows());
- b.undo();
- assertEquals(1, b.getColumnHeight(0));
- assertEquals(2, b.getColumnHeight(1));
- assertEquals(2, b.getMaxHeight());
- assertEquals(3, b.getRowWidth(0));
- assertEquals(1, b.getRowWidth(1));
- assertEquals(0, b.getRowWidth(2));
- }
- @Test
- public void getGridTest(){
- assertTrue(b.getGrid(0, 0));
- assertFalse(b.getGrid(1,3));
- assertTrue(b.getGrid(100, 100));
- assertTrue(b.getGrid(-3, -11));//out of bounds
- assertTrue(b.getGrid(3, -11));
- assertTrue(b.getGrid(2, 6));
- }
- @Test
- public void justMore(){
- b.commit();
- assertEquals(b.PLACE_ROW_FILLED, b.place(pyr1, 0, 2));
- assertEquals(3, b.getColumnHeight(0));
- assertEquals(4, b.getColumnHeight(1));
- assertEquals(4, b.getMaxHeight());
- assertEquals(3, b.getRowWidth(0));
- assertEquals(1, b.getRowWidth(1));
- assertEquals(3, b.getRowWidth(2));
- assertEquals(1, b.getRowWidth(3));
- assertEquals(0, b.getRowWidth(4));
- //clearing
- assertEquals(2,b.clearRows());
- assertEquals(0, b.getColumnHeight(0));
- assertEquals(2, b.getColumnHeight(1));
- assertEquals(0, b.getColumnHeight(2));
- assertEquals(1, b.getRowWidth(1));
- assertEquals(1, b.getRowWidth(0));
- assertEquals(0, b.getRowWidth(2));
- assertEquals(2, b.getMaxHeight());
- }
- @Test
- public void fullClear(){
- b = new Board(3,4);
- assertEquals(b.PLACE_OK,b.place(box, 0, 0));
- b.commit();
- assertEquals(b.PLACE_OK,b.place(box, 0,2));
- b.commit();
- assertEquals(b.PLACE_ROW_FILLED, b.place(stick, 2, 0));
- assertEquals(4, b.clearRows());
- b.commit();
- assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 2, 0));
- assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, -2, 0));
- assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 0, -1));
- assertEquals(b.PLACE_OUT_BOUNDS, b.place(box, 2, 3));
- assertEquals(0, b.getColumnHeight(1));
- b.place(box, 0, 0);
- b.commit();
- assertEquals(b.PLACE_BAD, b.place(box, 1, 1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement