Files
Giants/Tests/Giants.Core.Tests/Commands/PrepareMatchCommandTest.cs
mcmuzzle 3dba66344d
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m46s
fin de l'initialisation d'un match et ajout du random aux commandes
2025-04-24 22:31:19 +02:00

115 lines
4.7 KiB
C#

using Giants.Application;
using Giants.Core.Commands;
using Giants.Core.Enums;
using Giants.Core.Interfaces;
using Giants.Infrastructure;
namespace Giants.Core.Tests;
public class PrepareMatchCommandTest
{
private readonly IMatchRepository _repo;
public PrepareMatchCommandTest()
{
IHexagonalGrid _grid = new HexagonalGridImpl();
BoardLayout layout = new BoardLayout(_grid);
_repo = new MatchRepositoryMock(layout);
}
[Fact]
void SimpleInit5Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5, 14, 9 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 5; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(5, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
[Fact]
void SimpleInit4Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5, 14 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 4; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(6, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
[Fact]
void SimpleInit3Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 3; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(7, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
}