Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stewan Lheureux
Échecs féeriques
Commits
75c7d162
Commit
75c7d162
authored
Mar 09, 2020
by
Gerson Sunyé
Browse files
Add tests to verify Black Pawn movements
parent
89cd07c2
Changes
11
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
75c7d162
...
...
@@ -6,7 +6,8 @@
"scripts"
:
{
"build"
:
"tsc"
,
"dev"
:
"ts-node-dev --respawn --transpileOnly ./src/main.ts"
,
"serve"
:
"tsc && node ./build/main.js"
"serve"
:
"tsc && node ./build/main.js"
,
"test"
:
"alsatian './src/test/ts/**/*.spec.ts' "
},
"keywords"
:
[],
"author"
:
"Gerson Sunyé"
,
...
...
spec/movements-spec.ts
deleted
100644 → 0
View file @
89cd07c2
import
{
Expect
,
Test
}
from
"
alsatian
"
;
import
{
parseMoveString
,
Move
}
from
"
../src/movements
"
import
{
Position
,
equals
}
from
"
../src/position
"
src/chessboard.ts
→
src/
main/ts/
chessboard.ts
View file @
75c7d162
File moved
src/main.ts
→
src/main
/ts/main
.ts
View file @
75c7d162
File moved
src/move-validation.ts
→
src/
main/ts/
move-validation.ts
View file @
75c7d162
File moved
src/movements.ts
→
src/
main/ts/
movements.ts
View file @
75c7d162
File moved
src/piece.ts
→
src/
main/ts/
piece.ts
View file @
75c7d162
File moved
src/position.ts
→
src/
main/ts/
position.ts
View file @
75c7d162
File moved
s
pec
/move-validation
-
spec.ts
→
s
rc/test/ts
/move-validation
.
spec.ts
View file @
75c7d162
import
{
Expect
,
Test
}
from
"
alsatian
"
;
import
*
as
isPossible
from
'
../
src
/move-validation
'
import
*
as
pieces
from
'
../
src
/piece
'
import
{
Chessboard
,
createEmptyChessboard
,
putPiece
}
from
'
../
src
/chessboard
'
;
import
{
Position
,
position
}
from
'
../
src
/position
'
;
import
{
Move
,
move
}
from
'
../
src
/movements
'
;
import
{
Expect
,
Test
,
Setup
}
from
"
alsatian
"
;
import
*
as
isPossible
from
'
../
../main/ts
/move-validation
'
import
*
as
pieces
from
'
../
../main/ts
/piece
'
import
{
Chessboard
,
createEmptyChessboard
,
putPiece
}
from
'
../
../main/ts
/chessboard
'
;
import
{
Position
,
position
}
from
'
../
../main/ts
/position
'
;
import
{
Move
,
move
}
from
'
../
../main/ts
/movements
'
;
let
chessboard
:
Chessboard
;
...
...
@@ -66,3 +66,80 @@ const moveE4_D6 : Move = move(positionE4, positionD6);
// Impossible moves
const
moveE4_C7
:
Move
=
move
(
positionE4
,
positionC7
);
const
moveE4_B2
:
Move
=
move
(
positionE4
,
positionB2
);
export
class
TestBlackPawnMoves
{
chessboard
:
Chessboard
@
Setup
beforeEach
(){
chessboard
=
createEmptyChessboard
();
}
@
Test
(
"
Pawns can move forward
"
)
testPawnCanMoveForward
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
let
singleForward
:
Move
=
{
from
:
positionA7
,
to
:
positionA6
,
isValid
:
true
};
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
singleForward
)).
toBeTruthy
();
}
@
Test
(
"
Pawns cannot move backward
"
)
testPawnCannotMoveBackward
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
let
singleForward
:
Move
=
{
from
:
positionA7
,
to
:
positionA8
,
isValid
:
true
};
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
singleForward
)).
not
.
toBeTruthy
();
}
@
Test
(
"
When in the initial position, paws can move 2 squares forward
"
)
testPawnInitialMove
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
let
doubleForward
:
Move
=
{
from
:
positionA7
,
to
:
positionA5
,
isValid
:
true
};
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
doubleForward
)).
toBeTruthy
();
}
@
Test
(
"
When a paws has already moved, it cannot move 2 squares forward
"
)
testCannotMoveTwoSquaresIfAlreadyMoved
()
{
putPiece
(
chessboard
,
positionC6
,
pieces
.
blackPawn
);
let
doubleForward
:
Move
=
{
from
:
positionC6
,
to
:
positionC4
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
doubleForward
)).
not
.
toBeTruthy
();
}
@
Test
(
"
When in the initial position, pawns cannot move 3 squares forward
"
)
testCannotMoveThreeSquares
()
{
putPiece
(
chessboard
,
positionC6
,
pieces
.
blackPawn
);
let
tripleForward
:
Move
=
{
from
:
positionA7
,
to
:
positionA4
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
tripleForward
)).
not
.
toBeTruthy
();
}
@
Test
(
"
When in face of another piece, pawns cannot move foreward
"
)
testPawnCannotMoveForwardToFullSquare
()
{
putPiece
(
chessboard
,
positionA6
,
pieces
.
whitePawn
);
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
let
singleForward
:
Move
=
{
from
:
positionA7
,
to
:
positionA6
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
singleForward
)).
not
.
toBeTruthy
();
}
@
Test
(
"
Pawns cannot capture an empty square
"
)
testPawnCannotCaptureEmptySquare
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
let
diagonalCapture
:
Move
=
{
from
:
positionA7
,
to
:
positionB6
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
diagonalCapture
)).
not
.
toBeTruthy
();
}
@
Test
(
"
Pawns cannot capture pieces of the same color
"
)
testPawnCannotCaptureSameColor
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
putPiece
(
chessboard
,
positionB6
,
pieces
.
blackKing
);
let
diagonalCapture
:
Move
=
{
from
:
positionA7
,
to
:
positionB6
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
diagonalCapture
)).
not
.
toBeTruthy
();
}
@
Test
(
"
Pawns can capture pieces of a different color
"
)
testPawnCanCaptureDifferentColorPieces
()
{
putPiece
(
chessboard
,
positionA7
,
pieces
.
blackPawn
);
putPiece
(
chessboard
,
positionB6
,
pieces
.
whiteQueen
);
let
diagonalCapture
:
Move
=
{
from
:
positionA7
,
to
:
positionB6
,
isValid
:
true
}
Expect
(
isPossible
.
blackPawnMove
(
chessboard
,
diagonalCapture
)).
toBeTruthy
();
}
}
src/test/ts/movements.spec.ts
0 → 100644
View file @
75c7d162
import
{
Expect
,
Test
}
from
"
alsatian
"
;
import
{
parseMoveString
,
Move
}
from
"
../../main/ts/movements
"
import
{
Position
,
equals
}
from
"
../../main/ts/position
"
export
class
ParseMoveStringTest
{
@
Test
(
"
A2-A4
"
)
testParseA2_A4
()
{
let
move
:
Move
=
parseMoveString
(
"
A2-A4
"
);
let
expectedFrom
:
Position
=
{
file
:
0
,
rank
:
1
}
let
expectedTo
:
Position
=
{
file
:
0
,
rank
:
3
}
Expect
(
move
.
isValid
).
toBeTruthy
();
Expect
(
equals
(
expectedFrom
,
move
.
from
!
)).
toBeTruthy
();
Expect
(
equals
(
expectedTo
,
move
.
to
!
)).
toBeTruthy
();
}
@
Test
(
"
B8-B3
"
)
testParseB8_B3
()
{
let
move
:
Move
=
parseMoveString
(
"
B8-B3
"
);
let
expectedFrom
:
Position
=
{
file
:
1
,
rank
:
7
}
let
expectedTo
:
Position
=
{
file
:
1
,
rank
:
2
}
Expect
(
move
.
isValid
).
toBeTruthy
();
Expect
(
equals
(
expectedFrom
,
move
.
from
!
)).
toBeTruthy
();
Expect
(
equals
(
expectedTo
,
move
.
to
!
)).
toBeTruthy
();
}
@
Test
(
"
H8-H3
"
)
testParseH8_H3
()
{
let
move
:
Move
=
parseMoveString
(
"
H8-H3
"
);
let
expectedFrom
:
Position
=
{
file
:
7
,
rank
:
7
}
let
expectedTo
:
Position
=
{
file
:
7
,
rank
:
2
}
Expect
(
move
.
isValid
).
toBeTruthy
();
Expect
(
equals
(
expectedFrom
,
move
.
from
!
)).
toBeTruthy
();
Expect
(
equals
(
expectedTo
,
move
.
to
!
)).
toBeTruthy
();
}
@
Test
(
"
a1-h8 == A1-H8
"
)
testParseLowerCase
()
{
let
lowercaseMove
:
Move
=
parseMoveString
(
"
a1-h8
"
);
let
uppercaseMove
:
Move
=
parseMoveString
(
"
A1-H8
"
);
Expect
(
lowercaseMove
.
isValid
).
toBeTruthy
();
Expect
(
uppercaseMove
.
isValid
).
toBeTruthy
();
Expect
(
equals
(
lowercaseMove
.
from
!
,
uppercaseMove
.
from
!
)).
toBeTruthy
();
Expect
(
equals
(
lowercaseMove
.
to
!
,
uppercaseMove
.
to
!
)).
toBeTruthy
();
}
}
tsconfig.json
View file @
75c7d162
...
...
@@ -12,5 +12,8 @@
},
"exclude"
:
[
"node_modules"
],
"include"
:
[
"src/main/ts/**/*"
]
}
Write
Preview
Supports
Markdown
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