From 98d6bf1acf9a677b8065f5999ea3eb5278815b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerson=20Suny=C3=A9?= <sunye@protonmail.com> Date: Tue, 10 Mar 2020 09:25:20 +0100 Subject: [PATCH] Separate unit tests into several files to simplify readability - Create one file containing one test class for each piece - Update README. --- README.adoc | 21 +++---- src/test/ts/bishop-move-validation.spec.ts | 53 +++++++++++++++++ src/test/ts/king-move-validation.spec.ts | 41 +++++++++++++ src/test/ts/knight-move-validation.spec.ts | 52 ++++++++++++++++ ...n.spec.ts => pawn-move-validation.spec.ts} | 0 src/test/ts/queen-move-validation.spec.ts | 59 +++++++++++++++++++ src/test/ts/rook-move-validation.spec.ts | 53 +++++++++++++++++ 7 files changed, 269 insertions(+), 10 deletions(-) create mode 100644 src/test/ts/bishop-move-validation.spec.ts create mode 100644 src/test/ts/king-move-validation.spec.ts create mode 100644 src/test/ts/knight-move-validation.spec.ts rename src/test/ts/{move-validation.spec.ts => pawn-move-validation.spec.ts} (100%) create mode 100644 src/test/ts/queen-move-validation.spec.ts create mode 100644 src/test/ts/rook-move-validation.spec.ts diff --git a/README.adoc b/README.adoc index cce1f7a..ced2f86 100644 --- a/README.adoc +++ b/README.adoc @@ -142,7 +142,7 @@ Le paramètre `move` contient 2 coordonnées de type `Position`, représentant l Les coordonnées indiquent *toujours* des cases à l'intérieur de l'échiquier, c'est à dire, une colonne entre `A` et `H` et une ligne entre `1` et `8`. Donc, il n'y a pas besoin de vérifier si un déplacement conduit une pièce à l'extérieur de l'échiquier. -Les tests unitaires de la fonction `blackPawnMove()` ont déjà été implémentés, vous les trouverez dans le fichier `./src/test/ts/move-validation-spec.ts`. +Les tests unitaires de la fonction `blackPawnMove()` ont déjà été implémentés, vous les trouverez dans le fichier `./src/test/ts/pawn-move-validation-spec.ts`. *Vous devez compléter tous les squelettes de tests unitaires fournis à l'intérieur de ce fichier !* Vous devez procéder par itérations successives, n'essayez pas d'implémenter les fonctions d'un seul trait. Observez le cycle de développement suivant: @@ -178,9 +178,10 @@ export function rookMove(board: Chessboard, move: Move): boolean { [source,ts] ---- -// Dans le fichier "move-validation.spec.ts" -export class TestRockMoves { - chessboard : Chessboard +// Dans le fichier "rook-move-validation.spec.ts" +let chessboard : Chessboard; + +export class TestRookMoves { @Setup beforeEach(){ chessboard = createEmptyChessboard(); @@ -190,8 +191,8 @@ export class TestRockMoves { putPiece(chessboard, positionE4, pieces.blackPawn); } - @Test("A roock can move horizontally") - testRockCanMoveHorizontally() { + @Test("A rook can move horizontally") + testCanMoveHorizontally() { // Les variable "moveE4_H4" et "moveE4_14" ont été créées au début // du module pour simplifier le code des tests. // Le déplacement doit être possible: @@ -219,12 +220,12 @@ export function rookMove(board: Chessboard, move: Move): boolean { [source,ts] ---- -// Dans le fichier "move-validation.spec.ts" -export class TestRockMoves { +// Dans le fichier "rook-move-validation.spec.ts" +export class TestRocoMoves { // (...) - @Test("A roock can move vertically") - testRockCanMoveVertically() { + @Test("A rook can move vertically") + testCanMoveVertically() { Expect(isPossible.rookMove(chessboard, moveE4_E8)).toBeTruthy(); Expect(isPossible.rookMove(chessboard, moveE4_E1)).toBeTruthy(); } diff --git a/src/test/ts/bishop-move-validation.spec.ts b/src/test/ts/bishop-move-validation.spec.ts new file mode 100644 index 0000000..45f6cba --- /dev/null +++ b/src/test/ts/bishop-move-validation.spec.ts @@ -0,0 +1,53 @@ +import { Expect, Test, Setup} from "alsatian"; +import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; + +let chessboard : Chessboard; + +export class TestBishopMoves { + @Setup + beforeEach() { + // TODO: + // Initialize an empty chessboard + // Place a black Bishop on E4 + } + + @Test("A Bishop can move diagonally") + testCanMoveDiagonally() { + // TODO: + // Check the following moves are possible: + // moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1 + } + + @Test("A Bishop cannot move horizontally") + testCannotMoveHorizontally() { + // TODO: + // Check the following moves are impossible: moveE4_H4, moveE4_A4 + } + + @Test("A Bishop cannot move vertically") + testCannotMoveVertically() { + // TODO: + // Check the following moves are impossible: moveE4_E1, moveE4_E8 + } + + @Test("A Bishop can capture a piece from another color") + testCanCaptureDifferentColor() { + // TODO: + // Place a white Pawn on A8 + // Check the move moveE4_A8 is possible + } + + @Test("A Bishop cannot capture a piece from the same color") + testCannotCaptureSameColor() { + // TODO: + // Place a black Pawn on A8 + // Check the move moveE4_A8 is impossible + } + + @Test("A Bishop cannot leap other pieces") + testCannotLeap() { + // TODO: + // Place a white Pawn on C6 + // Check the move moveE4_A8 is impossible + } +} diff --git a/src/test/ts/king-move-validation.spec.ts b/src/test/ts/king-move-validation.spec.ts new file mode 100644 index 0000000..168f9b6 --- /dev/null +++ b/src/test/ts/king-move-validation.spec.ts @@ -0,0 +1,41 @@ +import { Expect, Test, Setup} from "alsatian"; +import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; + +let chessboard : Chessboard; + +export class TestKingMoves { + + @Setup + beforeEach() { + // TODO: + // Initialize an empty chessboard + // Place a black King on E4 + } + + @Test("A King can move 1 square in all directions") + testCanMoveOneSquare() { + // TODO: + // Check it can move to squares D3, D4, D5, E3, E5, F3, F4, and F5 + } + + @Test("A King cannot move more than 1 square") + testCannotMoveMoreThanOneSquare() { + // TODO: + // Check it cannot move to squares C2, C3, C4, C6, D4, and F4 + + } + + @Test("A King cannot capure pieces from the same color") + testCannotCaptureSameColor() { + // TODO: + // Place a black Pawn on E5 + // Check the King cannot move to E5. + } + + @Test("A King can capure pieces from a different color") + testCanCaptureSameColor() { + // TODO: + // Place a white Pawn on E5 + // Check the King can move to E5. + } +} \ No newline at end of file diff --git a/src/test/ts/knight-move-validation.spec.ts b/src/test/ts/knight-move-validation.spec.ts new file mode 100644 index 0000000..884d7cc --- /dev/null +++ b/src/test/ts/knight-move-validation.spec.ts @@ -0,0 +1,52 @@ +import { Expect, Test, Setup} from "alsatian"; +import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; + +let chessboard : Chessboard; + +export class TestKnightMoves { + @Setup + beforeEach() { + // TODO: + // Initialize an empty chessboard + } + + @Test("A Knight can move two squares horizontally and one square vertically") + testCanMoveTwoHorizontalAndOneVertical() { + // TODO: + } + + @Test("A Knight can move two squares vertically and one square horizontally") + testCanMoveTwoVerticalAndOneHorizontal() { + // TODO: + } + + @Test("A Knight can leap other pieces") + testCanLeapOtherPieces() { + // TODO: + } + + @Test("A Knight cannot move diagonally") + testCannotMoveDiagonally() { + // TODO: + } + + @Test("A Knight cannot move horizontally") + testCannotMoveHorizontally() { + // TODO: + } + + @Test("A Knight cannot move vertically") + testCannotMoveVertically() { + // TODO: + } + + @Test("A Knight can capture a piece from another color") + testCanCaptureAnotherColor() { + // TODO: + } + + @Test("A Knight cannot capture a piece from the same color") + testCannotCaptureSameColor() { + // TODO: + } +} diff --git a/src/test/ts/move-validation.spec.ts b/src/test/ts/pawn-move-validation.spec.ts similarity index 100% rename from src/test/ts/move-validation.spec.ts rename to src/test/ts/pawn-move-validation.spec.ts diff --git a/src/test/ts/queen-move-validation.spec.ts b/src/test/ts/queen-move-validation.spec.ts new file mode 100644 index 0000000..549e344 --- /dev/null +++ b/src/test/ts/queen-move-validation.spec.ts @@ -0,0 +1,59 @@ +import { Expect, Test, Setup} from "alsatian"; +import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; + +let chessboard : Chessboard; + +export class TestQueenMoves { + @Setup + beforeEach() { + // TODO: + // Initialize an empty chessboard + // Place a white Queen on E4 + } + + @Test("A Queen can move diagonally") + testCanMoveDiagonally() { + // TODO: + // Check the following moves are possible: + // moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1 + } + + @Test("A Queen can move horizontally") + testCanMoveHorizontally() { + // TODO: + // Check the following moves are possible: moveE4_H4, moveE4_A4 + } + + @Test("A Queen can move vertically") + testCanMoveVertically() { + // TODO: + // Check the following moves are possible: moveE4_E1, moveE4_E8 + } + + @Test("A Queen can only move horizontally, vertically, and diagonally") + testForbiddenMoves() { + // TODO: + // Check the following moves are impossible: moveE4_C7, moveE4_B2 + } + + @Test("A Queen cannot leap other pieces") + testCannotLeap() { + // TODO: + // Place a white Pawn on C6 and a black Pawn on F4 + // Check the moves moveE4_A8 and moveE4_H4 are impossible + } + + @Test("A Queen cannot capure pieces from the same color") + testCannotCaptureSameColor() { + // TODO: + // Place a white Pawn on H4 + // Check the move moveE4_H4 is impossible + } + + @Test("A Queen can capure pieces from a different color") + testCanCaptureDifferentColor() { + // TODO: + // Place a black Pawn on H4 + // Check the move moveE4_H4 is possible + } +} \ No newline at end of file diff --git a/src/test/ts/rook-move-validation.spec.ts b/src/test/ts/rook-move-validation.spec.ts new file mode 100644 index 0000000..a4e6e23 --- /dev/null +++ b/src/test/ts/rook-move-validation.spec.ts @@ -0,0 +1,53 @@ +import { Expect, Test, Setup} from "alsatian"; +import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; + +let chessboard : Chessboard; + +export class TestRookMoves { + @Setup + beforeEach() { + // TODO: + // Initialize an empty chessboard + // Place a white Rook on E4 + } + + @Test("A rook can move horizontally") + testCanMoveHorizontally() { + // TODO: + // Check the following moves are possible: moveE4_H4, moveE4_A4 + } + + @Test("A rook can move vertically") + testCanMoveVertically() { + // TODO: + // Check the following moves are possible: moveE4_E1, moveE4_E8 + } + + @Test("A rook cannot move diagonally") + testCannotMoveDiagonally() { + // TODO: + // Check the following moves are impossible: + // moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1 + } + + @Test("A rook can capture a piece from different color") + testCanCaptureDifferentColor() { + // TODO: + // Place a black Pawn on H4 + // Check the move moveE4_H4 is possible + } + + @Test("A rook cannot capture a piece from the same color") + testCannotCaptureSameColor() { + // TODO: + // Place a white Pawn on H4 + // Check the move moveE4_H4 is impossible + } + + @Test("A Rook cannot leap other pieces") + testCannotLeap() { + // TODO: + // Place a black Pawn on F4 + // Check the move moveE4_H4 is impossible + } +} -- GitLab