Many more tests and fixes
All checks were successful
Build / Build (push) Successful in 3m12s

This commit is contained in:
2026-08-27 17:11:12 +02:00
parent 32b3ef9c4a
commit d2a82b5fe3
204 changed files with 20255 additions and 242 deletions

View File

@@ -0,0 +1,113 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// <summary>
/// Tests for the <see cref="FirstImpression"/> move script.
/// Gen VII Bulbapedia behavior: "First Impression inflicts damage. It has a priority of +2, and is used
/// before moves of lower priority. First Impression always fails if it is used after the first turn the
/// user is out, or if the move is called by Instruct."
/// </summary>
public class FirstImpressionTests
{
/// <summary>
/// Creates a fully mocked test setup for First Impression tests, with the user having switched in on
/// <paramref name="switchInTurn"/> while the battle is on <paramref name="currentTurn"/>.
/// </summary>
private static (FirstImpression script, IExecutingMove move, IPokemon user) CreateTestSetup(uint switchInTurn,
uint currentTurn)
{
var script = new FirstImpression();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
var battle = Substitute.For<IBattle>();
battle.CurrentTurnNumber.Returns(currentTurn);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
battleData.SwitchInTurn.Returns(switchInTurn);
user.BattleData.Returns(battleData);
move.User.Returns(user);
return (script, move, user);
}
/// <summary>
/// Bulbapedia: "First Impression always fails if it is used after the first turn the user is out".
/// On the turn the user switched in, the move is allowed to execute.
/// </summary>
[Test]
public async Task StopBeforeMove_UsedOnSwitchInTurn_MoveIsNotStopped()
{
// Arrange
var (script, move, _) = CreateTestSetup(3, 3);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsFalse();
}
/// <summary>
/// Bulbapedia: "First Impression always fails if it is used after the first turn the user is out".
/// One turn after switching in, the move is stopped.
/// </summary>
[Test]
public async Task StopBeforeMove_UsedTurnAfterSwitchIn_MoveIsStopped()
{
// Arrange
var (script, move, _) = CreateTestSetup(1, 2);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsTrue();
}
/// <summary>
/// Bulbapedia: "First Impression always fails if it is used after the first turn the user is out".
/// The move only executes when the current turn is the turn the user switched in, regardless of
/// the absolute turn numbers.
/// </summary>
[Test, Arguments(1u, 1u, false), Arguments(1u, 2u, true), Arguments(4u, 4u, false), Arguments(2u, 7u, true)]
public async Task StopBeforeMove_SwitchInTurnVersusCurrentTurn_StopsOnlyAfterFirstTurnOut(uint switchInTurn,
uint currentTurn, bool expectedStop)
{
// Arrange
var (script, move, _) = CreateTestSetup(switchInTurn, currentTurn);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsEqualTo(expectedStop);
}
/// <summary>
/// Technical test: if the user has no <see cref="IPokemon.BattleData"/>, the script cannot determine the
/// switch-in turn and leaves the move untouched.
/// </summary>
[Test]
public async Task StopBeforeMove_NoBattleData_MoveIsNotStopped()
{
// Arrange
var script = new FirstImpression();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
user.BattleData.Returns((IPokemonBattleData?)null);
move.User.Returns(user);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsFalse();
}
}