1 | package jpacman.model; |
2 | |
3 | import static org.junit.Assert.assertEquals; |
4 | import static org.junit.Assert.assertNotSame; |
5 | import static org.junit.Assert.assertNull; |
6 | |
7 | import java.util.Vector; |
8 | |
9 | import org.junit.Test; |
10 | |
11 | /** |
12 | * Series of test cases for the game itself. |
13 | * It makes use of the GameTestCase fixture, which |
14 | * contains a simple board. |
15 | * @author Arie van Deursen, 2007 |
16 | * @version $Id: GameTest.java,v 1.7 2008/02/10 19:28:20 arie Exp $ |
17 | * |
18 | */ |
19 | public class GameTest extends GameTestCase { |
20 | |
21 | /** |
22 | * Is each list of monsters a fresh one? |
23 | */ |
24 | @Test |
25 | public void testGetMonsters() { |
26 | assertEquals(2, theGame.getMonsters().size()); |
27 | // each call to getMonsters should deliver a fresh copy. |
28 | Vector<Monster> ms1 = theGame.getMonsters(); |
29 | Vector<Monster> ms2 = theGame.getMonsters(); |
30 | assertNotSame(ms1, ms2); |
31 | } |
32 | |
33 | /** |
34 | * Are the dx/dy in the player correctly set after moving |
35 | * the player around? |
36 | */ |
37 | @Test |
38 | public void testDxDyPossibleMove() { |
39 | // start dx/dy should be zero. |
40 | assertEquals(0, theGame.getPlayerLastDx()); |
41 | assertEquals(0, theGame.getPlayerLastDy()); |
42 | // move to left empty cell -- dx should have beeen adjusted. |
43 | theGame.movePlayer(1, 0); |
44 | assertEquals(1, theGame.getPlayerLastDx()); |
45 | assertEquals(0, theGame.getPlayerLastDy()); |
46 | // move to up empty cell -- dy should have been adjusted. |
47 | theGame.movePlayer(0, -1); |
48 | assertEquals(0, theGame.getPlayerLastDx()); |
49 | assertEquals(-1, theGame.getPlayerLastDy()); |
50 | } |
51 | |
52 | /** |
53 | * Do the player dx/dy remain unaltered if a move fails? |
54 | */ |
55 | @Test |
56 | public void testDxDyImpossibleMove() { |
57 | // start dx/dy should be zero. |
58 | assertEquals(0, theGame.getPlayerLastDx()); |
59 | assertEquals(0, theGame.getPlayerLastDy()); |
60 | // move to a wallcell -- dxdy should have been adjusted. |
61 | theGame.movePlayer(0, -1); |
62 | assertEquals(0, theGame.getPlayerLastDx()); |
63 | assertEquals(-1, theGame.getPlayerLastDy()); |
64 | } |
65 | |
66 | } |