Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static javafx.scene.paint.Color.*;
import static org.assertj.core.api.Assertions.assertThat;
class FloodGameTest {
private final int totalNumberOfCells = 6;
private final Grid gridTwoThree = new ArrayGrid(2,3);
private final Color colorONE = RED;
private final Color colorTWO = BLUE;
private FloodGame game;
private final Player playerONE = new ComputerPlayer("player1", gridTwoThree.getCell(0, 0), startCell -> colorONE);
private final Player playerTWO = new ComputerPlayer("player2", gridTwoThree.getCell(1, 2), startCell -> colorTWO);
@BeforeEach
private void initGame(){
game = new FloodGame(totalNumberOfCells);
}
@Test
void testSetTurnAndGetTurn() {
assertThat(game.getTurn()).isEqualTo(0);
game.setTurn(100);
assertThat(game.getTurn()).isEqualTo(100);
}
@Test
void testResetTurn() {
game.setTurn(100);
game.resetTurn();
assertThat(game.getTurn()).isEqualTo(0);
}
@Test
void testIncrementTurn() {
game.incrementTurn();
game.incrementTurn();
assertThat(game.getTurn()).isEqualTo(2);
}
@Test
void testGetPlayer() {
game.setPlayer(playerONE);
game.setPlayer(playerTWO);
assertThat(game.getPlayer()).isEqualTo(playerTWO);
game.incrementTurn();
assertThat(game.getPlayer()).isEqualTo(playerTWO);
}
@Test
void testIsHumanTurn() {
game.setPlayer(new HumanPlayer("human",gridTwoThree.getCell(1,2)));
assertThat(game.isHumanTurn()).isTrue();
game.setPlayer(playerONE);
assertThat(game.isHumanTurn()).isFalse();
}
private void fillGridYellow(Grid grid){
for(Cell cell: grid)
cell.setColor(YELLOW);
}
@Test
void testHasWon() {
game.setPlayer(playerONE);
gridTwoThree.getCell(0,0).setColor(RED);
gridTwoThree.getCell(1,1).setColor(BLUE);
assertThat(game.hasWon(game.getPlayer())).isFalse();
fillGridYellow(gridTwoThree);
assertThat(game.hasWon(game.getPlayer())).isTrue();
}
@Test
void testHasEnded() {
game.setPlayer(playerONE);
gridTwoThree.getCell(1,2).setColor(RED);
gridTwoThree.getCell(0,1).setColor(YELLOW);
assertThat(game.hasEnded()).isFalse();
fillGridYellow(gridTwoThree);
assertThat(game.hasEnded()).isTrue();
}
}