Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
Chess
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
90aeec8c
authored
6 years ago
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring + completed 7.3.a
parent
816ed672
master
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
114 additions
and
96 deletions
src/main/com/paktalin/chess/Board.java
src/main/com/paktalin/chess/BoardLayout.java
src/main/com/paktalin/chess/Color.java
src/main/com/paktalin/chess/Position.java
src/main/com/paktalin/chess/language/Continue.java
src/main/com/paktalin/chess/language/Factorial.java
src/main/com/paktalin/chess/moves/KingMoveStrategy.java
src/main/com/paktalin/chess/moves/MoveStrategy.java
src/main/com/paktalin/chess/moves/QueenMoveStrategy.java
src/main/com/paktalin/chess/pieces/Bishop.java
src/main/com/paktalin/chess/pieces/King.java
src/main/com/paktalin/chess/pieces/Knight.java
src/main/com/paktalin/chess/pieces/Pawn.java
src/main/com/paktalin/chess/pieces/Piece.java
src/main/com/paktalin/chess/pieces/Queen.java
src/main/com/paktalin/chess/pieces/Rook.java
src/test/com/paktalin/chess/CharacterTest.java → src/test/com/paktalin/chess/language/CharacterTest.java
src/test/com/paktalin/chess/language/ContinueTest.java
src/test/com/paktalin/chess/language/FactorialTest.java
src/test/com/paktalin/chess/moves/KingMoveStrategyTest.java
src/test/com/paktalin/chess/moves/MoveStrategyTest.java
src/test/com/paktalin/chess/moves/QueenMoveStrategyTest.java
src/test/com/paktalin/chess/pieces/PieceTest.java
src/main/com/paktalin/chess/Board.java
View file @
90aeec8c
...
@@ -4,8 +4,7 @@ import com.paktalin.chess.pieces.Piece;
...
@@ -4,8 +4,7 @@ import com.paktalin.chess.pieces.Piece;
import
java.util.List
;
import
java.util.List
;
import
static
com
.
paktalin
.
chess
.
pieces
.
Piece
.
Color
.
Black
;
import
static
com
.
paktalin
.
chess
.
Color
.*;
import
static
com
.
paktalin
.
chess
.
pieces
.
Piece
.
Color
.
White
;
/**
/**
* Created by Paktalin on 23/05/2018.
* Created by Paktalin on 23/05/2018.
...
@@ -65,7 +64,7 @@ public class Board {
...
@@ -65,7 +64,7 @@ public class Board {
getSide
(
piece
.
getColor
()).
addPiece
(
piece
);
getSide
(
piece
.
getColor
()).
addPiece
(
piece
);
}
}
private
Side
getSide
(
Piece
.
Color
color
){
private
Side
getSide
(
Color
color
){
if
(
color
==
White
)
if
(
color
==
White
)
return
whiteSide
;
return
whiteSide
;
return
blackSide
;
return
blackSide
;
...
@@ -74,13 +73,13 @@ public class Board {
...
@@ -74,13 +73,13 @@ public class Board {
int
getPiecesCount
()
{
int
getPiecesCount
()
{
return
getPiecesCount
(
Black
)
+
getPiecesCount
(
White
);
return
getPiecesCount
(
Black
)
+
getPiecesCount
(
White
);
}
}
double
getStrength
(
Piece
.
Color
color
)
{
double
getStrength
(
Color
color
)
{
return
getSide
(
color
).
getStrength
();
return
getSide
(
color
).
getStrength
();
}
}
List
<
Piece
>
getPieces
(
Piece
.
Color
color
)
{
List
<
Piece
>
getPieces
(
Color
color
)
{
return
getSide
(
color
).
getPieces
();
return
getSide
(
color
).
getPieces
();
}
}
int
getPiecesCount
(
Piece
.
Color
color
){
int
getPiecesCount
(
Color
color
){
return
getSide
(
color
).
getPiecesCount
();
return
getSide
(
color
).
getPiecesCount
();
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/BoardLayout.java
View file @
90aeec8c
...
@@ -3,7 +3,7 @@ package com.paktalin.chess;
...
@@ -3,7 +3,7 @@ package com.paktalin.chess;
import
com.paktalin.chess.pieces.Piece
;
import
com.paktalin.chess.pieces.Piece
;
import
com.paktalin.chess.pieces.*
;
import
com.paktalin.chess.pieces.*
;
import
static
com
.
paktalin
.
chess
.
pieces
.
Piece
.
Color
.*;
import
static
com
.
paktalin
.
chess
.
Color
.*;
import
static
com
.
paktalin
.
chess
.
util
.
StringUtil
.
NEW_LINE
;
import
static
com
.
paktalin
.
chess
.
util
.
StringUtil
.
NEW_LINE
;
...
@@ -33,7 +33,7 @@ class BoardLayout {
...
@@ -33,7 +33,7 @@ class BoardLayout {
return
layout
;
return
layout
;
}
}
private
void
initializeKingRank
(
Piece
.
Color
color
,
int
row
)
{
private
void
initializeKingRank
(
Color
color
,
int
row
)
{
placePiece
(
new
Rook
(
color
),
Position
.
create
(
row
,
0
));
placePiece
(
new
Rook
(
color
),
Position
.
create
(
row
,
0
));
placePiece
(
new
Knight
(
color
),
Position
.
create
(
row
,
1
));
placePiece
(
new
Knight
(
color
),
Position
.
create
(
row
,
1
));
placePiece
(
new
Bishop
(
color
),
Position
.
create
(
row
,
2
));
placePiece
(
new
Bishop
(
color
),
Position
.
create
(
row
,
2
));
...
@@ -44,7 +44,7 @@ class BoardLayout {
...
@@ -44,7 +44,7 @@ class BoardLayout {
placePiece
(
new
Rook
(
color
),
Position
.
create
(
row
,
7
));
placePiece
(
new
Rook
(
color
),
Position
.
create
(
row
,
7
));
}
}
private
void
initializePawnRank
(
Piece
.
Color
color
,
int
row
)
{
private
void
initializePawnRank
(
Color
color
,
int
row
)
{
for
(
int
column
=
0
;
column
<
COLUMN_COUNT
;
column
++)
for
(
int
column
=
0
;
column
<
COLUMN_COUNT
;
column
++)
placePiece
(
new
Pawn
(
color
),
Position
.
create
(
row
,
column
));
placePiece
(
new
Pawn
(
color
),
Position
.
create
(
row
,
column
));
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/Color.java
0 → 100644
View file @
90aeec8c
package
com
.
paktalin
.
chess
;
public
enum
Color
{
White
,
Black
}
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/Position.java
View file @
90aeec8c
...
@@ -9,8 +9,6 @@ public class Position {
...
@@ -9,8 +9,6 @@ public class Position {
private
int
row
;
private
int
row
;
private
char
column
;
private
char
column
;
private
Position
()
{}
private
Position
(
int
row
,
char
column
)
{
private
Position
(
int
row
,
char
column
)
{
this
.
row
=
row
;
this
.
row
=
row
;
this
.
column
=
column
;
this
.
column
=
column
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/language/Continue.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
language
;
package
com
.
paktalin
.
chess
.
language
;
import
java.util.Vector
;
class
Continue
{
class
Continue
{
private
final
static
char
WHITESPACE
=
' '
;
private
final
static
char
WHITESPACE
=
' '
;
private
final
static
char
ASTERISK
=
'*'
;
private
final
static
char
ASTERISK
=
'*'
;
static
String
generate
OneToNString
(
int
n
)
{
static
String
generate
StringOneToN
(
int
n
)
{
if
(
n
<
1
)
return
null
;
if
(
n
<
1
)
return
null
;
StringBuilder
result
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
...
@@ -15,4 +17,17 @@ class Continue {
...
@@ -15,4 +17,17 @@ class Continue {
}
}
return
result
.
toString
();
return
result
.
toString
();
}
}
static
Vector
<
String
>
generateVectorOneToN
(
int
n
)
{
if
(
n
<
1
)
return
null
;
Vector
<
String
>
resultVector
=
new
Vector
<>();
StringBuilder
currentBuilder
;
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
currentBuilder
=
new
StringBuilder
(
String
.
valueOf
(
i
));
if
(
i
%
5
==
0
)
currentBuilder
.
append
(
ASTERISK
);
resultVector
.
add
(
currentBuilder
.
toString
());
}
return
resultVector
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/language/Factorial.java
View file @
90aeec8c
...
@@ -2,7 +2,7 @@ package com.paktalin.chess.language;
...
@@ -2,7 +2,7 @@ package com.paktalin.chess.language;
class
Factorial
{
class
Factorial
{
static
int
getW
hileFactorial
(
int
number
)
{
static
int
w
hileFactorial
(
int
number
)
{
int
factorial
;
int
factorial
;
if
(
number
==
0
||
number
==
1
)
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
factorial
=
1
;
...
@@ -17,7 +17,7 @@ class Factorial {
...
@@ -17,7 +17,7 @@ class Factorial {
return
factorial
;
return
factorial
;
}
}
static
int
getD
oWhileFactorial
(
int
number
)
{
static
int
d
oWhileFactorial
(
int
number
)
{
int
factorial
;
int
factorial
;
if
(
number
==
0
||
number
==
1
)
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
factorial
=
1
;
...
@@ -32,7 +32,7 @@ class Factorial {
...
@@ -32,7 +32,7 @@ class Factorial {
return
factorial
;
return
factorial
;
}
}
static
int
getF
orFactorial
(
int
number
)
{
static
int
f
orFactorial
(
int
number
)
{
int
factorial
;
int
factorial
;
if
(
number
==
0
||
number
==
1
)
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
factorial
=
1
;
...
@@ -45,7 +45,7 @@ class Factorial {
...
@@ -45,7 +45,7 @@ class Factorial {
return
factorial
;
return
factorial
;
}
}
static
int
getB
reakFactorial
(
int
number
)
{
static
int
b
reakFactorial
(
int
number
)
{
int
factorial
;
int
factorial
;
if
(
number
==
0
||
number
==
1
)
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
factorial
=
1
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/moves/KingMoveStrategy.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
moves
;
package
com
.
paktalin
.
chess
.
moves
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
/**
/**
...
@@ -11,7 +10,7 @@ public class KingMoveStrategy extends MoveStrategy{
...
@@ -11,7 +10,7 @@ public class KingMoveStrategy extends MoveStrategy{
@Override
@Override
public
boolean
isMovable
(
Position
from
,
Position
to
)
{
public
boolean
isMovable
(
Position
from
,
Position
to
)
{
super
.
isMovabl
e
(
from
,
to
);
initializ
e
(
from
,
to
);
return
!(
distantRows
()
||
distantColumns
());
return
!(
distantRows
()
||
distantColumns
());
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/moves/MoveStrategy.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
moves
;
package
com
.
paktalin
.
chess
.
moves
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
/**
/**
...
@@ -8,20 +7,15 @@ import com.paktalin.chess.Position;
...
@@ -8,20 +7,15 @@ import com.paktalin.chess.Position;
*/
*/
public
abstract
class
MoveStrategy
{
public
abstract
class
MoveStrategy
{
int
fromRow
,
fromColumn
;
int
fromRow
,
fromColumn
;
int
toRow
,
toColumn
;
int
toRow
,
toColumn
;
private
void
initialize
(
Position
from
,
Position
to
)
{
void
initialize
(
Position
from
,
Position
to
)
{
fromRow
=
from
.
getRow
();
fromRow
=
from
.
getRow
();
fromColumn
=
from
.
getIntColumn
();
fromColumn
=
from
.
getIntColumn
();
toRow
=
to
.
getRow
();
toRow
=
to
.
getRow
();
toColumn
=
to
.
getIntColumn
();
toColumn
=
to
.
getIntColumn
();
}
}
public
boolean
isMovable
(
Position
from
,
Position
to
)
{
public
abstract
boolean
isMovable
(
Position
from
,
Position
to
);
initialize
(
from
,
to
);
return
false
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/moves/QueenMoveStrategy.java
View file @
90aeec8c
...
@@ -10,7 +10,7 @@ public class QueenMoveStrategy extends MoveStrategy {
...
@@ -10,7 +10,7 @@ public class QueenMoveStrategy extends MoveStrategy {
@Override
@Override
public
boolean
isMovable
(
Position
from
,
Position
to
)
{
public
boolean
isMovable
(
Position
from
,
Position
to
)
{
super
.
isMovabl
e
(
from
,
to
);
initializ
e
(
from
,
to
);
return
sameRow
()
||
sameColumn
()
||
diagonal
();
return
sameRow
()
||
sameColumn
()
||
diagonal
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Bishop.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
/**
/**
* Created by Paktalin on 01/06/2018.
* Created by Paktalin on 01/06/2018.
*/
*/
public
class
Bishop
extends
Piece
{
public
class
Bishop
extends
Piece
{
public
Bishop
(
Piece
.
Color
color
)
{
public
Bishop
(
Color
color
)
{
strength
=
3
;
strength
=
3
;
representation
=
'b'
;
representation
=
'b'
;
this
.
color
=
color
;
this
.
color
=
color
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/King.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
import
com.paktalin.chess.moves.KingMoveStrategy
;
import
com.paktalin.chess.moves.KingMoveStrategy
;
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Knight.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
/**
/**
* Created by Paktalin on 01/06/2018.
* Created by Paktalin on 01/06/2018.
*/
*/
public
class
Knight
extends
Piece
{
public
class
Knight
extends
Piece
{
public
Knight
(
Piece
.
Color
color
)
{
public
Knight
(
Color
color
)
{
strength
=
2.5
;
strength
=
2.5
;
representation
=
'n'
;
representation
=
'n'
;
this
.
color
=
color
;
this
.
color
=
color
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Pawn.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -8,7 +10,7 @@ import java.util.List;
...
@@ -8,7 +10,7 @@ import java.util.List;
public
class
Pawn
extends
Piece
{
public
class
Pawn
extends
Piece
{
public
Pawn
(
Piece
.
Color
color
)
{
public
Pawn
(
Color
color
)
{
strength
=
1
;
strength
=
1
;
representation
=
'p'
;
representation
=
'p'
;
this
.
color
=
color
;
this
.
color
=
color
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Piece.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.moves.MoveStrategy
;
import
com.paktalin.chess.moves.MoveStrategy
;
...
@@ -10,8 +11,6 @@ import java.util.List;
...
@@ -10,8 +11,6 @@ import java.util.List;
*/
*/
public
abstract
class
Piece
implements
Comparable
<
Piece
>
{
public
abstract
class
Piece
implements
Comparable
<
Piece
>
{
public
enum
Color
{
White
,
Black
}
Color
color
;
Color
color
;
private
Position
position
;
private
Position
position
;
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Queen.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
import
com.paktalin.chess.moves.QueenMoveStrategy
;
import
com.paktalin.chess.moves.QueenMoveStrategy
;
/**
/**
...
@@ -8,7 +9,7 @@ import com.paktalin.chess.moves.QueenMoveStrategy;
...
@@ -8,7 +9,7 @@ import com.paktalin.chess.moves.QueenMoveStrategy;
public
class
Queen
extends
Piece
{
public
class
Queen
extends
Piece
{
public
Queen
(
Piece
.
Color
color
)
{
public
Queen
(
Color
color
)
{
strength
=
9
;
strength
=
9
;
representation
=
'q'
;
representation
=
'q'
;
moveStrategy
=
new
QueenMoveStrategy
();
moveStrategy
=
new
QueenMoveStrategy
();
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/pieces/Rook.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
pieces
;
package
com
.
paktalin
.
chess
.
pieces
;
import
com.paktalin.chess.Color
;
/**
/**
* Created by Paktalin on 01/06/2018.
* Created by Paktalin on 01/06/2018.
*/
*/
public
class
Rook
extends
Piece
{
public
class
Rook
extends
Piece
{
public
Rook
(
Piece
.
Color
color
)
{
public
Rook
(
Color
color
)
{
strength
=
5
;
strength
=
5
;
representation
=
'r'
;
representation
=
'r'
;
this
.
color
=
color
;
this
.
color
=
color
;
...
...
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/CharacterTest.java
→
src/test/com/paktalin/chess/
language/
CharacterTest.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
;
package
com
.
paktalin
.
chess
.
language
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
...
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/language/ContinueTest.java
View file @
90aeec8c
...
@@ -2,17 +2,30 @@ package com.paktalin.chess.language;
...
@@ -2,17 +2,30 @@ package com.paktalin.chess.language;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
java.util.List
;
import
java.util.Vector
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
class
ContinueTest
{
class
ContinueTest
{
@Test
@Test
void
testContinue
(){
void
generateStringOneToN
()
{
int
n
=
12
;
int
n
=
0
;
assertNull
(
Continue
.
generateStringOneToN
(
n
));
n
=
12
;
String
oneToN
=
"1 2 3 4 5* 6 7 8 9 10* 11 12"
;
String
oneToN
=
"1 2 3 4 5* 6 7 8 9 10* 11 12"
;
assertEquals
(
oneToN
,
Continue
.
generateOneToNString
(
n
));
assertEquals
(
oneToN
,
Continue
.
generateStringOneToN
(
n
));
}
@Test
void
generateVectorOneToN
()
{
int
n
=
0
;
assertNull
(
Continue
.
generateStringOneToN
(
n
));
n
=
0
;
n
=
10
;
assertNull
(
Continue
.
generateOneToNString
(
n
));
Vector
<
String
>
oneToNVector
=
new
Vector
<>(
List
.
of
(
"1"
,
"2"
,
"3"
,
"4"
,
"5*"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10*"
));
assertEquals
(
oneToNVector
,
Continue
.
generateVectorOneToN
(
n
));
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/language/FactorialTest.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
language
;
package
com
.
paktalin
.
chess
.
language
;
import
com.paktalin.chess.language.Factorial
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
...
@@ -8,42 +7,42 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
...
@@ -8,42 +7,42 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
class
FactorialTest
{
class
FactorialTest
{
@Test
@Test
void
testWhile
()
{
void
whileFactorial
()
{
int
factorial
=
Factorial
.
getW
hileFactorial
(
5
);
int
factorial
=
Factorial
.
w
hileFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getW
hileFactorial
(
4
);
factorial
=
Factorial
.
w
hileFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getW
hileFactorial
(
3
);
factorial
=
Factorial
.
w
hileFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
}
@Test
@Test
void
testDoWhile
()
{
void
doWhileFactorial
()
{
int
factorial
=
Factorial
.
getD
oWhileFactorial
(
5
);
int
factorial
=
Factorial
.
d
oWhileFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getD
oWhileFactorial
(
4
);
factorial
=
Factorial
.
d
oWhileFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getD
oWhileFactorial
(
3
);
factorial
=
Factorial
.
d
oWhileFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
}
@Test
@Test
void
testFor
()
{
void
forFactorial
()
{
int
factorial
=
Factorial
.
getF
orFactorial
(
5
);
int
factorial
=
Factorial
.
f
orFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getF
orFactorial
(
4
);
factorial
=
Factorial
.
f
orFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getF
orFactorial
(
3
);
factorial
=
Factorial
.
f
orFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
}
@Test
@Test
void
testBreak
()
{
void
breakFactorial
()
{
int
factorial
=
Factorial
.
getB
reakFactorial
(
5
);
int
factorial
=
Factorial
.
b
reakFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getB
reakFactorial
(
4
);
factorial
=
Factorial
.
b
reakFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getB
reakFactorial
(
3
);
factorial
=
Factorial
.
b
reakFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/moves/KingMoveStrategyTest.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
moves
;
package
com
.
paktalin
.
chess
.
moves
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.pieces.King
;
import
com.paktalin.chess.pieces.Piece
;
/**
/**
* Created by Paktalin on 31/05/2018.
* Created by Paktalin on 31/05/2018.
...
@@ -11,17 +9,17 @@ import com.paktalin.chess.pieces.Piece;
...
@@ -11,17 +9,17 @@ import com.paktalin.chess.pieces.Piece;
class
KingMoveStrategyTest
extends
MoveStrategyTest
{
class
KingMoveStrategyTest
extends
MoveStrategyTest
{
@Override
@Override
void
putPieceOnBoard
()
{
MoveStrategy
moveStrategy
()
{
board
.
placePiece
(
new
King
(
Piece
.
Color
.
Black
),
currentPosition
);
return
new
KingMoveStrategy
(
);
}
}
@Override
@Override
void
setA
ccessiblePosition
()
{
Position
a
ccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"a6"
);
return
Position
.
create
(
"a6"
);
}
}
@Override
@Override
void
setN
otAccessiblePosition
()
{
Position
n
otAccessiblePosition
()
{
notAccessiblePosition
=
Position
.
create
(
"d4"
);
return
Position
.
create
(
"d4"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/moves/MoveStrategyTest.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
moves
;
package
com
.
paktalin
.
chess
.
moves
;
import
com.paktalin.chess.Board
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.pieces.Piece
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -14,33 +12,24 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
...
@@ -14,33 +12,24 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
*/
abstract
class
MoveStrategyTest
{
abstract
class
MoveStrategyTest
{
private
Piece
piece
;
private
Position
accessiblePosition
,
notAccessiblePosition
,
initialPosition
;
Board
board
;
private
MoveStrategy
moveStrategy
;
Position
accessiblePosition
,
notAccessiblePosition
;
Position
currentPosition
=
Position
.
create
(
"b5"
);
@BeforeEach
@BeforeEach
void
init
()
{
void
init
()
{
board
=
Board
.
createEmpty
();
initialPosition
=
Position
.
create
(
"b5"
);
putPieceOnBoard
();
moveStrategy
=
moveStrategy
();
piece
=
board
.
getPieceAtPosition
(
currentPosition
);
accessiblePosition
=
accessiblePosition
();
setAccessiblePosition
();
notAccessiblePosition
=
notAccessiblePosition
();
setNotAccessiblePosition
();
}
}
abstract
void
putPieceOnBoard
();
abstract
MoveStrategy
moveStrategy
();
abstract
void
setA
ccessiblePosition
();
abstract
Position
a
ccessiblePosition
();
abstract
void
setN
otAccessiblePosition
();
abstract
Position
n
otAccessiblePosition
();
@Test
@Test
void
testMove
()
{
void
isMovable
()
{
board
.
move
(
piece
,
accessiblePosition
);
assertTrue
(
moveStrategy
.
isMovable
(
initialPosition
,
accessiblePosition
));
assertTrue
(
piece
.
isAtPosition
(
accessiblePosition
));
assertFalse
(
moveStrategy
.
isMovable
(
initialPosition
,
notAccessiblePosition
));
assertFalse
(
piece
.
isAtPosition
(
currentPosition
));
currentPosition
=
accessiblePosition
;
board
.
move
(
piece
,
notAccessiblePosition
);
assertTrue
(
piece
.
isAtPosition
(
currentPosition
));
assertFalse
(
piece
.
isAtPosition
(
notAccessiblePosition
));
}
}
}
}
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/moves/QueenMoveStrategyTest.java
View file @
90aeec8c
package
com
.
paktalin
.
chess
.
moves
;
package
com
.
paktalin
.
chess
.
moves
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.Position
;
import
com.paktalin.chess.pieces.Piece
;
import
com.paktalin.chess.pieces.Queen
;
/**
/**
* Created by Paktalin on 31/05/2018.
* Created by Paktalin on 31/05/2018.
...
@@ -11,17 +9,17 @@ import com.paktalin.chess.pieces.Queen;
...
@@ -11,17 +9,17 @@ import com.paktalin.chess.pieces.Queen;
class
QueenMoveStrategyTest
extends
MoveStrategyTest
{
class
QueenMoveStrategyTest
extends
MoveStrategyTest
{
@Override
@Override
void
putPieceOnBoard
()
{
MoveStrategy
moveStrategy
()
{
board
.
placePiece
(
new
Queen
(
Piece
.
Color
.
Black
),
currentPosition
);
return
new
QueenMoveStrategy
(
);
}
}
@Override
@Override
void
setA
ccessiblePosition
()
{
Position
a
ccessiblePosition
()
{
accessiblePosition
=
Position
.
create
(
"d3"
);
return
Position
.
create
(
"d3"
);
}
}
@Override
@Override
void
setN
otAccessiblePosition
()
{
Position
n
otAccessiblePosition
()
{
notAccessiblePosition
=
Position
.
create
(
"f7"
);
return
Position
.
create
(
"f7"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/pieces/PieceTest.java
View file @
90aeec8c
...
@@ -30,6 +30,8 @@ abstract class PieceTest {
...
@@ -30,6 +30,8 @@ abstract class PieceTest {
abstract
Piece
createPiece
(
Piece
.
Color
color
);
abstract
Piece
createPiece
(
Piece
.
Color
color
);
abstract
void
setExpectedStrength
();
abstract
void
setExpectedStrength
();
@Test
@Test
void
testCreate
()
{
void
testCreate
()
{
Piece
whitePiece
=
createPiece
(
White
);
Piece
whitePiece
=
createPiece
(
White
);
...
...
This diff is collapsed.
Click to expand it.
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