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,120 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// <summary>
/// Tests for the <see cref="FakeOut"/> move script.
/// Gen VII Bulbapedia behavior: "Fake Out inflicts damage and always makes the target flinch, unless it has
/// the Ability Inner Focus or Shield Dust." and "Fake Out will fail if not used on the first turn the user
/// is out."
/// </summary>
public class FakeOutTests
{
/// <summary>
/// Creates a fully mocked test setup where the user switched in on the given turn and the battle is
/// currently on the given turn.
/// </summary>
private static (FakeOut script, IExecutingMove move) CreateStopSetup(uint switchInTurn, uint currentTurn)
{
var script = new FakeOut();
var move = Substitute.For<IExecutingMove>();
var battle = Substitute.For<IBattle>();
battle.CurrentTurnNumber.Returns(currentTurn);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
battleData.SwitchInTurn.Returns(switchInTurn);
var user = Substitute.For<IPokemon>();
user.BattleData.Returns(battleData);
move.User.Returns(user);
return (script, move);
}
/// <summary>
/// Bulbapedia: "Fake Out will fail if not used on the first turn the user is out." — on the first turn
/// the user is on the field (its switch-in turn), the move is not stopped. This includes Pokémon sent
/// out later in the battle, as the check is against the turn the user came out, not the battle's first
/// turn.
/// </summary>
[Test, Arguments(1u, 1u), Arguments(5u, 5u)]
public async Task StopBeforeMove_FirstTurnOnField_MoveNotStopped(uint switchInTurn, uint currentTurn)
{
// Arrange
var (script, move) = CreateStopSetup(switchInTurn, currentTurn);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsFalse();
}
/// <summary>
/// Bulbapedia: "Fake Out will fail if not used on the first turn the user is out." — on any later turn
/// the move is stopped.
/// </summary>
[Test, Arguments(1u, 2u), Arguments(1u, 10u), Arguments(4u, 5u)]
public async Task StopBeforeMove_LaterTurnOnField_MoveStopped(uint switchInTurn, uint currentTurn)
{
// Arrange
var (script, move) = CreateStopSetup(switchInTurn, currentTurn);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsTrue();
}
/// <summary>
/// Technical test: without battle data on the user (outside of battle) the first-turn check does nothing
/// and the move is not stopped.
/// </summary>
[Test]
public async Task StopBeforeMove_UserHasNoBattleData_MoveNotStopped()
{
// Arrange
var script = new FakeOut();
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();
}
/// <summary>
/// Bulbapedia: "Fake Out inflicts damage and always makes the target flinch" — the secondary effect puts
/// a <see cref="FlinchEffect"/> on the target.
/// </summary>
[Test]
public async Task OnSecondaryEffect_AddsFlinchEffectToTarget()
{
// Arrange
var script = new FakeOut();
var move = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
target.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet volatileSet = new ScriptSet(target);
target.Volatile.Returns(volatileSet);
// Act
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName<FlinchEffect>())).IsTrue();
}
}