Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 98d6bf1a rédigé par Gerson Sunyé's avatar Gerson Sunyé
Parcourir les fichiers

Separate unit tests into several files to simplify readability

- Create one file containing one test class for each piece
- Update README.
parent 6338564e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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();
}
......
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
}
}
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
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:
}
}
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
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
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter