/
BoardTest.java
129 lines (113 loc) · 4.99 KB
/
BoardTest.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package usantatecla.tictactoe.models;
import org.junit.jupiter.api.Test;
import usantatecla.tictactoe.types.Token;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class BoardTest {
private Board board;
public BoardTest() {
this.board = new Board();
}
@Test
public void testGivenNewBoardWhenPutNewTokenIsOccupiedThenIsTrue() {
Token token = Token.values()[0];
Coordinate coordinate = new Coordinate(0, 0);
this.board.put(coordinate, token);
assertThat(this.board.isOccupied(coordinate, token), is(true));
}
@Test
public void testGivenNewBoardWhenPutNewTokenIsOccupiedThenIsFalse() {
Token token = Token.values()[0];
Coordinate coordinate = new Coordinate(0, 0);
assertThat(this.board.isOccupied(coordinate, token), is(false));
}
@Test
public void testGivenNewBoardWhenMoveNewTokenIsOccupiedAndOriginIsEmptyThenIsTrue() {
Token token = Token.values()[0];
Coordinate originCoordinate = new Coordinate(0, 0);
Coordinate coordinateToMove = new Coordinate(0, 1);
this.board.put(originCoordinate, token);
this.board.move(originCoordinate, coordinateToMove);
assertThat(this.board.isEmpty(originCoordinate), is(true));
assertThat(this.board.isOccupied(coordinateToMove, token), is(true));
}
@Test
public void testGivenNewBoardWhenMoveNewTokenIsOccupiedAndOriginIsEmptyThenIsFalse() {
Token token = Token.values()[0];
Coordinate originCoordinate = new Coordinate(0, 0);
Coordinate coordinateToMove = new Coordinate(0, 1);
this.board.put(originCoordinate, token);
this.board.move(originCoordinate, coordinateToMove);
assertThat(this.board.isEmpty(coordinateToMove), is(false));
assertThat(this.board.isOccupied(originCoordinate, token), is(false));
}
@Test//(expected = AssertionError.class)
public void testGivenNewBoardWhenMoveNewTokenTheOriginIsEmptyThenAssertionException() {
Coordinate originCoordinate = new Coordinate(0, 0);
Coordinate coordinateToMove = new Coordinate(0, 1);
this.board.move(originCoordinate, coordinateToMove);
}
@Test
public void testGivenNewBoardWhenPutThreeTokenAndIsTicTacToeThenIsTrue() {
Token token = Token.values()[0];
Coordinate coordinate11 = new Coordinate(0, 0);
Coordinate coordinate12 = new Coordinate(0, 1);
Coordinate coordinate13 = new Coordinate(0, 2);
this.board.put(coordinate11, token);
this.board.put(coordinate12, token);
this.board.put(coordinate13, token);
assertThat(this.board.isTicTacToe(token), is(true));
}
@Test
public void testGivenNewBoardWhenPutTwoTokenAndIsTicTacToeThenIsFalse() {
Token token = Token.values()[0];
Coordinate coordinate11 = new Coordinate(0, 0);
Coordinate coordinate12 = new Coordinate(0, 1);
this.board.put(coordinate11, token);
this.board.put(coordinate12, token);
assertThat(this.board.isTicTacToe(token), is(false));
}
@Test
public void testGivenNewBoardWhenNotPutTokensAndIsTicTacToeThenIsFalse() {
Token token = Token.values()[0];
assertThat(this.board.isTicTacToe(token), is(false));
}
@Test
public void testGivenNewBoardWhenPutSixTokensAndIsCompletedThenIsTrue() {
Token tokenX = Token.values()[0];
Token tokenO = Token.values()[1];
Coordinate coordinate11 = new Coordinate(0, 0);
Coordinate coordinate21 = new Coordinate(1, 0);
Coordinate coordinate12 = new Coordinate(0, 1);
Coordinate coordinate22 = new Coordinate(1, 1);
Coordinate coordinate23 = new Coordinate(1, 2);
Coordinate coordinate33 = new Coordinate(2, 2);
this.board.put(coordinate11, tokenX);
this.board.put(coordinate21, tokenO);
this.board.put(coordinate12, tokenX);
this.board.put(coordinate22, tokenO);
this.board.put(coordinate23, tokenX);
this.board.put(coordinate33, tokenO);
assertThat(this.board.isCompleted(), is(true));
}
@Test
public void testGivenNewBoardWhenPutFiveTokensAndIsCompletedThenIsFalse() {
Token tokenX = Token.values()[0];
Token tokenO = Token.values()[1];
Coordinate coordinate11 = new Coordinate(0, 0);
Coordinate coordinate21 = new Coordinate(1, 0);
Coordinate coordinate12 = new Coordinate(0, 1);
Coordinate coordinate22 = new Coordinate(1, 1);
Coordinate coordinate23 = new Coordinate(1, 2);
this.board.put(coordinate11, tokenX);
this.board.put(coordinate21, tokenO);
this.board.put(coordinate12, tokenX);
this.board.put(coordinate22, tokenO);
this.board.put(coordinate23, tokenX);
assertThat(this.board.isCompleted(), is(false));
}
@Test
public void testGivenNewBoardWhenNotPutTokensAndIsCompletedThenIsFalse() {
assertThat(this.board.isCompleted(), is(false));
}
}