This commit is contained in:
2021-12-29 22:11:49 -06:00
parent 9ec91615a3
commit 499e480851
4 changed files with 57 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
using FluentAssertions;
using FluentAssertions.Execution;
using System;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
@@ -14,62 +15,65 @@ namespace Shogi.Domain.UnitTests
this.output = output;
}
//[Fact]
//public void InitializeBoardStateWithMoves()
//{
// var board = new ShogiBoardState();
// var rules = new StandardRules(board);
// var moves = new[]
// {
// // P1 Pawn
// new Move("A3", "A4")
// };
// var shogi = new Shogi(moves);
// shogi.Board["A3"].Should().BeNull();
// shogi.Board["A4"].WhichPiece.Should().Be(WhichPiece.Pawn);
//}
[Fact]
public void MoveAPieceToAnEmptyPosition()
{
// Arrange
var board = new ShogiBoardState();
var shogi = new Shogi(board);
board["A4"].Should().BeNull();
var expectedPiece = board["A3"];
expectedPiece.Should().NotBeNull();
//[Fact]
//public void AllowValidMoves_AfterCheck()
//{
// // Arrange
// var moves = new[]
// {
// // P1 Pawn
// new Move("C3", "C4"),
// // P2 Pawn
// new Move("G7", "G6"),
// // P1 Bishop puts P2 in check
// new Move("B2", "G7"),
// };
// var shogi = new Shogi(moves);
// shogi.InCheck.Should().Be(WhichPlayer.Player2);
// Act
shogi.Move("A3", "A4", false);
// // Act - P2 is able to un-check theirself.
// /// P2 King moves out of check
// var moveSuccess = shogi.Move(new Move("E9", "E8"));
// Assert
board["A3"].Should().BeNull();
board["A4"].Should().Be(expectedPiece);
}
// // Assert
// using var _ = new AssertionScope();
// moveSuccess.Should().BeTrue();
// shogi.InCheck.Should().BeNull();
//}
[Fact]
public void AllowValidMoves_AfterCheck()
{
// Arrange
var board = new ShogiBoardState();
var shogi = new Shogi(board);
// P1 Pawn
shogi.Move("C3", "C4", false);
// P2 Pawn
shogi.Move("G7", "G6", false);
// P1 Bishop puts P2 in check
shogi.Move("B2", "G7", false);
board.InCheck.Should().Be(WhichPlayer.Player2);
//[Fact]
//public void PreventInvalidMoves_MoveFromEmptyPosition()
//{
// // Arrange
// var shogi = new Shogi();
// shogi.Board["D5"].Should().BeNull();
// Act - P2 is able to un-check theirself.
/// P2 King moves out of check
shogi.Move("E9", "E8", false);
// // Act
// var moveSuccess = shogi.Move(new Move("D5", "D6"));
// Assert
using (new AssertionScope())
{
board.InCheck.Should().BeNull();
}
}
// // Assert
// moveSuccess.Should().BeFalse();
// shogi.Board["D5"].Should().BeNull();
// shogi.Board["D6"].Should().BeNull();
//}
[Fact]
public void PreventInvalidMoves_MoveFromEmptyPosition()
{
// Arrange
var board = new ShogiBoardState();
var shogi = new Shogi(board);
board["D5"].Should().BeNull();
// Act
var act = () => shogi.Move("D5", "D6", false);
// Assert
act.Should().Throw<InvalidOperationException>();
board["D5"].Should().BeNull();
board["D6"].Should().BeNull();
}
//[Fact]
//public void PreventInvalidMoves_MoveToCurrentPosition()