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
4a9cc889
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test refactoring: created parent MoveStrategyTest
parent
fc9af304
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
52 deletions
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/KingMoveStrategyTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/MoveStrategyTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/QueenMoveStrategyTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/KingMoveStrategyTest.java
View file @
4a9cc889
package
com
.
example
.
paktalin
.
agilejava_exercises
.
moves
;
import
com.example.paktalin.agilejava_exercises.Board
;
import
com.example.paktalin.agilejava_exercises.Piece
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 31/05/2018.
*/
public
class
KingMoveStrategyTest
extends
TestCase
{
private
Piece
king
;
private
Board
board
;
public
class
KingMoveStrategyTest
extends
MoveStrategyTest
{
@Override
protected
void
setUp
()
throws
Exception
{
board
=
Board
.
createEmpty
();
board
.
placePiece
(
Piece
.
createKing
(
Piece
.
Color
.
Black
),
"b5"
);
king
=
board
.
getPieceAtPosition
(
"b5"
);
void
setAccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"a6"
);
}
public
void
testMove
()
{
Position
currentPosition
=
king
.
getPosition
();
assertEquals
(
"b5"
,
currentPosition
.
toString
());
Position
accessiblePosition
=
Position
.
create
(
"a6"
);
board
.
move
(
currentPosition
,
accessiblePosition
);
assertTrue
(
king
.
isAtPosition
(
accessiblePosition
));
assertFalse
(
king
.
isAtPosition
(
currentPosition
));
currentPosition
=
accessiblePosition
;
Position
notAccessiblePosition
=
Position
.
create
(
"d4"
);
board
.
move
(
currentPosition
,
notAccessiblePosition
);
assertTrue
(
king
.
isAtPosition
(
currentPosition
));
assertFalse
(
king
.
isAtPosition
(
notAccessiblePosition
));
@Override
void
setNotAccessiblePosition
()
{
notAccessiblePosition
=
Position
.
create
(
"d4"
);
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/MoveStrategyTest.java
0 → 100644
View file @
4a9cc889
package
com
.
example
.
paktalin
.
agilejava_exercises
.
moves
;
import
com.example.paktalin.agilejava_exercises.Board
;
import
com.example.paktalin.agilejava_exercises.Piece
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 31/05/2018.
*/
public
abstract
class
MoveStrategyTest
extends
TestCase
{
private
Piece
piece
;
private
Board
board
;
Position
accessiblePosition
,
notAccessiblePosition
;
@Override
protected
void
setUp
()
throws
Exception
{
board
=
Board
.
createEmpty
();
board
.
placePiece
(
Piece
.
createKing
(
Piece
.
Color
.
Black
),
"b5"
);
piece
=
board
.
getPieceAtPosition
(
"b5"
);
setAccessiblePosition
();
setNotAccessiblePosition
();
}
abstract
void
setAccessiblePosition
();
abstract
void
setNotAccessiblePosition
();
public
void
testMove
()
{
Position
currentPosition
=
piece
.
getPosition
();
board
.
move
(
currentPosition
,
accessiblePosition
);
assertTrue
(
piece
.
isAtPosition
(
accessiblePosition
));
assertFalse
(
piece
.
isAtPosition
(
currentPosition
));
currentPosition
=
accessiblePosition
;
board
.
move
(
currentPosition
,
notAccessiblePosition
);
assertTrue
(
piece
.
isAtPosition
(
currentPosition
));
assertFalse
(
piece
.
isAtPosition
(
notAccessiblePosition
));
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/QueenMoveStrategyTest.java
View file @
4a9cc889
package
com
.
example
.
paktalin
.
agilejava_exercises
.
moves
;
import
com.example.paktalin.agilejava_exercises.Board
;
import
com.example.paktalin.agilejava_exercises.Piece
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 31/05/2018.
*/
public
class
QueenMoveStrategyTest
extends
TestCase
{
private
Piece
queen
;
private
Board
board
;
public
class
QueenMoveStrategyTest
extends
MoveStrategyTest
{
@Override
protected
void
setUp
()
throws
Exception
{
board
=
Board
.
createEmpty
();
board
.
placePiece
(
Piece
.
createQueen
(
Piece
.
Color
.
Black
),
"b5"
);
queen
=
board
.
getPieceAtPosition
(
"b5"
);
void
setAccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"d3"
);
}
public
void
testMove
()
{
Position
currentPosition
=
queen
.
getPosition
();
Position
accessiblePosition
=
Position
.
create
(
"d3"
);
board
.
move
(
currentPosition
,
accessiblePosition
);
assertTrue
(
queen
.
isAtPosition
(
accessiblePosition
));
assertFalse
(
queen
.
isAtPosition
(
currentPosition
));
currentPosition
=
accessiblePosition
;
Position
notAccessiblePosition
=
Position
.
create
(
"f7"
);
board
.
move
(
currentPosition
,
notAccessiblePosition
);
assertTrue
(
queen
.
isAtPosition
(
currentPosition
));
assertFalse
(
queen
.
isAtPosition
(
notAccessiblePosition
));
@Override
void
setNotAccessiblePosition
()
{
notAccessiblePosition
=
Position
.
create
(
"f7"
);
}
}
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