Commit 75c7d162 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Add tests to verify Black Pawn movements

parent 89cd07c2
......@@ -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é",
......
import { Expect, Test } from "alsatian";
import {parseMoveString,Move} from "../src/movements"
import {Position, equals} from "../src/position"
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();
}
}
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();
}
}
......@@ -12,5 +12,8 @@
},
"exclude": [
"node_modules"
],
"include": [
"src/main/ts/**/*"
]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment