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
7ad17e3e
authored
May 23, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 3 done
parent
2a341b7f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
16 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/CharacterTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
7ad17e3e
...
@@ -10,17 +10,54 @@ import java.util.List;
...
@@ -10,17 +10,54 @@ import java.util.List;
*/
*/
class
Board
{
class
Board
{
private
List
<
Pawn
>
pawns
=
new
ArrayList
<>();
private
List
<
Pawn
>
seventhRank
=
new
ArrayList
<>();
private
List
<
Pawn
>
secondRank
=
new
ArrayList
<>();
void
initialize
()
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
addWhitePawn
();
addBlackPawn
();
}
}
int
getNumberOfPieces
()
{
int
getNumberOfPieces
()
{
return
pawns
.
size
();
return
seventhRank
.
size
()
+
secondRank
.
size
();
}
void
addWhitePawn
()
{
seventhRank
.
add
(
new
Pawn
(
Pawn
.
COLOR_WHITE
));
}
void
addBlackPawn
()
{
secondRank
.
add
(
new
Pawn
(
Pawn
.
COLOR_BLACK
));
}
}
void
addPawn
(
Pawn
pawn
)
{
List
<
Pawn
>
getRank
(
int
rankNumber
)
{
pawns
.
add
(
pawn
);
if
(
rankNumber
==
2
)
return
secondRank
;
return
seventhRank
;
}
}
Pawn
getPawn
(
int
index
)
{
String
printRank
(
int
rankNumber
)
{
return
pawns
.
get
(
index
);
StringBuilder
rankRepresentation
=
new
StringBuilder
();
for
(
Pawn
pawn
:
getRank
(
rankNumber
))
rankRepresentation
.
append
(
pawn
.
print
());
return
rankRepresentation
.
toString
();
}
void
print
()
{
StringBuilder
buffer
=
new
StringBuilder
();
buffer
.
append
(
"........\n"
);
buffer
.
append
(
printRank
(
2
)
+
"\n"
);
for
(
int
i
=
3
;
i
<
7
;
i
++)
buffer
.
append
(
"........\n"
);
buffer
.
append
(
printRank
(
7
)
+
"\n"
);
buffer
.
append
(
"........\n"
);
System
.
out
.
print
(
buffer
.
toString
());
}
}
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
View file @
7ad17e3e
...
@@ -10,7 +10,7 @@ public class Pawn {
...
@@ -10,7 +10,7 @@ public class Pawn {
private
String
color
;
private
String
color
;
public
Pawn
()
{
Pawn
()
{
color
=
"white"
;
color
=
"white"
;
}
}
...
@@ -21,4 +21,10 @@ public class Pawn {
...
@@ -21,4 +21,10 @@ public class Pawn {
public
String
getColor
()
{
public
String
getColor
()
{
return
color
;
return
color
;
}
}
public
String
print
()
{
if
(
this
.
getColor
().
equals
(
COLOR_BLACK
))
return
"P"
;
return
"p"
;
}
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
View file @
7ad17e3e
...
@@ -15,6 +15,7 @@ public class AllTests extends TestSuite {
...
@@ -15,6 +15,7 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
PawnTest
.
class
);
suite
.
addTestSuite
(
PawnTest
.
class
);
suite
.
addTestSuite
(
BoardTest
.
class
);
suite
.
addTestSuite
(
BoardTest
.
class
);
suite
.
addTestSuite
(
CharacterTest
.
class
);
return
suite
;
return
suite
;
}
}
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
View file @
7ad17e3e
package
com
.
example
.
paktalin
.
agilejava_exercises
;
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.pieces.Pawn
;
import
junit.framework.TestCase
;
import
junit.framework.TestCase
;
/**
/**
...
@@ -17,15 +15,13 @@ public class BoardTest extends TestCase {
...
@@ -17,15 +15,13 @@ public class BoardTest extends TestCase {
}
}
public
void
testBoard
()
{
public
void
testBoard
()
{
assertEquals
(
0
,
board
.
getNumberOfPieces
()
);
board
.
initialize
(
);
}
assertEquals
(
16
,
board
.
getNumberOfPieces
());
public
void
testNumberOfPieces
()
{
assertEquals
(
"PPPPPPPP"
,
board
.
printRank
(
2
));
Pawn
pawn
=
new
Pawn
(
Pawn
.
COLOR_BLACK
);
assertEquals
(
"pppppppp"
,
board
.
printRank
(
7
)
);
board
.
addPawn
(
pawn
);
board
.
print
();
assertEquals
(
1
,
board
.
getNumberOfPieces
());
assertEquals
(
"black"
,
board
.
getPawn
(
0
).
getColor
());
}
}
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/CharacterTest.java
0 → 100644
View file @
7ad17e3e
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
CharacterTest
extends
TestCase
{
public
void
testWhiteSpace
()
{
assertTrue
(
Character
.
isWhitespace
(
' '
));
assertTrue
(
Character
.
isWhitespace
(
'\t'
));
assertTrue
(
Character
.
isWhitespace
(
'\n'
));
assertFalse
(
Character
.
isWhitespace
(
'm'
));
assertFalse
(
Character
.
isWhitespace
(
'a'
));
}
public
void
testIdentifiers
()
{
assertFalse
(
Character
.
isJavaIdentifierPart
(
'^'
));
assertTrue
(
Character
.
isJavaIdentifierPart
(
'k'
));
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
View file @
7ad17e3e
...
@@ -23,4 +23,12 @@ public class PawnTest extends TestCase {
...
@@ -23,4 +23,12 @@ public class PawnTest extends TestCase {
Pawn
pawn
=
new
Pawn
();
Pawn
pawn
=
new
Pawn
();
assertEquals
(
"white"
,
pawn
.
getColor
());
assertEquals
(
"white"
,
pawn
.
getColor
());
}
}
public
void
testPawnRepresentation
()
{
Pawn
blackPawn
=
new
Pawn
(
Pawn
.
COLOR_BLACK
);
assertEquals
(
"P"
,
blackPawn
.
print
());
Pawn
whitePawn
=
new
Pawn
(
Pawn
.
COLOR_WHITE
);
assertEquals
(
"p"
,
whitePawn
.
print
());
}
}
}
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