Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
ChessAndroid
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1642774c
authored
May 24, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 5, exercise 5 done
parent
94b90657
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
1642774c
...
...
@@ -36,9 +36,7 @@ class Board {
}
private
void
setPosition
(
Piece
piece
,
int
rank
,
char
file
)
{
char
firstColumnLetter
=
'a'
;
int
column
=
(
int
)
file
-
(
int
)
firstColumnLetter
;
setPosition
(
piece
,
rank
,
column
);
setPosition
(
piece
,
rank
,
fileToColumn
(
file
));
}
private
void
setPosition
(
Piece
piece
,
int
rank
,
int
column
)
{
...
...
@@ -91,4 +89,18 @@ class Board {
}
return
buffer
.
toString
();
}
private
int
fileToColumn
(
char
file
)
{
char
firstColumnLetter
=
'a'
;
return
(
int
)
file
-
(
int
)
firstColumnLetter
;
}
Piece
getPieceAtLocation
(
String
location
)
{
int
row
=
Integer
.
parseInt
(
location
.
split
(
""
)[
1
])
-
1
;
int
column
=
fileToColumn
(
location
.
toCharArray
()[
0
]);
return
positionState
[
row
][
column
];
}
}
\ No newline at end of file
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
View file @
1642774c
...
...
@@ -43,8 +43,16 @@ public class BoardTest extends TestCase {
assertEquals
(
2
,
board
.
pieceCount
(
Piece
.
Type
.
Rook
,
Piece
.
Color
.
Black
));
}
public
void
testBoardDimensions
()
{
assertEquals
(
8
,
board
.
ROW_COUNT
);
assertEquals
(
8
,
board
.
COLUMN_COUNT
);
public
void
testPieceLocation
()
{
board
.
initialize
();
Piece
piece
=
board
.
getPieceAtLocation
(
"a8"
);
assertEquals
(
Piece
.
Type
.
Rook
,
piece
.
getType
());
assertEquals
(
Piece
.
Color
.
White
,
piece
.
getColor
());
piece
=
board
.
getPieceAtLocation
(
"e1"
);
assertEquals
(
Piece
.
Type
.
King
,
piece
.
getType
());
assertEquals
(
Piece
.
Color
.
Black
,
piece
.
getColor
());
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
View file @
1642774c
...
...
@@ -26,4 +26,14 @@ public class PieceTest extends TestCase {
assertEquals
(
type
,
blackPiece
.
getType
());
assertEquals
(
Character
.
toUpperCase
(
representation
),
blackPiece
.
getRepresentation
());
}
public
void
testLanguage
()
{
assertEquals
(
8
,
Integer
.
parseInt
(
"a8"
.
split
(
""
)[
1
]));
assertEquals
(
0
,
fileToColumn
(
"a8"
.
toCharArray
()[
0
]));
}
private
int
fileToColumn
(
char
file
)
{
char
firstColumnLetter
=
'a'
;
return
(
int
)
file
-
(
int
)
firstColumnLetter
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment