|
@ -6,6 +6,7 @@ import org.junit.jupiter.params.ParameterizedTest; |
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
import java.util.Collection; |
|
|
import java.util.Collection; |
|
|
import java.util.Iterator; |
|
|
import java.util.Iterator; |
|
@ -36,9 +37,10 @@ public class PlayerTest { |
|
|
@Test |
|
|
@Test |
|
|
void checkStartPositionOfFigures() { |
|
|
void checkStartPositionOfFigures() { |
|
|
int expectedResult = -1; |
|
|
int expectedResult = -1; |
|
|
int calculatedResult = p.figures[0].position; |
|
|
|
|
|
for(int i = 0; i < 4; i++) { |
|
|
|
|
|
calculatedResult = p.figures[i].position; |
|
|
|
|
|
|
|
|
Iterator<Figure> it = p.figures.iterator(); |
|
|
|
|
|
int calculatedResult = it.next().position; |
|
|
|
|
|
while(it.hasNext()) { |
|
|
|
|
|
calculatedResult = it.next().position; |
|
|
if(expectedResult != calculatedResult) { |
|
|
if(expectedResult != calculatedResult) { |
|
|
calculatedResult = 1; |
|
|
calculatedResult = 1; |
|
|
break; |
|
|
break; |
|
@ -48,59 +50,126 @@ public class PlayerTest { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
@ParameterizedTest |
|
|
@MethodSource("FieldStream") |
|
|
|
|
|
void checkGameWin(String testname, Collection<Figure> figures, Collection<Integer> positions, boolean expectedResult) { |
|
|
|
|
|
|
|
|
@MethodSource("GameWinTestData") |
|
|
|
|
|
void checkGameWin(String testname, ArrayList<Figure> figures, Collection<Integer> positions, boolean expectedResult) { |
|
|
Iterator<Figure> it = figures.iterator(); |
|
|
Iterator<Figure> it = figures.iterator(); |
|
|
Iterator<Integer> it2 = positions.iterator(); |
|
|
Iterator<Integer> it2 = positions.iterator(); |
|
|
for(;it.hasNext();) { |
|
|
|
|
|
|
|
|
while(it.hasNext()) { |
|
|
it.next().setPosition(it2.next()); |
|
|
it.next().setPosition(it2.next()); |
|
|
} |
|
|
} |
|
|
boolean calculatedResult = p.checkGameWin(figures); |
|
|
boolean calculatedResult = p.checkGameWin(figures); |
|
|
assertThat(calculatedResult).describedAs("Check Win").isEqualTo(expectedResult); |
|
|
|
|
|
|
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Stream<Arguments> FieldStream() { |
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@MethodSource("BaseTestData") |
|
|
|
|
|
void checkFigureInBase(String testname, ArrayList<Figure> figures, Collection<Integer> positions, boolean expectedResult) { |
|
|
|
|
|
Iterator<Figure> it = figures.iterator(); |
|
|
|
|
|
Iterator<Integer> it2 = positions.iterator(); |
|
|
|
|
|
while(it.hasNext()) { |
|
|
|
|
|
it.next().setPosition(it2.next()); |
|
|
|
|
|
} |
|
|
|
|
|
boolean calculatedResult = p.checkFigureInBase(figures); |
|
|
|
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Stream<Arguments> GameWinTestData() { |
|
|
return Stream.of( |
|
|
return Stream.of( |
|
|
Arguments.of("No Figure in House", |
|
|
|
|
|
|
|
|
Arguments.of("No Figures in House", |
|
|
|
|
|
new ArrayList<>( |
|
|
Arrays.asList( |
|
|
Arrays.asList( |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure()), |
|
|
|
|
|
Arrays.asList(-1, -1, -1, -1), |
|
|
|
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(-1, -1, -1, -1), |
|
|
false), |
|
|
false), |
|
|
Arguments.of("One Figure in House", |
|
|
Arguments.of("One Figure in House", |
|
|
|
|
|
new ArrayList<>( |
|
|
Arrays.asList( |
|
|
Arrays.asList( |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure()), |
|
|
|
|
|
Arrays.asList(40, -1, -1, -1), |
|
|
|
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, -1, -1, -1), |
|
|
false), |
|
|
false), |
|
|
Arguments.of("Two Figure in House", |
|
|
|
|
|
|
|
|
Arguments.of("Two Figures in House", |
|
|
|
|
|
new ArrayList<>( |
|
|
Arrays.asList( |
|
|
Arrays.asList( |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure()), |
|
|
|
|
|
Arrays.asList(40, 41, -1, -1), |
|
|
|
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, -1, -1), |
|
|
false), |
|
|
false), |
|
|
Arguments.of("Three Figure in House", |
|
|
|
|
|
|
|
|
Arguments.of("Three Figures in House", |
|
|
|
|
|
new ArrayList<>( |
|
|
Arrays.asList( |
|
|
Arrays.asList( |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure()), |
|
|
|
|
|
Arrays.asList(40, 41, 42, -1), |
|
|
|
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, 42, -1), |
|
|
false), |
|
|
false), |
|
|
Arguments.of("Four Figure in House", |
|
|
|
|
|
|
|
|
Arguments.of("Four Figures in House", |
|
|
|
|
|
new ArrayList<>( |
|
|
Arrays.asList( |
|
|
Arrays.asList( |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure(), |
|
|
new Figure()), |
|
|
|
|
|
Arrays.asList(40, 41, 42, 43), |
|
|
|
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, 42, 43), |
|
|
true) |
|
|
true) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Stream<Arguments> BaseTestData() { |
|
|
|
|
|
return Stream.of( |
|
|
|
|
|
Arguments.of("Four Figures in Base", |
|
|
|
|
|
new ArrayList<>( |
|
|
|
|
|
Arrays.asList( |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(-1, -1, -1, -1), |
|
|
|
|
|
true), |
|
|
|
|
|
Arguments.of("Three Figures in Base", |
|
|
|
|
|
new ArrayList<>( |
|
|
|
|
|
Arrays.asList( |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, -1, -1, -1), |
|
|
|
|
|
true), |
|
|
|
|
|
Arguments.of("Two Figures in Base", |
|
|
|
|
|
new ArrayList<>( |
|
|
|
|
|
Arrays.asList( |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, -1, -1), |
|
|
|
|
|
true), |
|
|
|
|
|
Arguments.of("One Figure in Base", |
|
|
|
|
|
new ArrayList<>( |
|
|
|
|
|
Arrays.asList( |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, 42, -1), |
|
|
|
|
|
true), |
|
|
|
|
|
Arguments.of("No Figures in Base", |
|
|
|
|
|
new ArrayList<>( |
|
|
|
|
|
Arrays.asList( |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure(), |
|
|
|
|
|
new Figure()) |
|
|
|
|
|
), Arrays.asList(40, 41, 42, 43), |
|
|
|
|
|
false) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |