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

@@ -1,12 +1,20 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Plugin.Gen7.Scripts.Battle;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Static;
using PkmnLib.Static.Libraries;
using PkmnLib.Static.Species;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// <summary>
/// Tests for the <see cref="MultiAttack"/> move script.
/// Gen VII Bulbapedia behavior: "The type of Multi-Attack depends on the type of memory held by the user,
/// being Normal-type if there is no held memory."
/// </summary>
public class MultiAttackTests
{
public record TestCaseData(string? ItemName, string ExpectedTypeName)
@@ -88,4 +96,81 @@ public class MultiAttackTests
// Assert
await Assert.That(typeIdentifier!.Value.Name.ToString()).IsEqualTo(test.ExpectedTypeName);
}
/// <summary>
/// Creates a mocked executing move whose user holds a fire_memory, with a type library that knows both
/// "normal" and "fire".
/// </summary>
private static (IExecutingMove move, IPokemon user) CreateMemoryHolderSetup()
{
var typeLibrary = new TypeLibrary();
typeLibrary.RegisterType("normal");
typeLibrary.RegisterType("fire");
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
var dynamicLibrary = Substitute.For<IDynamicLibrary>();
var staticLibrary = Substitute.For<IStaticLibrary>();
var item = Substitute.For<IItem>();
user.Library.Returns(dynamicLibrary);
dynamicLibrary.StaticLibrary.Returns(staticLibrary);
staticLibrary.Types.Returns(typeLibrary);
item.Name.Returns(new StringKey("fire_memory"));
user.HeldItem.Returns(item);
move.User.Returns(user);
return (move, user);
}
/// <summary>
/// Bulbapedia: "If the user has Klutz, or if Magic Room is in effect, Multi-Attack's type will always be
/// Normal regardless of the memory held." A Klutz user holding a fire_memory still uses a Normal-type
/// Multi-Attack.
/// </summary>
[Test]
public async Task ChangeMoveType_UserHasKlutz_MoveTypeStaysNormal()
{
// Arrange
var (move, user) = CreateMemoryHolderSetup();
var klutz = Substitute.For<IAbility>();
klutz.Name.Returns(new StringKey("klutz"));
user.ActiveAbility.Returns(klutz);
TypeIdentifier? typeIdentifier = new TypeIdentifier(1, "normal");
var multiAttack = new MultiAttack();
// Act
multiAttack.ChangeMoveType(move, Substitute.For<IPokemon>(), 0, ref typeIdentifier);
// Assert
await Assert.That(typeIdentifier!.Value.Name.ToString()).IsEqualTo("normal");
}
/// <summary>
/// Bulbapedia: "If the user has Klutz, or if Magic Room is in effect, Multi-Attack's type will always be
/// Normal regardless of the memory held." While the <see cref="MagicRoomEffect"/> is on the battle, a held
/// fire_memory does not change Multi-Attack's type.
/// </summary>
[Test]
public async Task ChangeMoveType_MagicRoomInEffect_MoveTypeStaysNormal()
{
// Arrange
var (move, _) = CreateMemoryHolderSetup();
var battle = Substitute.For<IBattle>();
battle.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet battleVolatile = new ScriptSet(battle);
battleVolatile.Add(new MagicRoomEffect());
battle.Volatile.Returns(battleVolatile);
move.Battle.Returns(battle);
TypeIdentifier? typeIdentifier = new TypeIdentifier(1, "normal");
var multiAttack = new MultiAttack();
// Act
multiAttack.ChangeMoveType(move, Substitute.For<IPokemon>(), 0, ref typeIdentifier);
// Assert
await Assert.That(typeIdentifier!.Value.Name.ToString()).IsEqualTo("normal");
}
}