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
cb3f5fad
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test refactoring
parent
4a9cc889
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
7 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
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/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
cb3f5fad
...
...
@@ -32,16 +32,28 @@ public class Board {
layout
.
placePiece
(
piece
,
Position
.
create
(
position
));
}
public
void
placePiece
(
Piece
piece
,
Position
position
)
{
layout
.
placePiece
(
piece
,
position
);
}
public
void
move
(
Position
from
,
Position
to
)
{
Piece
piece
=
layout
.
getPieceAtPosition
(
from
);
if
(
piece
.
isMovable
(
from
,
to
))
layout
.
move
(
from
,
to
);
}
public
void
move
(
Piece
piece
,
Position
to
)
{
move
(
piece
.
getPosition
(),
to
);
}
public
Piece
getPieceAtPosition
(
String
position
)
{
return
layout
.
getPieceAtPosition
(
Position
.
create
(
position
));
}
public
Piece
getPieceAtPosition
(
Position
position
)
{
return
layout
.
getPieceAtPosition
(
position
);
}
String
print
()
{
return
layout
.
print
();
}
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/KingMoveStrategyTest.java
View file @
cb3f5fad
package
com
.
example
.
paktalin
.
agilejava_exercises
.
moves
;
import
com.example.paktalin.agilejava_exercises.Piece
;
import
com.example.paktalin.agilejava_exercises.Position
;
/**
...
...
@@ -9,6 +10,11 @@ import com.example.paktalin.agilejava_exercises.Position;
public
class
KingMoveStrategyTest
extends
MoveStrategyTest
{
@Override
void
putPieceOnBoard
()
{
board
.
placePiece
(
Piece
.
createKing
(
Piece
.
Color
.
Black
),
currentPosition
);
}
@Override
void
setAccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"a6"
);
}
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/MoveStrategyTest.java
View file @
cb3f5fad
...
...
@@ -13,30 +13,30 @@ import junit.framework.TestCase;
public
abstract
class
MoveStrategyTest
extends
TestCase
{
private
Piece
piece
;
private
Board
board
;
Board
board
;
Position
accessiblePosition
,
notAccessiblePosition
;
Position
currentPosition
=
Position
.
create
(
"b5"
);
@Override
protected
void
setUp
()
throws
Exception
{
board
=
Board
.
createEmpty
();
board
.
placePiece
(
Piece
.
createKing
(
Piece
.
Color
.
Black
),
"b5"
);
piece
=
board
.
getPieceAtPosition
(
"b5"
);
putPieceOnBoard
(
);
piece
=
board
.
getPieceAtPosition
(
currentPosition
);
setAccessiblePosition
();
setNotAccessiblePosition
();
}
abstract
void
putPieceOnBoard
();
abstract
void
setAccessiblePosition
();
abstract
void
setNotAccessiblePosition
();
public
void
testMove
()
{
Position
currentPosition
=
piece
.
getPosition
();
board
.
move
(
currentPosition
,
accessiblePosition
);
board
.
move
(
piece
,
accessiblePosition
);
assertTrue
(
piece
.
isAtPosition
(
accessiblePosition
));
assertFalse
(
piece
.
isAtPosition
(
currentPosition
));
currentPosition
=
accessiblePosition
;
board
.
move
(
currentPosition
,
notAccessiblePosition
);
board
.
move
(
piece
,
notAccessiblePosition
);
assertTrue
(
piece
.
isAtPosition
(
currentPosition
));
assertFalse
(
piece
.
isAtPosition
(
notAccessiblePosition
));
}
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/moves/QueenMoveStrategyTest.java
View file @
cb3f5fad
package
com
.
example
.
paktalin
.
agilejava_exercises
.
moves
;
import
com.example.paktalin.agilejava_exercises.Piece
;
import
com.example.paktalin.agilejava_exercises.Position
;
/**
...
...
@@ -9,6 +10,11 @@ import com.example.paktalin.agilejava_exercises.Position;
public
class
QueenMoveStrategyTest
extends
MoveStrategyTest
{
@Override
void
putPieceOnBoard
()
{
board
.
placePiece
(
Piece
.
createQueen
(
Piece
.
Color
.
Black
),
currentPosition
);
}
@Override
void
setAccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"d3"
);
}
...
...
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