-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJunitTest.java
More file actions
169 lines (154 loc) · 4.34 KB
/
Copy pathJunitTest.java
File metadata and controls
169 lines (154 loc) · 4.34 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import static org.junit.Assert.*;
import org.junit.Test;
public class JunitTest{
//Test from 1 to 4 check if put works fine for user1
@Test
public void test1() {
int [][] expectedBoard = {{ 1,-1,-1},
{-1,-1,-1},
{-1,-1,-1}};
Board board1 = new Board();
board1.put(1,1,1);
assertArrayEquals(board1.getBoard(),expectedBoard);
}
@Test
public void test2() {
int [][] expectedBoard = {{-1, 1,-1},
{-1,-1,-1},
{-1,-1,-1}};
Board board2 = new Board();
board2.put(1,2,1);
assertArrayEquals(board2.getBoard(),expectedBoard);
}
@Test
public void test3() {
int [][] expectedBoard = {{-1,-1, 1},
{-1,-1,-1},
{-1,-1,-1}};
Board board3 = new Board();
board3.put(1,3,1);
assertArrayEquals(board3.getBoard(),expectedBoard);
}
@Test
public void test4() {
int [][] expectedBoard = {{-1,-1,-1},
{ 1,-1,-1},
{-1,-1,-1}};
Board board4 = new Board();
board4.put(2,1,1);
assertArrayEquals(board4.getBoard(),expectedBoard);
}
//Test from 5 to 8 check if put works fine for user2
@Test
public void test5() {
int [][] expectedBoard = {{-1,-1,-1},
{-1, 0,-1},
{-1,-1,-1}};
Board board5 = new Board();
board5.put(2,2,2);
assertArrayEquals(board5.getBoard(),expectedBoard);
}
@Test
public void test6() {
int [][] expectedBoard = {{-1,-1,-1},
{-1,-1, 0},
{-1,-1,-1}};
Board board6 = new Board();
board6.put(2,3,2);
assertArrayEquals(board6.getBoard(),expectedBoard);
}
@Test
public void test7() {
int [][] expectedBoard = {{-1,-1,-1},
{-1,-1,-1},
{ 0,-1,-1}};
Board board7 = new Board();
board7.put(3,1,2);
assertArrayEquals(board7.getBoard(),expectedBoard);
}
@Test
public void test8() {
int [][] expectedBoard = {{-1,-1,-1},
{-1,-1,-1},
{-1, 0,-1}};
Board board8 = new Board();
board8.put(3,2,2);
assertArrayEquals(board8.getBoard(),expectedBoard);
}
//Test to check if checkWin() returns true if
//there's three consecutives horizontally
@Test
public void test9() {
Board board9 = new Board();
board9.put(1,1,2);
board9.put(1,2,2);
board9.put(1,3,2);
assertTrue(board9.checkWin());
}
//Test to check if checkWin() returns true if
//there's three consecutives diagonally
@Test
public void test10() {
Board board10 = new Board();
board10.put(1,1,2);
board10.put(2,2,2);
board10.put(3,3,2);
assertTrue(board10.checkWin());
}
//Test to check if checkWin() returns true if
//there's three consecutives vertically
@Test
public void test11() {
Board board11 = new Board();
board11.put(1,3,1);
board11.put(2,3,1);
board11.put(3,3,1);
assertTrue(board11.checkWin());
}
//Test to check if putting only one element in the grid will
//cause checkWin() to return false
@Test
public void test12() {
Board board12 = new Board();
board12.put(1,3,1);
assertFalse(board12.checkWin());
}
//Test to check if checkTie returns true when the board is
//full but no winner
@Test
public void test13() {
Board board13 = new Board();
board13.put(1,1,1);
board13.put(1,2,1);
board13.put(1,3,2);
board13.put(2,1,2);
board13.put(2,2,2);
board13.put(2,3,1);
board13.put(3,1,1);
board13.put(3,2,1);
board13.put(3,3,2);
assertTrue(board13.checkTie());
}
//Test to check if checkTie returns false when there's a winner
@Test
public void test14() {
Board board14 = new Board();
board14.put(1,1,1);
board14.put(1,2,1);
board14.put(1,3,1);
board14.put(2,1,2);
board14.put(2,2,2);
board14.put(2,3,1);
board14.put(3,1,1);
board14.put(3,2,1);
board14.put(3,3,2);
assertFalse(board14.checkTie());
}
//Test to check if isEmpty works fine
@Test
public void test15() {
Board board15 = new Board();
board15.put(1,3,1);
assertFalse(board15.isEmpty(1,3));
}
}