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,111 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Side;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// <summary>
/// Tests for the <see cref="LuckyChant"/> move script and its volatile effect script
/// <see cref="LuckyChantEffect"/>.
/// Gen VII Bulbapedia behavior: "Lucky Chant prevents opponents from landing critical hits on the user's
/// party for five turns, even if the move would always result in a critical hit (e.g. Frost Breath)."
/// </summary>
public class LuckyChantTests
{
/// <summary>
/// Bulbapedia: the protection applies to "the user's party for five turns" — like the other
/// side-affecting moves, the effect belongs on the user's side of the field so that Pokémon switching
/// in during those five turns are protected as well.
/// </summary>
[Test]
public async Task OnSecondaryEffect_Used_AddsLuckyChantEffectToUserSide()
{
// Arrange
var script = new LuckyChant();
var move = Substitute.For<IExecutingMove>();
var sideScripts = Substitute.For<IScriptSet>();
var side = Substitute.For<IBattleSide>();
side.VolatileScripts.Returns(sideScripts);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.BattleSide.Returns(side);
var user = Substitute.For<IPokemon>();
user.BattleData.Returns(battleData);
user.Volatile.Returns(Substitute.For<IScriptSet>());
move.User.Returns(user);
// Act - Lucky Chant targets the user's side; the user itself is one of the targets
script.OnSecondaryEffect(move, user, 0);
// Assert
await Assert.That(sideScripts.ReceivedCalls().Any(c => c.GetMethodInfo().Name is "Add" or "StackOrAdd"))
.IsTrue();
}
/// <summary>
/// Bulbapedia: Lucky Chant "prevents opponents from landing critical hits" — the engine consults the
/// defending side through <see cref="IScriptBlockIncomingCriticalHit"/>
/// (<c>MoveTurnExecutor</c> only runs <see cref="IScriptBlockCriticalHit"/> over the attacking move's
/// own scripts), so the effect must block through that hook to protect the party.
/// </summary>
[Test]
public async Task BlockIncomingCriticalHit_EffectActive_CriticalHitBlocked()
{
// Arrange
var effect = new LuckyChantEffect();
var attack = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
var block = false;
// Act
if (effect is IScriptBlockIncomingCriticalHit blockIncoming)
blockIncoming.BlockIncomingCriticalHit(attack, target, 0, ref block);
// Assert
await Assert.That(block).IsTrue();
}
/// <summary>
/// Bulbapedia: the protection lasts "for five turns" — after four end-of-turns (the turn Lucky Chant
/// was used and three more) the effect is still active.
/// </summary>
[Test]
public async Task OnEndTurn_FourTurnsPassed_EffectStillActive()
{
// Arrange
var effect = new LuckyChantEffect();
var owner = Substitute.For<IPokemon>();
owner.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet set = new ScriptSet(owner);
set.Add(effect);
// Act
for (var i = 0; i < 4; i++)
effect.OnEndTurn(owner, Substitute.For<IBattle>());
// Assert
await Assert.That(set.Contains(ScriptUtils.ResolveName<LuckyChantEffect>())).IsTrue();
}
/// <summary>
/// Bulbapedia: the protection lasts "for five turns" — at the end of the fifth turn the effect expires.
/// </summary>
[Test]
public async Task OnEndTurn_FiveTurnsPassed_EffectExpires()
{
// Arrange
var effect = new LuckyChantEffect();
var owner = Substitute.For<IPokemon>();
owner.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet set = new ScriptSet(owner);
set.Add(effect);
// Act
for (var i = 0; i < 5; i++)
effect.OnEndTurn(owner, Substitute.For<IBattle>());
// Assert
await Assert.That(set.Contains(ScriptUtils.ResolveName<LuckyChantEffect>())).IsFalse();
}
}