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: "False Swipe inflicts damage, but will leave the target with 1 HP if it would
/// otherwise cause it to faint. If the target has 1 HP remaining, False Swipe will hit and leave the target
/// at 1 HP."
///
public class FalseSwipeTests
{
///
/// Creates a fully mocked test setup where the target has the given current health.
///
private static (FalseSwipe script, IExecutingMove move, IBattlePokemon target) CreateTestSetup(uint currentHealth)
{
var script = new FalseSwipe();
var move = Substitute.For();
var target = Substitute.For();
target.CurrentHealth.Returns(currentHealth);
return (script, move, target);
}
///
/// Bulbapedia: "False Swipe inflicts damage, but will leave the target with 1 HP if it would otherwise
/// cause it to faint." — damage exactly equal to the target's remaining HP is reduced to leave 1 HP.
/// The (1, 1, 0) row verifies "If the target has 1 HP remaining, False Swipe will hit and leave the
/// target at 1 HP."
///
[Test, Arguments(50u, 50u, 49u), Arguments(100u, 100u, 99u), Arguments(1u, 1u, 0u)]
public async Task ChangeMoveDamage_DamageExactlyLethal_LeavesTargetWithOneHp(uint currentHealth, uint damage,
uint expectedDamage)
{
// Arrange
var (script, move, target) = CreateTestSetup(currentHealth);
// Act
script.ChangeMoveDamage(move, target, 0, ref damage);
// Assert
await Assert.That(damage).IsEqualTo(expectedDamage);
}
///
/// Bulbapedia: "False Swipe inflicts damage, but will leave the target with 1 HP if it would otherwise
/// cause it to faint." — damage exceeding the target's remaining HP is also capped so the target is left
/// at 1 HP.
///
[Test, Arguments(50u, 100u, 49u), Arguments(1u, 5u, 0u), Arguments(30u, 4000u, 29u)]
public async Task ChangeMoveDamage_DamageExceedsCurrentHealth_LeavesTargetWithOneHp(uint currentHealth, uint damage,
uint expectedDamage)
{
// Arrange
var (script, move, target) = CreateTestSetup(currentHealth);
// Act
script.ChangeMoveDamage(move, target, 0, ref damage);
// Assert
await Assert.That(damage).IsEqualTo(expectedDamage);
}
///
/// Bulbapedia: "False Swipe inflicts damage" — when the damage would not cause the target to faint, it
/// is dealt in full.
///
[Test, Arguments(100u, 50u), Arguments(100u, 99u), Arguments(2u, 1u)]
public async Task ChangeMoveDamage_DamageNotLethal_DamageUnchanged(uint currentHealth, uint damage)
{
// Arrange
var (script, move, target) = CreateTestSetup(currentHealth);
var originalDamage = damage;
// Act
script.ChangeMoveDamage(move, target, 0, ref damage);
// Assert
await Assert.That(damage).IsEqualTo(originalDamage);
}
}