import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class TestForza4 { final char[][] board1 = {{'X', ' ', ' ', ' '}, {'O', 'O', 'O', ' '}}; char[][] deepCopy(char[][] a) { char[][] result = new char[a.length][]; for (int i = 0; i < a.length; i++) result[i] = a[i].clone(); return result; } @Test void testCreateBoard() { char[][] result = {{' ', ' ', ' '}, {' ', ' ', ' '}}; assertArrayEquals(result, Forza4.createEmptyBoard(2, 3)); } @Test void testCheckMove() { assertFalse(Forza4.checkMove(board1, -1)); assertFalse(Forza4.checkMove(board1, 4)); assertTrue(Forza4.checkMove(board1, 1)); assertFalse(Forza4.checkMove(board1, 0)); } @Test void testMove() { var board = deepCopy(board1); Forza4.move(board, 1, 'X'); assertArrayEquals(new char[][] {{'X', 'X', ' ', ' '}, {'O', 'O', 'O', ' '}}, board); board = deepCopy(board1); Forza4.move(board, 3, 'X'); assertArrayEquals(new char[][] {{'X', ' ', ' ', ' '}, {'O', 'O', 'O', 'X'}}, board); board = deepCopy(board1); Forza4.move(board, 3, 'O'); assertArrayEquals(new char[][] {{'X', ' ', ' ', ' '}, {'O', 'O', 'O', 'O'}}, board); } @Test void testNextPlayer() { assertEquals('X', Forza4.nextPlayer('O')); assertEquals('O', Forza4.nextPlayer('X')); } }