package pdp.scrabble.test.rack;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import pdp.scrabble.game.Player;
import static org.junit.Assert.fail;
import static pdp.scrabble.Factory.FACTORY;
import pdp.scrabble.Game;
import pdp.scrabble.Language;
public class LetterSwitch {
private static final Game GAME = FACTORY.createGame(Language.init("English"), null);
public LetterSwitch() {
}
@BeforeClass
public static void setUpClass() throws Exception {
GAME.create();
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void switchLettersTester() {
Player player = FACTORY.createPlayer(GAME, "test", 0, false, null);
System.out.println("Before: " + player.getRackLettersName());
try {
player.switchLetters(0, 1);
System.out.println("Normal switch (0, 1): " + player.getRackLettersName());
}
catch (ArrayIndexOutOfBoundsException e) {
fail("ArrayIndexOutOfBoundsException was not expected");
}
try {
player.switchLetters(-1, 0);
fail("ArrayIndexOutOfBoundsException was expected");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Can't switch (-1, 0)");
}
try {
player.switchLetters(-1, -2);
fail("ArrayIndexOutOfBoundsException was expected");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Can't switch (-1, -2)");
}
try {
player.switchLetters(2, 2);
System.out.println("Switch same letters (2, 2): " + player.getRackLettersName());
}
catch (ArrayIndexOutOfBoundsException e) {
fail("ArrayIndexOutOfBoundsException was not expected");
}
try {
player.switchLetters(3, 7);
fail("ArrayIndexOutOfBoundsException was expected");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Can't switch (3, 7)");
}
try {
player.switchLetters(-7, 7);
fail("ArrayIndexOutOfBoundsException was expected");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Can't switch (-1, 2)");
}
}
}