From ddce19c83bcb9b2b005fbcde443f2fb9fb1a0112 Mon Sep 17 00:00:00 2001 From: Evan JOUBERT <evan.joubert@etu.univ-nantes.fr> Date: Sun, 5 Apr 2020 17:08:18 +0200 Subject: [PATCH] test validation mouvement --- src/test/ts/king-move-validation.spec.ts | 77 ++++++++++++++++++++++- src/test/ts/queen-move-validation.spec.ts | 43 ++++++++++++- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/src/test/ts/king-move-validation.spec.ts b/src/test/ts/king-move-validation.spec.ts index 247de03..4f37cf9 100644 --- a/src/test/ts/king-move-validation.spec.ts +++ b/src/test/ts/king-move-validation.spec.ts @@ -1,8 +1,53 @@ import { Expect, Test, Setup} from "alsatian"; import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; - +import { Position, position } from '../../main/ts/position'; +import * as isPossible from '../../main/ts/move-validation'; +import * as pieces from '../../main/ts/piece'; +import { Move, move } from '../../main/ts/movements'; let chessboard : Chessboard; +const positionC2 : Position = position(2, 1); // C2 +const positionC3 : Position = position(2, 2); // C3 +const positionC4 : Position = position(2, 3); // C4 +const positionC6 : Position = position(2, 5); // C6 + +const positionD3 : Position = position(3, 2); // D3 +const positionD4 : Position = position(3, 3); // D4 +const positionD5 : Position = position(3, 4); // D5 + +const positionE2 : Position = position(4, 1); // E2 +const positionE3 : Position = position(4, 2); // E3 +const positionE4 : Position = position(4, 3); // E4 +const positionE5 : Position = position(4, 4);// E5 +const positionE6 : Position = position(4, 5);// E6 + +const positionF3 : Position = position(5, 2);// F3 +const positionF4 : Position = position(5, 3);// F4 +const positionF5 : Position = position(5, 4);// F5 + +const positionG2 : Position = position(6, 1);// G2 +const positionG4 : Position = position(6, 3);// G4 +const positionG6 : Position = position(6, 5);// G6 + +const moveE4_D4 : Move = move(positionE4, positionD4); +const moveE4_D5 : Move = move(positionE4, positionD5); +const moveE4_E3 : Move = move(positionE4, positionE3); +const moveE4_E5 : Move = move(positionE4, positionE5); +const moveE4_F3 : Move = move(positionE4, positionF3); +const moveE4_F4: Move = move(positionE4, positionF4); +const moveE4_F5 : Move = move(positionE4, positionF5); +const moveE4_D3 : Move = move(positionE4, positionD3); + +const moveE4_C2 : Move = move(positionE4, positionC2); +const moveE4_C3 : Move = move(positionE4, positionC3); +const moveE4_C4 : Move = move(positionE4, positionC4); +const moveE4_C6 : Move = move(positionE4, positionC6); +const moveE4_E2 : Move = move(positionE4, positionE2); +const moveE4_E6: Move = move(positionE4, positionE6); +const moveE4_G2 : Move = move(positionE4, positionG2); +const moveE4_G4 : Move = move(positionE4, positionG4); +const moveE4_G6 : Move = move(positionE4, positionG6); + export class TestKingMoves { @Setup @@ -10,19 +55,39 @@ export class TestKingMoves { // TODO: // Initialize an empty chessboard // Place a black King on E4 + chessboard = createEmptyChessboard(); + putPiece(chessboard,positionE4,pieces.blackKing); + } @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 + + Expect(isPossible.kingMove(chessboard, moveE4_D4)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_D5)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_E3)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_E5)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_F3)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_F4)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_F5)).toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_D3)).toBeTruthy(); } @Test("A King cannot move more than 1 square") testCannotMoveMoreThanOneSquare() { // TODO: // Check it cannot move to squares C2, C3, C4, C6, E2, E6, G2, G4, and G6 - + Expect(isPossible.kingMove(chessboard, moveE4_C2)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_C3)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_C4)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_C6)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_E2)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_E6)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_G2)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_G4)).not.toBeTruthy(); + Expect(isPossible.kingMove(chessboard, moveE4_G6)).not.toBeTruthy(); } @Test("A King cannot capure pieces from the same color") @@ -30,6 +95,9 @@ export class TestKingMoves { // TODO: // Place a black Pawn on E5 // Check the King cannot move to E5. + putPiece(chessboard,positionE5,pieces.blackPawn); + Expect(isPossible.kingMove(chessboard, moveE4_E5)).not.toBeTruthy(); + } @Test("A King can capure pieces from a different color") @@ -37,5 +105,8 @@ export class TestKingMoves { // TODO: // Place a white Pawn on E5 // Check the King can move to E5. + putPiece(chessboard,positionE5,pieces.whitePawn); + Expect(isPossible.kingMove(chessboard, moveE4_E5)).toBeTruthy(); + } -} \ No newline at end of file +} diff --git a/src/test/ts/queen-move-validation.spec.ts b/src/test/ts/queen-move-validation.spec.ts index 549e344..397a0ef 100644 --- a/src/test/ts/queen-move-validation.spec.ts +++ b/src/test/ts/queen-move-validation.spec.ts @@ -1,7 +1,29 @@ import { Expect, Test, Setup} from "alsatian"; import { Chessboard, createEmptyChessboard, putPiece } from '../../main/ts/chessboard'; +import { Position, position } from '../../main/ts/position'; +import * as isPossible from '../../main/ts/move-validation'; +import * as pieces from '../../main/ts/piece'; +import { Move, move } from '../../main/ts/movements'; let chessboard : Chessboard; +const positionA4 : Position = position(0, 3) // A4 + +const positionE1 : Position = position(4, 0) // E1 +const positionE4 : Position = position(4, 3) // E4 +const positionE8 : Position = position(4, 7) // E8 + +const positionF4 : Position = position(5, 3);//F4 + +const positionH4 : Position = position(7, 3) // H4 + + +const moveE4_A4 : Move = move(positionE4, positionA4); +const moveE4_H4 : Move = move(positionE4, positionH4); + +const moveE4_E1 : Move = move(positionE4, positionE1); +const moveE4_E8 : Move = move(positionE4, positionE8); + +const moveE4_F4: Move = move(positionE4, positionF4); export class TestQueenMoves { @Setup @@ -9,6 +31,9 @@ export class TestQueenMoves { // TODO: // Initialize an empty chessboard // Place a white Queen on E4 + + chessboard = createEmptyChessboard(); + putPiece(chessboard,positionE4,pieces.whiteQueen); } @Test("A Queen can move diagonally") @@ -22,12 +47,16 @@ export class TestQueenMoves { testCanMoveHorizontally() { // TODO: // Check the following moves are possible: moveE4_H4, moveE4_A4 + Expect(isPossible.queenMove(chessboard, moveE4_H4)).toBeTruthy(); + Expect(isPossible.queenMove(chessboard, moveE4_A4)).toBeTruthy(); } @Test("A Queen can move vertically") testCanMoveVertically() { // TODO: // Check the following moves are possible: moveE4_E1, moveE4_E8 + Expect(isPossible.queenMove(chessboard, moveE4_E8)).toBeTruthy(); + Expect(isPossible.queenMove(chessboard, moveE4_E1)).toBeTruthy(); } @Test("A Queen can only move horizontally, vertically, and diagonally") @@ -41,19 +70,29 @@ export class TestQueenMoves { // TODO: // Place a white Pawn on C6 and a black Pawn on F4 // Check the moves moveE4_A8 and moveE4_H4 are impossible + putPiece(chessboard,positionF4,pieces.blackPawn); + Expect(isPossible.queenMove(chessboard, moveE4_H4)).not.toBeTruthy(); + + } @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 + // Check the moveS moveE4_H4 is impossible + putPiece(chessboard,positionH4,pieces.whitePawn); + Expect(isPossible.queenMove(chessboard, moveE4_H4)).not.toBeTruthy(); + } @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 + // Check the move moveE4_H4 is possible + putPiece(chessboard,positionH4,pieces.blackPawn); + Expect(isPossible.queenMove(chessboard, moveE4_H4)).toBeTruthy(); + } } \ No newline at end of file -- GitLab