View Javadoc
1   /******************************************************************************
2    * TestGameMove.java - Test the GameMove domain object.
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.1  2011/06/15 03:48:51  dick
10   * TestGameMove becomes TestGameEventMove.
11   *
12   * Revision 1.3  2011/06/15 03:46:03  dick
13   * Forgot to test the direction...
14   *
15   * Revision 1.2  2011/06/15 03:38:38  dick
16   * This should give coverage to the entire object.
17   *
18   * Revision 1.1  2011/06/14 23:34:51  dick
19   * Test the GameMove domain object.
20   *
21   */
22  
23  /* 
24   * This program is free software: you can redistribute it and/or modify
25   * it under the terms of the GNU General Public License as published by
26   * the Free Software Foundation, either version 3 of the License, or
27   * (at your option) any later version.
28   *
29   * This program is distributed in the hope that it will be useful,
30   * but WITHOUT ANY WARRANTY; without even the implied warranty of
31   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32   * GNU General Public License for more details.
33   *
34   * You should have received a copy of the GNU General Public License
35   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
36   *
37   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
38   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
39   * 
40   */
41  package com.buckosoft.fibs.domain.gameEvent;
42  
43  import junit.framework.TestCase;
44  
45  import org.junit.Before;
46  import org.junit.Test;
47  
48  import com.buckosoft.fibs.domain.Board;
49  import com.buckosoft.fibs.domain.gameEvent.GameEventMove;
50  
51  /** Test the {@link com.buckosoft.fibs.domain.gameEvent.TestGameEventMove} type of GameEvent
52   * @author Dick Balaska
53   * @since 2011/06/13
54   * @version $Revision$ <br> $Date$
55   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/test/java/com/buckosoft/fibs/test/domain/gameEvent/TestGameEventMove.java">cvs TestGameEventMove.java</a>
56   */
57  public class TestGameEventMove extends TestCase {
58  
59  	/**
60  	 * @throws java.lang.Exception
61  	 */
62  	@Before
63  	public void setUp() throws Exception {
64  	}
65  
66  	private void verify(GameEventMove gm, String playerName, int[] expectedMoves) {
67  		assertEquals(playerName, gm.getPlayerName());
68  		int[] moves = gm.getMoves();
69  		assertNotNull(moves);
70  		assertEquals(expectedMoves.length, moves.length);
71  		for (int i=0; i<expectedMoves.length; i++) {
72  			assertEquals(expectedMoves[i], moves[i]);			
73  		}
74  	}
75  
76  	/**
77  	 * Test method for {@link com.buckosoft.fibs.domain.gameEvent.GameEventMove#getType()}.
78  	 */
79  	@Test
80  	public void testGameMove() {
81  		GameEventMove gm = new GameEventMove();
82  		gm.parse("You move 1-2 3-4 .");
83  		verify(gm, "You", new int[] {1,2,3,4});
84  		gm.parse("You move 5-6 7-8 . ");
85  		verify(gm, "You", new int[] {5,6,7,8});
86  		gm.parse("Bob moves bar-4 bar-3 .");
87  		verify(gm, "Bob", new int[] {Board.Bar, 4, Board.Bar, 3});
88  		gm.parse("Alice moves 2-off .");
89  		verify(gm, "Alice", new int[] {2, Board.Home});
90  		gm.parse("Billy moves 2-x .");
91  		verify(gm, "Billy", new int[] {2, 0});
92  		gm.setDirection(Board.O);
93  		assertEquals(Board.O, gm.getDirection());
94  		gm.setDirection(Board.X);
95  		assertEquals(Board.X, gm.getDirection());
96  	}
97  
98  	@Test
99  	public void testBearingOff() {
100 		GameEventMove gm = new GameEventMove();
101 		gm.parseBearingOff("Bearing off: 6 o 2 o ");
102 		verify(gm, "You", new int[] {6,0,2,0});
103 	}
104 
105 	@Test
106 	public void testBadGameMove() {
107 		GameEventMove gm = new GameEventMove();
108 		boolean b = false;
109 		try {
110 			gm.parse("You move 1");
111 		} catch (RuntimeException ex) {
112 			b = true;
113 		}
114 		assertTrue(b);
115 	}
116 	
117 	@Test
118 	public void testToString() {
119 		GameEventMove gm = new GameEventMove();
120 		gm.parse("You move 1-2 3-4 .");
121 		verify(gm, "You", new int[] {1,2,3,4});
122 		assertEquals("You move 1-2 3-4", gm.toString());
123 	}
124 }