Merged in better-communication (pull request #49)

Better communication
This commit is contained in:
2022-05-10 22:14:25 +00:00
parent 04f2d115ad
commit 8951cd4223
26 changed files with 1397 additions and 811 deletions

View File

@@ -0,0 +1,227 @@
using FluentAssertions;
using Shogi.Domain.Pathing;
using Shogi.Domain.Pieces;
using System.Numerics;
using Xunit;
namespace Shogi.Domain.UnitTests
{
public class RookShould
{
public class MoveSet
{
private readonly Rook rook1;
private readonly Rook rook2;
public MoveSet()
{
this.rook1 = new Rook(WhichPlayer.Player1);
this.rook2 = new Rook(WhichPlayer.Player2);
}
[Fact]
public void Player1_HasCorrectMoveSet()
{
var moveSet = rook1.MoveSet;
moveSet.Should().HaveCount(4);
moveSet.Should().ContainEquivalentOf(new Path(Direction.Up, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Left, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Right, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Down, Distance.MultiStep));
}
[Fact]
public void Player1_Promoted_HasCorrectMoveSet()
{
// Arrange
rook1.Promote();
rook1.IsPromoted.Should().BeTrue();
// Assert
var moveSet = rook1.MoveSet;
moveSet.Should().HaveCount(8);
moveSet.Should().ContainEquivalentOf(new Path(Direction.Up, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Left, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Right, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Down, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.UpLeft, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.DownLeft, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.UpRight, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.DownRight, Distance.OneStep));
}
[Fact]
public void Player2_HasCorrectMoveSet()
{
var moveSet = rook2.MoveSet;
moveSet.Should().HaveCount(4);
moveSet.Should().ContainEquivalentOf(new Path(Direction.Up, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Left, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Right, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Down, Distance.MultiStep));
}
[Fact]
public void Player2_Promoted_HasCorrectMoveSet()
{
// Arrange
rook2.Promote();
rook2.IsPromoted.Should().BeTrue();
// Assert
var moveSet = rook2.MoveSet;
moveSet.Should().HaveCount(8);
moveSet.Should().ContainEquivalentOf(new Path(Direction.Up, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Left, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Right, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.Down, Distance.MultiStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.UpLeft, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.DownLeft, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.UpRight, Distance.OneStep));
moveSet.Should().ContainEquivalentOf(new Path(Direction.DownRight, Distance.OneStep));
}
}
private readonly Rook rookPlayer1;
private readonly Rook rookPlayer2;
public RookShould()
{
this.rookPlayer1 = new Rook(WhichPlayer.Player1);
this.rookPlayer2 = new Rook(WhichPlayer.Player2);
}
[Fact]
public void Promote()
{
this.rookPlayer1.IsPromoted.Should().BeFalse();
this.rookPlayer1.CanPromote.Should().BeTrue();
this.rookPlayer1.Promote();
this.rookPlayer1.IsPromoted.Should().BeTrue();
this.rookPlayer1.CanPromote.Should().BeFalse();
}
[Fact]
public void GetStepsFromStartToEnd_Player1NotPromoted_LateralMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(0, 5);
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeFalse();
steps.Should().HaveCount(5);
steps.Should().Contain(new Vector2(0, 1));
steps.Should().Contain(new Vector2(0, 2));
steps.Should().Contain(new Vector2(0, 3));
steps.Should().Contain(new Vector2(0, 4));
steps.Should().Contain(new Vector2(0, 5));
}
[Fact]
public void GetStepsFromStartToEnd_Player1NotPromoted_DiagonalMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(1, 1);
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeFalse();
steps.Should().BeEmpty();
}
[Fact]
public void GetStepsFromStartToEnd_Player1Promoted_LateralMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(0, 5);
rookPlayer1.Promote();
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeTrue();
steps.Should().HaveCount(5);
steps.Should().Contain(new Vector2(0, 1));
steps.Should().Contain(new Vector2(0, 2));
steps.Should().Contain(new Vector2(0, 3));
steps.Should().Contain(new Vector2(0, 4));
steps.Should().Contain(new Vector2(0, 5));
}
[Fact]
public void GetStepsFromStartToEnd_Player1Promoted_DiagonalMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(1, 1);
rookPlayer1.Promote();
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeTrue();
steps.Should().HaveCount(1);
steps.Should().Contain(new Vector2(1, 1));
}
[Fact]
public void GetStepsFromStartToEnd_Player2NotPromoted_LateralMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(0, 5);
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeFalse();
steps.Should().HaveCount(5);
steps.Should().Contain(new Vector2(0, 1));
steps.Should().Contain(new Vector2(0, 2));
steps.Should().Contain(new Vector2(0, 3));
steps.Should().Contain(new Vector2(0, 4));
steps.Should().Contain(new Vector2(0, 5));
}
[Fact]
public void GetStepsFromStartToEnd_Player2NotPromoted_DiagonalMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(1, 1);
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeFalse();
steps.Should().BeEmpty();
}
[Fact]
public void GetStepsFromStartToEnd_Player2Promoted_LateralMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(0, 5);
rookPlayer1.Promote();
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeTrue();
steps.Should().HaveCount(5);
steps.Should().Contain(new Vector2(0, 1));
steps.Should().Contain(new Vector2(0, 2));
steps.Should().Contain(new Vector2(0, 3));
steps.Should().Contain(new Vector2(0, 4));
steps.Should().Contain(new Vector2(0, 5));
}
[Fact]
public void GetStepsFromStartToEnd_Player2Promoted_DiagonalMove()
{
Vector2 start = new(0, 0);
Vector2 end = new(1, 1);
rookPlayer1.Promote();
var steps = rookPlayer1.GetPathFromStartToEnd(start, end);
rookPlayer1.IsPromoted.Should().BeTrue();
steps.Should().HaveCount(1);
steps.Should().Contain(new Vector2(1, 1));
}
}
}