Files
MovementTests/tests/components/HealthComponentUnitTest.cs
Minimata 9207295a99
Some checks failed
Create tag and build when new code gets to main / BumpTag (push) Successful in 20s
Create tag and build when new code gets to main / Test (push) Failing after 7m29s
Create tag and build when new code gets to main / Export (push) Successful in 8m18s
basic tests for a wider variety of files
2026-02-20 16:58:17 +01:00

57 lines
1.8 KiB
C#

using Godot;
using GdUnit4;
using static GdUnit4.Assertions;
using Movementtests.interfaces;
using Movementtests.systems.damage;
namespace Movementtests.tests;
[TestSuite, RequireGodotRuntime]
public class HealthComponentUnitTest
{
[TestCase]
public void ReadyInitializesCurrentHealth()
{
var cHealth = new CHealth();
cHealth.RHealth = new RHealth(150.0f);
// Simulate Godot ready
cHealth._Ready();
AssertFloat(cHealth.CurrentHealth).IsEqual(150.0f);
}
[TestCase]
public void ReduceHealthDecreasesAndDoesNotDeplete()
{
var cHealth = new CHealth();
cHealth.RHealth = new RHealth(100.0f);
cHealth.CurrentHealth = 100.0f;
var damage = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
var record = cHealth.ReduceHealth(source: null!, damageRecord: damage);
AssertFloat(cHealth.CurrentHealth).IsEqual(75.0f);
AssertFloat(record.CurrentHealth).IsEqual(75.0f);
AssertFloat(record.PreviousHealth).IsEqual(100.0f);
AssertFloat(record.MaxHealth).IsEqual(100.0f);
}
[TestCase]
public void ReduceHealthTriggersDepletionToZero()
{
var cHealth = new CHealth();
cHealth.RHealth = new RHealth(50.0f);
cHealth.CurrentHealth = 50.0f;
bool depleted = false;
cHealth.HealthDepleted += _ => depleted = true;
var damage = new DamageRecord(Vector3.Zero, new RDamage(100.0f, EDamageTypes.Normal));
var record = cHealth.ReduceHealth(source: null!, damageRecord: damage);
AssertBool(depleted).IsTrue();
AssertFloat(cHealth.CurrentHealth).IsEqual(0.0f);
AssertFloat(record.CurrentHealth).IsEqual(-50.0f);
AssertFloat(record.MaxHealth).IsEqual(50.0f);
}
}