Code smells
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using FluentAssertions;
|
||||
using Gameboard.ShogiUI.BoardState;
|
||||
using Gameboard.ShogiUI.BoardState.Pieces;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -81,7 +82,6 @@ namespace Gameboard.ShogiUI.UnitTests.BoardState
|
||||
shogi.Board[0, 3].WhichPiece.Should().Be(WhichPiece.Pawn);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void PreventInvalidMoves_MoveFromEmptyPosition()
|
||||
{
|
||||
@@ -245,30 +245,110 @@ namespace Gameboard.ShogiUI.UnitTests.BoardState
|
||||
var shogi = new ShogiBoard(moves);
|
||||
shogi.PrintStateAsAscii();
|
||||
|
||||
// Prerequisite
|
||||
// Prerequisites
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight);
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn);
|
||||
|
||||
// Act | Assert - It is P1 turn
|
||||
// try illegally placing Knight from the hand.
|
||||
/// try illegally placing Knight from the hand.
|
||||
shogi.Board[7, 8].Should().BeNull();
|
||||
var moveSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Knight, To = new Vector2(7, 8) });
|
||||
shogi.PrintStateAsAscii();
|
||||
moveSuccess.Should().BeFalse();
|
||||
var dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Knight, To = new Vector2(7, 8) });
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
shogi.Board[7, 8].Should().BeNull();
|
||||
dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Knight, To = new Vector2(7, 7) });
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
shogi.Board[7, 7].Should().BeNull();
|
||||
|
||||
// Assert
|
||||
//var pawnDropSuccess = shogi.Move(new Move)
|
||||
/// try illegally placing Pawn from the hand
|
||||
dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Pawn, To = new Vector2(7, 8) });
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn);
|
||||
shogi.Board[7, 8].Should().BeNull();
|
||||
|
||||
// Assert
|
||||
/// try illegally placing Lance from the hand
|
||||
dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Lance, To = new Vector2(7, 8) });
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
shogi.Board[7, 8].Should().BeNull();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PreventInvalidDrop_Check()
|
||||
{
|
||||
// Arrange
|
||||
var moves = new[]
|
||||
{
|
||||
// P1 Pawn
|
||||
new Move { From = new Vector2(2, 2), To = new Vector2(2, 3) },
|
||||
// P2 Pawn
|
||||
new Move { From = new Vector2(8, 6), To = new Vector2(8, 5) },
|
||||
// P1 Bishop, check
|
||||
new Move { From = new Vector2(1, 1), To = new Vector2(6, 6) },
|
||||
// P2 Gold, block check
|
||||
new Move { From = new Vector2(5, 8), To = new Vector2(5, 7) },
|
||||
// P1 arbitrary move
|
||||
new Move { From = new Vector2(0, 2), To = new Vector2(0, 3) },
|
||||
// P2 Bishop
|
||||
new Move { From = new Vector2(7, 7), To = new Vector2(8, 6) },
|
||||
// P1 Bishop takes P2 Lance
|
||||
new Move { From = new Vector2(6, 6), To = new Vector2(8, 8) },
|
||||
// P2 Bishop
|
||||
new Move { From = new Vector2(8, 6), To = new Vector2(7, 7) },
|
||||
// P1 arbitrary move
|
||||
new Move { From = new Vector2(0, 3), To = new Vector2(0, 4) },
|
||||
// P2 Bishop, check
|
||||
new Move { From = new Vector2(7, 7), To = new Vector2(2, 2) },
|
||||
};
|
||||
var shogi = new ShogiBoard(moves);
|
||||
|
||||
// Prerequisites
|
||||
shogi.InCheck.Should().Be(WhichPlayer.Player1);
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
|
||||
// Act - P1 tries to place a Lance while in check.
|
||||
var dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Lance, To = new Vector2(4, 4) });
|
||||
|
||||
// Assert
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Board[4, 4].Should().BeNull();
|
||||
shogi.InCheck.Should().Be(WhichPlayer.Player1);
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PreventInvalidDrop_Capture()
|
||||
{
|
||||
// Arrange
|
||||
var moves = new[]
|
||||
{
|
||||
// P1 Pawn
|
||||
new Move { From = new Vector2(2, 2), To = new Vector2(2, 3) },
|
||||
// P2 Pawn
|
||||
new Move { From = new Vector2(6, 6), To = new Vector2(6, 5) },
|
||||
// P1 Bishop, capture P2 Pawn, check
|
||||
new Move { From = new Vector2(1, 1), To = new Vector2(6, 6) },
|
||||
// P2 Gold, block check
|
||||
new Move { From = new Vector2(5, 8), To = new Vector2(5, 7) },
|
||||
// P1 Bishop capture P2 Bishop
|
||||
new Move { From = new Vector2(6, 6), To = new Vector2(7, 7) },
|
||||
// P2 arbitrary move
|
||||
new Move { From = new Vector2(0, 8), To = new Vector2(0, 7) },
|
||||
};
|
||||
var shogi = new ShogiBoard(moves);
|
||||
|
||||
// Prerequisites
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
|
||||
|
||||
// Act - P1 tries to place Bishop from hand to an already-occupied position
|
||||
var dropSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Bishop, To = new Vector2(4, 0) });
|
||||
|
||||
// Assert
|
||||
dropSuccess.Should().BeFalse();
|
||||
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
|
||||
shogi.Board[4, 0].WhichPiece.Should().Be(WhichPiece.King);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Reference in New Issue
Block a user