using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
///
/// Tests for the move script.
/// Gen VII Bulbapedia behavior: "Frustration inflicts damage and has no secondary effect. The base power of
/// Frustration is dependent on the user's friendship. The lower the user's friendship is, the greater the
/// base power of Frustration." The power formula is Power = (255 − Friendship) × 2 / 5, and from Generation
/// III to VII, "if calculations yielded zero, the move's power becomes 1 instead".
///
public class FrustrationTests
{
///
/// Creates a fully mocked test setup with a user that has the given friendship value.
///
private static (Frustration script, IExecutingMove move, IBattlePokemon target) CreateTestSetup(byte friendship)
{
var script = new Frustration();
var move = Substitute.For();
var target = Substitute.For();
var user = Substitute.For();
user.Happiness.Returns(friendship);
move.User.Returns(user);
return (script, move, target);
}
///
/// Bulbapedia: "The base power of Frustration is dependent on the user's friendship. The lower the
/// user's friendship is, the greater the base power of Frustration." The power formula is
/// Power = (255 − Friendship) × 2 / 5, with integer truncation.
///
[Test, Arguments((byte)0, (ushort)102), Arguments((byte)50, (ushort)82), Arguments((byte)100, (ushort)62),
Arguments((byte)128, (ushort)50), Arguments((byte)200, (ushort)22), Arguments((byte)250, (ushort)2)]
public async Task ChangeBasePower_FriendshipValue_MatchesFormula(byte friendship, ushort expectedPower)
{
// Arrange
var (script, move, target) = CreateTestSetup(friendship);
ushort basePower = 102;
// Act
script.ChangeBasePower(move, target, 0, ref basePower);
// Assert
await Assert.That(basePower).IsEqualTo(expectedPower);
}
///
/// Bulbapedia (Generations III to VII): the formula was adjusted so "if calculations yielded zero, the
/// move's power becomes 1 instead". Friendship values of 253 and above yield 0 from the formula, so the
/// power becomes 1.
///
[Test, Arguments((byte)253), Arguments((byte)254), Arguments((byte)255)]
public async Task ChangeBasePower_FriendshipNearMaximum_PowerIsMinimumOne(byte friendship)
{
// Arrange
var (script, move, target) = CreateTestSetup(friendship);
ushort basePower = 102;
// Act
script.ChangeBasePower(move, target, 0, ref basePower);
// Assert
await Assert.That(basePower).IsEqualTo((ushort)1);
}
///
/// Bulbapedia: "The lower the user's friendship is, the greater the base power of Frustration." — at 0
/// friendship the move reaches its maximum power of 102.
///
[Test]
public async Task ChangeBasePower_ZeroFriendship_PowerIsMaximum102()
{
// Arrange
var (script, move, target) = CreateTestSetup(0);
ushort basePower = 102;
// Act
script.ChangeBasePower(move, target, 0, ref basePower);
// Assert
await Assert.That(basePower).IsEqualTo((ushort)102);
}
///
/// The power is derived purely from the user's friendship: the incoming base power value does not
/// influence the result.
///
[Test]
public async Task ChangeBasePower_DifferentIncomingBasePower_ResultDependsOnlyOnFriendship()
{
// Arrange
var (script, move, target) = CreateTestSetup(100);
ushort basePowerLow = 1;
ushort basePowerHigh = 250;
// Act
script.ChangeBasePower(move, target, 0, ref basePowerLow);
script.ChangeBasePower(move, target, 0, ref basePowerHigh);
// Assert
await Assert.That(basePowerLow).IsEqualTo((ushort)62);
await Assert.That(basePowerHigh).IsEqualTo((ushort)62);
}
}