basic tests for a wider variety of files
This commit is contained in:
56
tests/components/HealthComponentUnitTest.cs
Normal file
56
tests/components/HealthComponentUnitTest.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user