-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessTester.java
More file actions
101 lines (88 loc) · 4.79 KB
/
ChessTester.java
File metadata and controls
101 lines (88 loc) · 4.79 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
// This is a class that tests my code
// Nathan Hsiao
import org.junit.*;
import static org.junit.Assert.*;
public class ChessTester{
// a field to store the board
ChessBoard board;
// this method is testing isLegalNonCapture Move
@Test
public void testIsLegalNonCaptureMove(){
RookPiece b = new RookPiece( "R" , board, ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", board,ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q", board, ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", board, ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", board, ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", board,ChessGame.Side.SOUTH, 5,5);
assertTrue("fails to move to 1,2", b.isLegalNonCaptureMove(1,2));
assertTrue("fails to move to point 4,5", a.isLegalNonCaptureMove(4,5));
assertTrue("fails to move to point 6,6", q.isLegalNonCaptureMove(6,6));
assertTrue("fails to move to point 7,7", k.isLegalNonCaptureMove(7,7));
assertTrue("fails to move to point 8.8", b2.isLegalNonCaptureMove(8,8));
assertTrue("fails to move to point 5,5", p.isLegalNonCaptureMove(5,5));
}
// this method is testing is legal move
@Test
public void testIsLegalMove(){
RookPiece b = new RookPiece( "R" , board,ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B",board, ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q",board, ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", board, ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1",board, ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", board,ChessGame.Side.SOUTH, 5,5);
assertEquals("fails to move to 1,2",false, b.isLegalNonCaptureMove(1,2));
assertTrue("fails to move to point 4,5", a.isLegalMove(4,5));
assertTrue("fails to move to point 6,6", q.isLegalMove(6,6));
assertTrue("fails to move to point 7,7", k.isLegalMove(7,7));
assertTrue("fails to move to point 8.8", b2.isLegalMove(8,8));
assertTrue("fails to move to point 5,5", p.isLegalMove(5,5));
}
// this method is testing is Legal Caputre Move
@Test
public void testIsLegalCaptureMove(){
RookPiece b = new RookPiece( "R" , board, ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", board,ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q", board,ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K",board, ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", board, ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", board, ChessGame.Side.SOUTH, 5,5);
assertEquals("fails to move to 1,2",false, b.isLegalCaptureMove(1,2));
assertTrue("fails to move to point 4,5", a.isLegalCaptureMove(4,5));
assertTrue("fails to move to point 6,6", q.isLegalCaptureMove(6,6));
assertTrue("fails to move to point 7,7", k.isLegalCaptureMove(7,7));
assertTrue("fails to move to point 8.8", b2.isLegalCaptureMove(8,8));
assertTrue("fails to move to point 5,5", p.isLegalCaptureMove(5,5));
}
//this method is testing getRow()
@Test
public void testGetRow(){
RookPiece b = new RookPiece( "R" , board, ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", board, ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q", board,ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", board,ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", board,ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", board,ChessGame.Side.SOUTH, 5,5);
assertEquals("fails to move to 1,2",1, b.getRow());
assertEquals("fails to move to point 4,5",4,a.getRow());
assertEquals("fails to move to point 6,6",6, q.getRow());
assertEquals("fails to move to point 7,7",7, k.getRow());
assertEquals("fails to move to point 8.8",8, b2.getRow());
assertEquals("fails to move to point 5,5",5, p.getRow());
}
// this method is testing getColumn()
@Test
public void testGetColumn(){
RookPiece b = new RookPiece( "R" , board,ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", board, ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q", board,ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", board,ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", board,ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", board,ChessGame.Side.SOUTH, 5,5);
assertEquals("fails to move to 1,2",1, b.getRow());
assertEquals("fails to move to point 4,5",5,a.getRow());
assertEquals("fails to move to point 6,6",6, q.getRow());
assertEquals("fails to move to point 7,7",7, k.getRow());
assertEquals("fails to move to point 8.8",8, b2.getRow());
assertEquals("fails to move to point 5,5",5, p.getRow());
}
}