|
@ -6,15 +6,21 @@ 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.Collection; |
|
|
|
|
|
import java.util.Iterator; |
|
|
import java.util.stream.Stream; |
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
public class GameboardTest { |
|
|
public class GameboardTest { |
|
|
|
|
|
|
|
|
private Gameboard gb; |
|
|
private Gameboard gb; |
|
|
|
|
|
private Game g; |
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setup() { |
|
|
void setup() { |
|
|
gb = new Gameboard(); |
|
|
gb = new Gameboard(); |
|
|
|
|
|
g = new Game(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
@ -28,9 +34,6 @@ public class GameboardTest { |
|
|
@Test |
|
|
@Test |
|
|
void checkGameboardFilled() { |
|
|
void checkGameboardFilled() { |
|
|
int[] expectedGameboard = new int[56]; |
|
|
int[] expectedGameboard = new int[56]; |
|
|
for(int i = 0; i < expectedGameboard.length; i++) { |
|
|
|
|
|
expectedGameboard[i] = 0; |
|
|
|
|
|
} |
|
|
|
|
|
int [] givenGameboard = gb.board; |
|
|
int [] givenGameboard = gb.board; |
|
|
|
|
|
|
|
|
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); |
|
|
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); |
|
@ -60,16 +63,66 @@ public class GameboardTest { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void checkPrintGameboard() { |
|
|
|
|
|
String expectedResult = "[1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + |
|
|
|
|
|
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + |
|
|
|
|
|
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + |
|
|
|
|
|
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + |
|
|
|
|
|
"3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]"; |
|
|
|
|
|
gb.initGameboard(); |
|
|
|
|
|
String calculatedResult = gb.toString(); |
|
|
|
|
|
assertThat(calculatedResult).describedAs("Print Gameboard").isEqualTo(expectedResult); |
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@MethodSource("FiguresOnBoardData") |
|
|
|
|
|
void checkGetFiguresOnBoard (String testname, ArrayList<Integer> positions, String[] expectedResult) { |
|
|
|
|
|
Iterator<Player> pIt = g.players.iterator(); |
|
|
|
|
|
Iterator<Integer> posIt = positions.iterator(); |
|
|
|
|
|
while(pIt.hasNext()) { |
|
|
|
|
|
Player p = pIt.next(); |
|
|
|
|
|
for (Figure f : p.figures) { |
|
|
|
|
|
f.setPosition(posIt.next()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String[] calculatedResult = g.gb.getFiguresOnBoard(g); |
|
|
|
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Stream<Arguments> FiguresOnBoardData () { |
|
|
|
|
|
return Stream.of( |
|
|
|
|
|
Arguments.of( |
|
|
|
|
|
"All Figures in Base", |
|
|
|
|
|
new ArrayList<>(Arrays.asList( |
|
|
|
|
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 |
|
|
|
|
|
)), |
|
|
|
|
|
new String[] { |
|
|
|
|
|
" "," "," "," "," "," "," "," "," "," ", |
|
|
|
|
|
" "," "," "," "," "," "," "," "," "," ", |
|
|
|
|
|
" "," "," "," "," "," "," "," "," "," ", |
|
|
|
|
|
" "," "," "," "," "," "," "," "," "," ", |
|
|
|
|
|
" "," "," "," "," "," "," "," "," "," ", |
|
|
|
|
|
" "," "," "," "," "," ","\u001b[31;1m1\u001b[0m", "\u001b[31;1m2\u001b[0m","\u001b[31;1m3\u001b[0m","\u001b[31;1m4\u001b[0m", |
|
|
|
|
|
"\u001b[34;1m1\u001b[0m","\u001b[34;1m2\u001b[0m","\u001b[34;1m3\u001b[0m","\u001b[34;1m4\u001b[0m","\u001b[33;1m1\u001b[0m","\u001b[33;1m2\u001b[0m","\u001b[33;1m3\u001b[0m","\u001b[33;1m4\u001b[0m","\u001b[32;1m1\u001b[0m","\u001b[32;1m2\u001b[0m", |
|
|
|
|
|
"\u001b[32;1m3\u001b[0m","\u001b[32;1m4\u001b[0m"} |
|
|
|
|
|
), |
|
|
|
|
|
Arguments.of( |
|
|
|
|
|
"Figures on Board", |
|
|
|
|
|
new ArrayList<>(Arrays.asList( |
|
|
|
|
|
0,1,3,5,-1,-1,-1,-1,10,12,16,-1,-1,-1,-1,-1 |
|
|
|
|
|
)), |
|
|
|
|
|
new String[] { |
|
|
|
|
|
"\u001b[31;1m1\u001b[0m","\u001b[31;1m2\u001b[0m"," ","\u001b[31;1m3\u001b[0m", |
|
|
|
|
|
" ","\u001b[31;1m4\u001b[0m"," "," ", |
|
|
|
|
|
" "," ","\u001b[33;1m1\u001b[0m"," ", |
|
|
|
|
|
"\u001b[33;1m2\u001b[0m"," "," "," ", |
|
|
|
|
|
"\u001b[33;1m3\u001b[0m"," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
" "," "," "," ", |
|
|
|
|
|
"\u001b[34;1m1\u001b[0m","\u001b[34;1m2\u001b[0m","\u001b[34;1m3\u001b[0m","\u001b[34;1m4\u001b[0m", |
|
|
|
|
|
" "," "," ","\u001b[33;1m4\u001b[0m", |
|
|
|
|
|
"\u001b[32;1m1\u001b[0m","\u001b[32;1m2\u001b[0m","\u001b[32;1m3\u001b[0m","\u001b[32;1m4\u001b[0m"} |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |