Java Reference
In-Depth Information
9.
passed =
true
;
10.
//
Generate a model and print it (also as string)
11.
BoardModel bm =
new
BoardModel(4,4);
12.
ConfigurationModel trueConf, expectedConf;
13.
trueConf = bm.getCurrentConfiguration();
14.
expectedConf =
new
ConfigurationModel(
new int
[][]
15.
{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}});
16.
check(expectedConf,expectedConf);
17.
18.
//
Make a move
19.
System.out.println("Move 15 right");
20.
MoveModel move1 =
new
MoveModel(Constants.DIRECTION_RIGHT,15);
21.
if
(!bm.moveIt(move1)){
22.
System.out.println("Illegal Move!");
23.
}
24.
trueConf = bm.getCurrentConfiguration();
25.
expectedConf =
new
ConfigurationModel(
new int
[][]
26.
{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,0,15}});
27.
check(expectedConf,expectedConf);
28.
29.
//
Make another move
30.
System.out.println("Move 5 up");
31.
MoveModel move2 =
new
MoveModel(Constants.DIRECTION_UP,5);
32.
if
(!bm.moveIt(move2)){
33.
System.out.println("Illegal Move!");
34.
}
35.
trueConf = bm.getCurrentConfiguration();
36.
expectedConf =
new
ConfigurationModel(
new int
[][]
37.
{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,0,15}});
38.
check(expectedConf,expectedConf);
39.
//
display the test result
40.
if
(passed) {
41.
System.out.println("Test passed");
42.
}
43.
else
{
44.
System.out.println("Test NOT passed");
45.
}
46.
}
47.
private static void
check(ConfigurationModel conf1,
48.
ConfigurationModel conf2){
49.
if
(conf1.equals(conf2)){
50.
System.out.println("Configuration ok:");
51.
System.out.println(conf1.toString());
52.
}
53.
else
{
54.
System.out.println("Expected and true configurations"
55.
+"doNOT match");
Search WWH ::
Custom Search