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
43c0cc25
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug with Pawn strength + refactoring in tests
parent
125aa959
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
53 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Queen.java
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/KingTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PieceTest.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
View file @
43c0cc25
...
@@ -26,7 +26,7 @@ public class Pawn extends Piece {
...
@@ -26,7 +26,7 @@ public class Pawn extends Piece {
private
static
boolean
pawnsOnSameColumn
(
Piece
currentPiece
,
Piece
piece
)
{
private
static
boolean
pawnsOnSameColumn
(
Piece
currentPiece
,
Piece
piece
)
{
return
sameColumn
(
currentPiece
,
piece
)
&&
return
sameColumn
(
currentPiece
,
piece
)
&&
s
ameRow
(
currentPiece
,
piece
)
&&
notS
ameRow
(
currentPiece
,
piece
)
&&
piece
.
getClass
()
==
Pawn
.
class
;
piece
.
getClass
()
==
Pawn
.
class
;
}
}
...
@@ -34,7 +34,7 @@ public class Pawn extends Piece {
...
@@ -34,7 +34,7 @@ public class Pawn extends Piece {
return
piece2
.
getPosition
().
getColumn
()
==
piece1
.
getPosition
().
getColumn
();
return
piece2
.
getPosition
().
getColumn
()
==
piece1
.
getPosition
().
getColumn
();
}
}
private
static
boolean
s
ameRow
(
Piece
piece1
,
Piece
piece2
)
{
private
static
boolean
notS
ameRow
(
Piece
piece1
,
Piece
piece2
)
{
return
piece2
.
getPosition
().
getRow
()
=
=
piece1
.
getPosition
().
getRow
();
return
piece2
.
getPosition
().
getRow
()
!
=
piece1
.
getPosition
().
getRow
();
}
}
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Queen.java
View file @
43c0cc25
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
com.example.paktalin.agilejava_exercises.moves.KingMoveStrategy
;
import
com.example.paktalin.agilejava_exercises.moves.QueenMoveStrategy
;
import
com.example.paktalin.agilejava_exercises.moves.QueenMoveStrategy
;
/**
/**
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
View file @
43c0cc25
package
com
.
example
.
paktalin
.
agilejava_exercises
;
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.moves.*
;
import
com.example.paktalin.agilejava_exercises.moves.*
;
import
com.example.paktalin.agilejava_exercises.pieces.KingTest
;
import
com.example.paktalin.agilejava_exercises.pieces.PawnTest
;
import
junit.framework.TestSuite
;
import
junit.framework.TestSuite
;
...
@@ -13,13 +15,15 @@ public class AllTests extends TestSuite {
...
@@ -13,13 +15,15 @@ public class AllTests extends TestSuite {
public
static
TestSuite
suite
()
{
public
static
TestSuite
suite
()
{
TestSuite
suite
=
new
TestSuite
();
TestSuite
suite
=
new
TestSuite
();
suite
.
addTestSuite
(
PieceTest
.
class
);
suite
.
addTestSuite
(
BoardTest
.
class
);
suite
.
addTestSuite
(
BoardTest
.
class
);
suite
.
addTestSuite
(
CharacterTest
.
class
);
suite
.
addTestSuite
(
CharacterTest
.
class
);
suite
.
addTestSuite
(
PositionTest
.
class
);
suite
.
addTestSuite
(
PositionTest
.
class
);
suite
.
addTestSuite
(
KingMoveStrategyTest
.
class
);
suite
.
addTestSuite
(
KingMoveStrategyTest
.
class
);
suite
.
addTestSuite
(
QueenMoveStrategyTest
.
class
);
suite
.
addTestSuite
(
QueenMoveStrategyTest
.
class
);
suite
.
addTestSuite
(
KingTest
.
class
);
suite
.
addTestSuite
(
PawnTest
.
class
);
return
suite
;
return
suite
;
}
}
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
deleted
100644 → 0
View file @
125aa959
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.pieces.Bishop
;
import
com.example.paktalin.agilejava_exercises.pieces.King
;
import
com.example.paktalin.agilejava_exercises.pieces.Knight
;
import
com.example.paktalin.agilejava_exercises.pieces.Pawn
;
import
com.example.paktalin.agilejava_exercises.pieces.Piece
;
import
com.example.paktalin.agilejava_exercises.pieces.Queen
;
import
com.example.paktalin.agilejava_exercises.pieces.Rook
;
import
junit.framework.TestCase
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
.
Piece
.
Color
.*;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
PieceTest
extends
TestCase
{
public
void
testCreate
()
{
verifyCreation
(
new
Pawn
(
White
),
new
Pawn
(
Black
),
'p'
);
verifyCreation
(
new
King
(
White
),
new
King
(
Black
),
'k'
);
verifyCreation
(
new
Bishop
(
White
),
new
Bishop
(
Black
),
'b'
);
verifyCreation
(
new
Rook
(
White
),
new
Rook
(
Black
),
'r'
);
verifyCreation
(
new
Knight
(
White
),
new
Knight
(
Black
),
'n'
);
verifyCreation
(
new
Queen
(
White
),
new
Queen
(
Black
),
'q'
);
}
private
void
verifyCreation
(
Piece
whitePiece
,
Piece
blackPiece
,
char
representation
)
{
assertTrue
(
whitePiece
.
isWhite
());
assertEquals
(
representation
,
whitePiece
.
getRepresentation
());
assertTrue
(
blackPiece
.
isBlack
());
assertEquals
(
Character
.
toUpperCase
(
representation
),
blackPiece
.
getRepresentation
());
}
public
void
testStrength
()
{
Board
board
=
Board
.
createEmpty
();
board
.
placePiece
(
new
Pawn
(
Black
),
"a7"
);
assertEquals
(
1.0
,
board
.
getPieceAtPosition
(
"a7"
).
getStrength
());
board
.
placePiece
(
new
Pawn
(
Black
),
"a6"
);
assertEquals
(
0.5
,
board
.
getPieceAtPosition
(
"a6"
).
getStrength
());
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/KingTest.java
0 → 100644
View file @
43c0cc25
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
/**
* Created by Paktalin on 01/06/2018.
*/
public
class
KingTest
extends
PieceTest
{
@Override
void
setExpectedRepresentation
()
{
expectedRepresentation
=
'k'
;
}
@Override
Piece
createPiece
(
Piece
.
Color
color
)
{
return
new
King
(
color
);
}
@Override
void
setExpectedStrength
()
{
expectedStrength
=
0
;
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
0 → 100644
View file @
43c0cc25
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
.
Piece
.
Color
.
Black
;
/**
* Created by Paktalin on 01/06/2018.
*/
public
class
PawnTest
extends
PieceTest
{
@Override
void
setExpectedRepresentation
()
{
expectedRepresentation
=
'p'
;
}
@Override
Piece
createPiece
(
Piece
.
Color
color
)
{
return
new
Pawn
(
color
);
}
@Override
void
setExpectedStrength
()
{
expectedStrength
=
1
;
}
@Override
public
void
testStrength
()
{
super
.
testStrength
();
expectedStrength
=
0.5
;
board
.
placePiece
(
createPiece
(
Black
),
"a6"
);
assertEquals
(
expectedStrength
,
board
.
getPieceAtPosition
(
"a6"
).
getStrength
());
assertEquals
(
expectedStrength
,
board
.
getPieceAtPosition
(
"a7"
).
getStrength
());
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PieceTest.java
0 → 100644
View file @
43c0cc25
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
com.example.paktalin.agilejava_exercises.Board
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
junit.framework.TestCase
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
.
Piece
.
Color
.*;
/**
* Created by Paktalin on 23/05/2018.
*/
public
abstract
class
PieceTest
extends
TestCase
{
char
expectedRepresentation
;
double
expectedStrength
;
private
Position
position
=
Position
.
create
(
"a7"
);
Board
board
;
@Override
protected
void
setUp
()
throws
Exception
{
setExpectedRepresentation
();
setExpectedStrength
();
}
abstract
void
setExpectedRepresentation
();
abstract
Piece
createPiece
(
Piece
.
Color
color
);
abstract
void
setExpectedStrength
();
public
void
testCreate
()
{
Piece
whitePiece
=
createPiece
(
White
);
Piece
blackPiece
=
createPiece
(
Black
);
assertTrue
(
whitePiece
.
isWhite
());
assertEquals
(
expectedRepresentation
,
whitePiece
.
getRepresentation
());
assertTrue
(
blackPiece
.
isBlack
());
assertEquals
(
getBlackRepresentation
(),
blackPiece
.
getRepresentation
());
}
private
char
getBlackRepresentation
()
{
return
Character
.
toUpperCase
(
expectedRepresentation
);
}
public
void
testStrength
()
{
board
=
Board
.
createEmpty
();
board
.
placePiece
(
createPiece
(
Black
),
position
);
assertEquals
(
expectedStrength
,
board
.
getPieceAtPosition
(
position
).
getStrength
());
}
}
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