五子棋落子游戏 (七)

2014-11-24 11:10:37 · 作者: · 浏览: 2
t[] { 6, 6 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 9, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 7, 7 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 2, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 4, 4 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 5, 3 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 5, 5 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 7, 6 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 8, 8 }), BLACK_WIN);

assertEquals(game.startGame(BLACK, new int[] { 4, 6 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 9, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 6, 4 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 2, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 7, 3 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 5, 3 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 5, 5 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 8, 9 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 8, 2 }), BLACK_WIN);
}

/**
* CASE2:参数非法
*/
@Test
public void testStartGame2()
{
assertEquals(game.startGame(BLACK, new int[] { 4 }), FAIL);
assertEquals(game.startGame(BLACK, new int[] { 4, -1 }), FAIL);
assertEquals(game.startGame(BLACK, new int[] { -1, 4 }), FAIL);
assertEquals(game.startGame(BLACK, new int[] { 7, 15 }), FAIL);
}

/**
* CASE3:重复落子、顺序不对
*/
@Test
public void testStartGame3()
{
assertEquals(game.startGame(BLACK, new int[] { 4, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 10, 4 }), FAIL);
assertEquals(game.startGame(WHITE, new int[] { 4, 4 }), FAIL);

assertEquals(game.startGame(WHITE, new int[] { 5, 3 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 4, 5 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 7, 6 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 4, 6 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 9, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 4, 7 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 2, 4 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 4, 8 }), BLACK_WIN);
}
}

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
*
* 类名称:ChessGameTest 类描述: 创建人:dobuy
*
*/
public class ChessGameTest
{
private static ChessGame game = new ChessGame();

/**
* 落子成功
*/
int SUCCESS = 1;

/**
* 落子失败:顺序不对、位置非法、指定棋手非法
*/
int FAIL = -1;

/**
* 黑子赢
*/
int BLACK_WIN = 2;

/**
* 白子赢
*/
int WHITE_WIN = 3;

/**
* 黑子
*/
int BLACK = 0;

/**
* 白子
*/
int WHITE = 1;

/**
* CASE1:正常流程
*/
@Test
public void testStartGame1()
{
// 2条直线
assertEquals(game.startGame(BLACK, new int[] { 4, 4 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 5, 3 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 5, 4 }), SUCCESS);
assertEquals(game.startGame(WHITE, new int[] { 7, 6 }), SUCCESS);
assertEquals(game.startGame(BLACK, new int[] { 6, 4 }), S