This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the <see cref="Frustration"/> 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".
|
||||
/// </summary>
|
||||
public class FrustrationTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a fully mocked test setup with a user that has the given friendship value.
|
||||
/// </summary>
|
||||
private static (Frustration script, IExecutingMove move, IPokemon target) CreateTestSetup(byte friendship)
|
||||
{
|
||||
var script = new Frustration();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
user.Happiness.Returns(friendship);
|
||||
move.User.Returns(user);
|
||||
return (script, move, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The power is derived purely from the user's friendship: the incoming base power value does not
|
||||
/// influence the result.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user