Java Reference
In-Depth Information
45.
for
(
int
r=0; r < noOfRows; r++){
46.
for
(
int
c=0; c < noOfCols; c++){
47.
if
(
this
.board[r][c] != conf.board[r][c]){
48.
result =
false
;
49.
}//
if
50.
}//
for c
51.
}//
for r
52.
return
(result);
53.
}
54.
}
Class constants define constants for the possible directions of the moves.
File:
its/BlockPuzzle/Constants.java
package
its.BlockPuzzle;
1.
2.
3.
4.
public
class Constants {
5.
6.
public static final int
DIRECTION_UP
= 1;
7.
public static final int
DIRECTION_DOWN = 2;
8.
public static final int
DIRECTION_RIGHT = 3;
9.
public static final int
DIRECTION_LEFT = 4;
10.
}
The test of the model is done by class
BlockPuzzleTest
.Itconstructs a 4
4
board, fetches the initial configuration of the board and prints it. Then two moves
are generated and executed. The first one is legal but the second one is not. A
thorough test should of course check more situations, such as attempting to move
a block off the board or whether there are two blocks with the same number. The
test is performed by comparing the true and expected configurations.
×
File:
its/BlockPuzzle/BlockPuzzleTest.java
1.
package
its.BlockPuzzle;
2.
3.
4.
public class
BlockPuzzleTest{
5.
6.
private static
boolean passed;
7.
8.
public static void
main(String[] args){
Search WWH ::
Custom Search