예제 #1
0
  /**
   * Tests the deleteVertical method, by making a nice board with vertical combinations of 5,4 and 3
   * Gems and checking if the method finds those combinations.
   */
  @Test
  public final void testDeleteVertical() {
    board = new Board(5, 0, 0, false);
    gems = board.getGems();
    for (int col = 0; col < 5; col++) {
      for (int row = 0; row < 5 - col; row++) {
        gems[row][col].setType(1);
      }
    }
    gems[4][1].setType(2);
    gems[3][2].setType(2);
    gems[4][2].setType(2);
    ArrayList<Gem> array1 = new ArrayList<Gem>();
    array1.add(gems[1][0]);
    array1.add(gems[2][0]);
    array1.add(gems[3][0]);
    array1.add(gems[4][0]);
    ArrayList<Gem> array2 = board.deleteVertical(gems[0][0]);
    assertEquals(array1, array2);

    ArrayList<Gem> array3 = new ArrayList<Gem>();
    array3.add(gems[1][1]);
    array3.add(gems[0][1]);
    array3.add(gems[3][1]);
    ArrayList<Gem> array4 = board.deleteVertical(gems[2][1]);
    assertEquals(array3, array4);

    ArrayList<Gem> array5 = new ArrayList<Gem>();
    array5.add(gems[0][2]);
    array5.add(gems[2][2]);
    ArrayList<Gem> array6 = board.deleteVertical(gems[1][2]);
    assertEquals(array5, array6);
  }
예제 #2
0
 /**
  * Tests the setGems and getGems methods, by first setting Gems[][] testgems, and then checking
  * whether it was set with the getGems method.
  */
 @Test
 public final void setGemTest() {
   board = new Board(2, 0, 0, false);
   Gem[][] testgems = new Gem[2][2];
   board.setGems(testgems);
   assertArrayEquals(testgems, board.getGems());
 }
예제 #3
0
 /**
  * Tests the setSecondGem and getSecondGem methods, by first setting a Gem on second and then
  * checking with getSecondGem if it was second.
  */
 @Test
 public final void secondGemTest() {
   board = new Board(2, 0, 0, false);
   gems = board.getGems();
   Gem gem = gems[0][0];
   assertNull(board.getSecondGem());
   board.setSecondGem(gem);
   assertEquals(board.getSecondGem(), gem);
 }
예제 #4
0
 /** Tests the getUpper method by checking if the getUpper method returns the right Gem. */
 @Test
 public final void testGetUpper() {
   board = new Board(2, 0, 0, false);
   gems = board.getGems();
   Gem gem1 = gems[0][0];
   Gem gem2 = gems[0][1];
   Gem gem3 = gems[1][0];
   assertEquals(board.getUpper(gem3), gem1);
   assertFalse(board.getUpper(gem3) == gem2);
 }
예제 #5
0
 /**
  * Tests the colCheck method, by changing some types in a col and checking if the returned boolean
  * is right.
  */
 @Test
 public final void testColCheck() {
   board = new Board(3, 0, 0, false);
   gems = board.getGems();
   gems[0][0].setType(1);
   gems[1][0].setType(1);
   assertFalse(board.colCheck(2, 0, 1));
   gems[0][0].setType(2);
   assertTrue(board.colCheck(2, 0, 1));
 }
예제 #6
0
 /**
  * Tests the rowCheck method, by changing some types in a row and checking if the returned boolean
  * is right.
  */
 @Test
 public final void testRowCheck() {
   board = new Board(3, 0, 0, false);
   gems = board.getGems();
   gems[0][0].setType(1);
   gems[0][1].setType(1);
   assertFalse(board.rowCheck(0, 2, 1));
   gems[0][0].setType(2);
   assertTrue(board.rowCheck(0, 2, 1));
 }
예제 #7
0
 /**
  * Tests the swap method by swapping two gems and checking if their position has changed. Also, it
  * checks whether the gems are not changed if they are not next to each other.
  */
 @Test
 public final void testSwap() {
   board = new Board(2, 0, 0, false);
   assertFalse(board.swap(0, 1, 1, 0));
   gems = board.getGems();
   Gem gem1 = gems[0][0];
   Gem gem2 = gems[0][1];
   assertTrue(board.swap(0, 0, 0, 1));
   assertEquals(gems[0][0], gem2);
   assertEquals(gems[0][1], gem1);
   assertTrue(board.swap(0, 0, 1, 0));
 }
예제 #8
0
 /**
  * Tests the delete method, by deleting a gem and checking if it has disappeared and if the other
  * gems are on the right place.
  */
 @Test
 public final void testDelete() {
   board = new Board(3, 0, 0, false);
   gems = board.getGems();
   gems[0][0].setType(1);
   gems[1][0].setType(1);
   Gem gem1 = gems[0][0];
   Gem gem2 = gems[1][0];
   board.delete(2, 0);
   assertEquals(gems[2][0], gem2);
   assertEquals(gems[1][0], gem1);
 }
예제 #9
0
 /**
  * Tests the fillBoard method, it check for every place on the board if there is a Gem with a type
  * from 1 to 6.
  */
 @Test
 public final void testFillBoardIntInt() {
   board = new Board(3, 0, 0, false);
   board.fillBoard(0, 0);
   gems = board.getGems();
   for (int row = 0; row < 3; row++) {
     for (int col = 0; col < 3; col++) {
       assertTrue(1 <= gems[row][col].getType());
       assertTrue(gems[row][col].getType() <= 6);
     }
   }
 }
예제 #10
0
 /**
  * Tests the areNeighbours method, by testing neighbours and also testing Gems that aren't
  * neighbours.
  */
 @Test
 public final void testAreNeighbours() {
   board = new Board(2, 0, 0, false);
   gems = board.getGems();
   Gem gem1 = gems[0][0];
   Gem gem2 = gems[0][1];
   Gem gem3 = gems[1][0];
   Gem gem4 = gems[1][1];
   assertTrue(board.areNeighbours(gem1, gem2));
   assertTrue(board.areNeighbours(gem1, gem3));
   assertFalse(board.areNeighbours(gem1, gem4));
 }
예제 #11
0
 /**
  * Tests the deleteRows method by setting up some combinations and testing whether the method
  * finds them.
  */
 @Test
 public final void testDeleteRows() {
   board = new Board(3, 0, 0, false);
   gems = board.getGems();
   gems[0][0].setType(1);
   gems[0][1].setType(1);
   gems[0][2].setType(1);
   assertTrue(board.deleteRows(gems[0][0]) > 0);
   gems[0][1].setType(2);
   gems[1][0].setType(2);
   gems[0][0].setType(1);
   assertTrue(board.deleteRows(gems[0][0]) == 0);
 }
예제 #12
0
 /**
  * Tests the deleteAll method, by filling an ArrayList with gems and checking if those gems have
  * been deleted.
  */
 @Test
 public final void testDeleteAll() {
   board = new Board(3, 0, 0, false);
   gems = board.getGems();
   ArrayList<Gem> array = new ArrayList<Gem>();
   Gem gem1 = gems[0][0];
   Gem gem2 = gems[1][0];
   Gem gem3 = gems[2][0];
   array.add(gem3);
   array.add(gem1);
   array.add(gem2);
   board.deleteAll(array);
   assertFalse(gem1 == gems[0][0]);
   assertFalse(gem2 == gems[1][0]);
   assertFalse(gem3 == gems[2][0]);
   assertFalse(gem2 == gems[2][0]);
 }