commit
a060c1302e
@ -0,0 +1,10 @@
|
||||
package model;
|
||||
|
||||
public class Board {
|
||||
public void setBox(int column, int row, Player value) {
|
||||
}
|
||||
|
||||
public Player getBox(int column, int row) {
|
||||
return Player.None;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package model;
|
||||
|
||||
public class InputChecker {
|
||||
public boolean isInputValid(Board board, int box) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package model;
|
||||
|
||||
public enum Player {
|
||||
X,
|
||||
O,
|
||||
None
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package model;
|
||||
|
||||
public class WinChecker {
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
import model.Board;
|
||||
import model.InputChecker;
|
||||
import model.Player;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class InputCheckerTests {
|
||||
static Random rng = new Random();
|
||||
|
||||
public static Stream<Object[]> validIndexTestData() {
|
||||
int val = rng.nextInt();
|
||||
boolean isValid = val >= 1 && val <= 9;
|
||||
return Stream.of(
|
||||
new Object[]{1, true},
|
||||
new Object[]{9, true},
|
||||
new Object[]{-3, false},
|
||||
new Object[]{15, false},
|
||||
new Object[]{val, isValid}
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<Object[]> boxOccupiedTestData() {
|
||||
Board b = randomBoard();
|
||||
int index = rng.nextInt(1, 10);
|
||||
boolean isValid = true;
|
||||
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
for (int j = 1; j <= 3; ++j)
|
||||
if (b.getBox(i, j) != Player.None)
|
||||
isValid = false;
|
||||
|
||||
return Stream.of(
|
||||
new Object[]{new Board(), 1, true},
|
||||
new Object[]{fullBoard(), 1, false},
|
||||
new Object[]{topLeftBoard(), 1, false},
|
||||
new Object[]{topLeftBoard(), 3, true},
|
||||
new Object[]{b, index, isValid}
|
||||
);
|
||||
}
|
||||
|
||||
private static Board fullBoard(){
|
||||
Board b = new Board();
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
for (int j = 1; j <= 3; ++j)
|
||||
b.setBox(i, j, Player.X);
|
||||
return b;
|
||||
}
|
||||
|
||||
private static Board topLeftBoard(){
|
||||
Board b = new Board();
|
||||
b.setBox(1, 1, Player.X);
|
||||
return b;
|
||||
}
|
||||
|
||||
private static Board randomBoard(){
|
||||
Player[] vals = Player.values();
|
||||
Board b = new Board();
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
for (int j = 1; j <= 3; ++j)
|
||||
b.setBox(i, j, vals[rng.nextInt(vals.length)]);
|
||||
return b;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("validIndexTestData")
|
||||
public void validIndexTest(Object[] args){
|
||||
Board b = new Board();
|
||||
int val = (int) args[0];
|
||||
boolean expected = (boolean) args[1];
|
||||
boolean actual = new InputChecker().isInputValid(b, val);
|
||||
Assertions.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("boxOccupiedTestData")
|
||||
public void boxOccupiedTest(Object[] args){
|
||||
Board b = (Board) args[0];
|
||||
int input = (int) args[1];
|
||||
boolean expected = (boolean) args[2];
|
||||
boolean actual = new InputChecker().isInputValid(b, input);
|
||||
Assertions.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
public class WinCheckerTests {
|
||||
}
|
Loading…
Reference in new issue