-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjunitTest.java
More file actions
126 lines (126 loc) · 5.69 KB
/
junitTest.java
File metadata and controls
126 lines (126 loc) · 5.69 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
// This is a class that tests my code
// Nathan Hsiao
import org.junit.*;
import static org.junit.Assert.*;
public class ChessTester{
// this method is testing isLegalNonCapture Move
@Test
public void testIsLegalNonCaptureMove(){
// i am making instance of rook piece
RookPiece b = new RookPiece( "R" , ChessGame.Side.NORTH, 1, 1);
// I am making instance of Bishop
BishopPiece a = new BishopPiece("B", ChessGame.Side.SOUTH, 4,5);
// i amking instance of Queen piece
QueenPiece q = new QueenPiece("Q", ChessGame.Side.NORTH, 6,6);
// I am making instance of king piece
KingPiece k = new KingPiece("K", ChessGame.Side.NORTH, 7,7);
// i am making instance of BIshop Piece
BishopPiece b2 = new BishopPiece("B1", ChessGame.Side.SOUTH, 8,8);
// I am making instance of Pawn
PawnPiece p = new PawnPiece("P", ChessGame.Side.SOUTH, 5,5);
// testing legal noncaputere, should be false
assertTrue("fails to move to 1,2", b.isLegalNonCaptureMove(1,2));
// testing legalnon caputer move, shoule be false
assertTrue("fails to move to point 4,5", a.isLegalNonCaptureMove(4,5));
// testing legal non caputer emove, should be false
assertTrue("fails to move to point 6,6", q.isLegalNonCaptureMove(6,6));
// testing legal noncaputer test for king , should be false
assertTrue("fails to move to point 7,7", k.isLegalNonCaptureMove(7,7));
// testing legal non capture move , should be false
assertTrue("fails to move to point 8.8", b2.isLegalNonCaptureMove(8,8));
//testing legal non capture move, should be false
assertTrue("fails to move to point 5,5", p.isLegalNonCaptureMove(5,5));
}
// this method is testing is legal move
@Test
public void testIsLegalMove(){
Creating instance of took
RookPiece b = new RookPiece( "R" , ChessGame.Side.NORTH, 1, 1);
// creating instance of bishopBishopPiece a = new BishopPiece("B", ChessGame.Side.SOUTH, 4,5);
// creating instance of QUeen
QueenPiece q = new QueenPiece("Q", ChessGame.Side.NORTH, 6,6);
//creating instance of king piece
KingPiece k = new KingPiece("K", ChessGame.Side.NORTH, 7,7);
// creaitng instance of Bishop
BishopPiece b2 = new BishopPiece("B1", ChessGame.Side.SOUTH, 8,8);
// creating instance of pawn
PawnPiece p = new PawnPiece("P", ChessGame.Side.SOUTH, 5,5);
// test should be false
assertEquals("fails to move to 1,2",false, b.isLegalNonCaptureMove(1,2));
//testing should be false
assertTrue("fails to move to point 4,5", a.isLegalMove(4,5));
//testing should be false
assertTrue("fails to move to point 6,6", q.isLegalMove(6,6));
//testing should be false
assertTrue("fails to move to point 7,7", k.isLegalMove(7,7));
//testing should be false
assertTrue("fails to move to point 8.8", b2.isLegalMove(8,8));
//testing should be false
assertTrue("fails to move to point 5,5", p.isLegalMove(5,5));
}
// this method is testing is Legal Caputre Move
@Test
public void testIsLegalCaptureMove(){
//cereating instance of rook
RookPiece b = new RookPiece( "R" , ChessGame.Side.NORTH, 1, 1);
///creaitn instance of bishop
BishopPiece a = new BishopPiece("B", ChessGame.Side.SOUTH, 4,5);
//creating instance of Queen
QueenPiece q = new QueenPiece("Q", ChessGame.Side.NORTH, 6,6);
//creating instance of King piece
KingPiece k = new KingPiece("K", ChessGame.Side.NORTH, 7,7);//creating instance of bishop
BishopPiece b2 = new BishopPiece("B1", ChessGame.Side.SOUTH, 8,8);
// creating instance of Pawn
PawnPiece p = new PawnPiece("P", ChessGame.Side.SOUTH, 5,5);
//should be false
assertEquals("fails to move to 1,2",false, b.isLegalCaptureMove(1,2));
//Should be false
assertTrue("fails to move to point 4,5", a.isLegalCaptureMove(4,5));
//Should be false
assertTrue("fails to move to point 6,6", q.isLegalCaptureMove(6,6));
//Shouldbe false
assertTrue("fails to move to point 7,7", k.isLegalCaptureMove(7,7));
//should be false
assertTrue("fails to move to point 8.8", b2.isLegalCaptureMove(8,8));
//should be false
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" , ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", ChessGame.Side.SOUTH, 4,5);
QueenPiece q = new QueenPiece("Q", ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", 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(){
//creaitng instances for all piece, rook, bishop, king, Pawn
RookPiece b = new RookPiece( "R" , ChessGame.Side.NORTH, 1, 1);
BishopPiece a = new BishopPiece("B", ChessGame.Side.SOUTH, 4,5);QueenPiece q = new QueenPiece("Q", ChessGame.Side.NORTH, 6,6);
KingPiece k = new KingPiece("K", ChessGame.Side.NORTH, 7,7);
BishopPiece b2 = new BishopPiece("B1", ChessGame.Side.SOUTH, 8,8);
PawnPiece p = new PawnPiece("P", ChessGame.Side.SOUTH, 5,5);
//should eb false
assertEquals("fails to move to 1,2",1, b.getColumn());
//should be false
assertEquals("fails to move to point 4,5",5,a.getColumn());
//should be false
assertEquals("fails to move to point 6,6",6, q.getColumn());
//should be false
assertEquals("fails to move to point 7,7",7, k.getColumn());
//should be false
assertEquals("fails to move to point 8.8",8, b2getColumn());
//should be false
assertEquals("fails to move to point 5,5",5, p.getColumn());
}
}