Commit e60d8e20 authored by Stefano Cobelli's avatar Stefano Cobelli

Merge branch 'MattsBranch' of git@gitlab.bucknell.edu:sjc032/205_hw02.git into MattsBranch

parents 4df4606e 48fb94c0
/**
* CSCI 205 - Software Design and Engineering
* Name(s): Matt Tower
*
* Work: hw02
* Created: Nov 14, 2014, 4:27:48 PM
*/
package model.player;
import static org.junit.Assert.assertTrue;
import model.Game;
import model.Mark;
import org.junit.Test;
/**
* @author mjt023
*
* This is the BlockerPlayerTest class that tests the BlockerPlayer
* class.
*/
public class BlockerPlayerTest {
/** a game instance */
private Game theGame;
/** a blocker player instance */
private BlockerPlayer blockerPlayer;
/**
* tests the decideMove() method
*/
@Test
public void decideMoveTest() {
theGame = new Game(3);
blockerPlayer = new BlockerPlayer(theGame.getBoard(), Mark.O);
// test for horizontal win
theGame.getBoard().setMark(0, 0, Mark.X);
theGame.getBoard().setMark(0, 1, Mark.X);
blockerPlayer.decideMove();
assertTrue(theGame.getBoard().getMark(0, 2) == Mark.O);
theGame.getBoard().clear();
// test for diagonal win
theGame.getBoard().setMark(0, 0, Mark.X);
theGame.getBoard().setMark(2, 2, Mark.X);
blockerPlayer.decideMove();
assertTrue(theGame.getBoard().getMark(1, 1) == Mark.O);
theGame.getBoard().clear();
// test for vertical win
theGame.getBoard().setMark(0, 0, Mark.X);
theGame.getBoard().setMark(2, 0, Mark.X);
blockerPlayer.decideMove();
assertTrue(theGame.getBoard().getMark(1, 0) == Mark.O);
}
}
/**
* CSCI 205 - Software Design and Engineering
* Name(s): Matt Tower
*
* Work: hw02
* Created: Nov 11, 2014, 8:18:37 PM
*/
package model.player;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import model.Board;
import model.Mark;
import org.junit.Before;
import org.junit.Test;
/**
* @author mjt023
*
*/
public class RandomPlayerTest {
/** a board instance */
private Board theBoard;
/** a RandomPlayer instance */
private RandomPlayer randPlayer;
/** size of the board */
private int size;
@Before
public void before() {
theBoard = new Board(size);
randPlayer = new RandomPlayer(theBoard, Mark.X);
size = 3;
theBoard.setMark(0, 0, Mark.O);
theBoard.setMark(0, 1, Mark.X);
theBoard.setMark(0, 2, Mark.O);
theBoard.setMark(1, 0, Mark.X);
theBoard.setMark(1, 1, Mark.O);
}
/**
* tests the decideMove() method
*/
@Test
public void decideMoveTest() {
for (int i = 0; i < 200; i++) {
randPlayer.decideMove();
}
assertTrue(randPlayer.decideMove());
assertTrue(randPlayer.decideMove());
assertTrue(randPlayer.decideMove());
assertTrue(randPlayer.decideMove());
assertFalse(randPlayer.decideMove());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment