|
|
@ -3,25 +3,26 @@ import model.InputChecker;
|
|
|
|
import model.Player;
|
|
|
|
import model.Player;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
|
public class InputCheckerTests {
|
|
|
|
public class InputCheckerTests {
|
|
|
|
public static Stream<Object[]> validIndexTestData() {
|
|
|
|
public static Stream<Arguments> validIndexTestData() {
|
|
|
|
int val = RandomSingleton.get.nextInt();
|
|
|
|
int val = RandomSingleton.get.nextInt();
|
|
|
|
boolean isValid = val >= 1 && val <= 9;
|
|
|
|
boolean isValid = val >= 1 && val <= 9;
|
|
|
|
return Stream.of(
|
|
|
|
return Stream.of(
|
|
|
|
new Object[]{1, true},
|
|
|
|
Arguments.of(1, true),
|
|
|
|
new Object[]{9, true},
|
|
|
|
Arguments.of(1, true),
|
|
|
|
new Object[]{-3, false},
|
|
|
|
Arguments.of(-3, false),
|
|
|
|
new Object[]{15, false},
|
|
|
|
Arguments.of(15, false),
|
|
|
|
new Object[]{val, isValid}
|
|
|
|
Arguments.of(val, isValid)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Stream<Object[]> boxOccupiedTestData() {
|
|
|
|
public static Stream<Arguments> boxOccupiedTestData() {
|
|
|
|
Board b = randomBoard();
|
|
|
|
Board b = randomBoard();
|
|
|
|
int index = RandomSingleton.get.nextInt(9) + 1;
|
|
|
|
int index = RandomSingleton.get.nextInt(9) + 1;
|
|
|
|
boolean isValid = true;
|
|
|
|
boolean isValid = true;
|
|
|
@ -32,12 +33,12 @@ public class InputCheckerTests {
|
|
|
|
isValid = false;
|
|
|
|
isValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
return Stream.of(
|
|
|
|
return Stream.of(
|
|
|
|
new Object[]{new Board(), 1, true},
|
|
|
|
Arguments.of(new Board(), 1, true),
|
|
|
|
new Object[]{fullBoard(), 1, false},
|
|
|
|
Arguments.of(fullBoard(), 1, false),
|
|
|
|
new Object[]{topLeftBoard(), 1, false},
|
|
|
|
Arguments.of(topLeftBoard(), 1, false),
|
|
|
|
new Object[]{topLeftBoard(), 3, true},
|
|
|
|
Arguments.of(topLeftBoard(), 3, true),
|
|
|
|
new Object[]{b, index, isValid}
|
|
|
|
Arguments.of(b, index, isValid
|
|
|
|
);
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Board fullBoard(){
|
|
|
|
private static Board fullBoard(){
|
|
|
@ -71,20 +72,15 @@ public class InputCheckerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
@ParameterizedTest
|
|
|
|
@MethodSource("validIndexTestData")
|
|
|
|
@MethodSource("validIndexTestData")
|
|
|
|
public void validIndexTest(Object[] args){
|
|
|
|
public void validIndexTest(int val,boolean expected){
|
|
|
|
Board b = new Board();
|
|
|
|
Board b = new Board();
|
|
|
|
int val = (int) args[0];
|
|
|
|
boolean actual = new InputChecker().isInputValid(b, val);
|
|
|
|
boolean expected = (boolean) args[1];
|
|
|
|
Assertions.assertEquals(expected, actual);
|
|
|
|
boolean actual = new InputChecker().isInputValid(b, val);
|
|
|
|
|
|
|
|
Assertions.assertEquals(expected, actual);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
@ParameterizedTest
|
|
|
|
@MethodSource("boxOccupiedTestData")
|
|
|
|
@MethodSource("boxOccupiedTestData")
|
|
|
|
public void boxOccupiedTest(Object[] args){
|
|
|
|
public void boxOccupiedTest(Board b, int input, boolean expected){
|
|
|
|
Board b = (Board) args[0];
|
|
|
|
|
|
|
|
int input = (int) args[1];
|
|
|
|
|
|
|
|
boolean expected = (boolean) args[2];
|
|
|
|
|
|
|
|
boolean actual = new InputChecker().isInputValid(b, input);
|
|
|
|
boolean actual = new InputChecker().isInputValid(b, input);
|
|
|
|
Assertions.assertEquals(expected, actual);
|
|
|
|
Assertions.assertEquals(expected, actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|