PkmnLib.NET/PkmnLib.Tests/Dynamic/ChoiceQueueTests.cs
2025-04-19 13:04:10 +02:00

107 lines
4.4 KiB
C#

using Moq;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
namespace PkmnLib.Tests.Dynamic;
public class ChoiceQueueTests
{
[Test]
public async Task ChoiceQueue_MovePokemonChoiceNext()
{
var pokemon1 = new Mock<IPokemon>();
var pokemon2 = new Mock<IPokemon>();
var pokemon3 = new Mock<IPokemon>();
var pokemon4 = new Mock<IPokemon>();
var choice1 = new Mock<ITurnChoice>();
choice1.Setup(c => c.User).Returns(pokemon1.Object);
var choice2 = new Mock<ITurnChoice>();
choice2.Setup(c => c.User).Returns(pokemon2.Object);
var choice3 = new Mock<ITurnChoice>();
choice3.Setup(c => c.User).Returns(pokemon3.Object);
var choice4 = new Mock<ITurnChoice>();
choice4.Setup(c => c.User).Returns(pokemon4.Object);
var queue = new BattleChoiceQueue([choice1.Object, choice2.Object, choice3.Object, choice4.Object]);
var result = queue.MovePokemonChoiceNext(pokemon3.Object);
await Assert.That(result).IsTrue();
await Assert.That(queue.Dequeue()).IsEqualTo(choice3.Object);
}
[Test]
public async Task ChoiceQueue_MovePokemonChoiceNextFailsIfAlreadyExecuted()
{
var pokemon1 = new Mock<IPokemon>();
var pokemon2 = new Mock<IPokemon>();
var pokemon3 = new Mock<IPokemon>();
var pokemon4 = new Mock<IPokemon>();
var choice1 = new Mock<ITurnChoice>();
choice1.Setup(c => c.User).Returns(pokemon1.Object);
var choice2 = new Mock<ITurnChoice>();
choice2.Setup(c => c.User).Returns(pokemon2.Object);
var choice3 = new Mock<ITurnChoice>();
choice3.Setup(c => c.User).Returns(pokemon3.Object);
var choice4 = new Mock<ITurnChoice>();
choice4.Setup(c => c.User).Returns(pokemon4.Object);
var queue = new BattleChoiceQueue([choice1.Object, choice2.Object, choice3.Object, choice4.Object]);
queue.Dequeue();
var result = queue.MovePokemonChoiceNext(pokemon1.Object);
await Assert.That(result).IsFalse();
await Assert.That(queue.Dequeue()).IsEqualTo(choice2.Object);
}
[Test]
public async Task ChoiceQueue_MovePokemonChoiceLast()
{
var pokemon1 = new Mock<IPokemon>();
var pokemon2 = new Mock<IPokemon>();
var pokemon3 = new Mock<IPokemon>();
var pokemon4 = new Mock<IPokemon>();
var choice1 = new Mock<ITurnChoice>();
choice1.Setup(c => c.User).Returns(pokemon1.Object);
var choice2 = new Mock<ITurnChoice>();
choice2.Setup(c => c.User).Returns(pokemon2.Object);
var choice3 = new Mock<ITurnChoice>();
choice3.Setup(c => c.User).Returns(pokemon3.Object);
var choice4 = new Mock<ITurnChoice>();
choice4.Setup(c => c.User).Returns(pokemon4.Object);
var queue = new BattleChoiceQueue([choice1.Object, choice2.Object, choice3.Object, choice4.Object]);
var result = queue.MovePokemonChoiceLast(pokemon2.Object);
await Assert.That(result).IsTrue();
await Assert.That(queue.Dequeue()).IsEqualTo(choice1.Object);
await Assert.That(queue.Dequeue()).IsEqualTo(choice3.Object);
await Assert.That(queue.Dequeue()).IsEqualTo(choice4.Object);
await Assert.That(queue.Dequeue()).IsEqualTo(choice2.Object);
}
[Test]
public async Task ChoiceQueue_MovePokemonChoiceLastFailsIfAlreadyExecuted()
{
var pokemon1 = new Mock<IPokemon>();
var pokemon2 = new Mock<IPokemon>();
var pokemon3 = new Mock<IPokemon>();
var pokemon4 = new Mock<IPokemon>();
var choice1 = new Mock<ITurnChoice>();
choice1.Setup(c => c.User).Returns(pokemon1.Object);
var choice2 = new Mock<ITurnChoice>();
choice2.Setup(c => c.User).Returns(pokemon2.Object);
var choice3 = new Mock<ITurnChoice>();
choice3.Setup(c => c.User).Returns(pokemon3.Object);
var choice4 = new Mock<ITurnChoice>();
choice4.Setup(c => c.User).Returns(pokemon4.Object);
var queue = new BattleChoiceQueue([choice1.Object, choice2.Object, choice3.Object, choice4.Object]);
queue.Dequeue();
var result = queue.MovePokemonChoiceLast(pokemon1.Object);
await Assert.That(result).IsFalse();
await Assert.That(queue.Dequeue()).IsEqualTo(choice2.Object);
await Assert.That(queue.Dequeue()).IsEqualTo(choice3.Object);
await Assert.That(queue.Dequeue()).IsEqualTo(choice4.Object);
}
}