Files
tiny_tackle_heroes/Assets/_Project/Tests/EditMode/Defense25DMonsterPoolTests.cs
T
2026-09-28 11:07:17 +09:00

85 lines
3.4 KiB
C#

using System;
using System.Linq;
using System.Reflection;
using BumpCombat.Defense.Comparison;
using NUnit.Framework;
using UnityEngine;
namespace BumpCombat.Tests
{
public sealed class Defense25DMonsterPoolTests
{
private const string PoolTypeName = "BumpCombat.Constants.Defense25DMonsterPoolDefinition";
[Test]
public void MonsterPoolDefinition_ExposesDirectorEntryProvider()
{
Type poolType = FindPoolType();
Assert.That(poolType, Is.Not.Null, "The runtime monster pool definition type is missing.");
if (poolType == null) return;
Assert.That(typeof(ScriptableObject).IsAssignableFrom(poolType), Is.True);
Assert.That(poolType.GetMethod("TryValidate", new[] { typeof(string).MakeByRefType() }), Is.Not.Null);
MethodInfo provider = poolType.GetMethod("GetDirectorEntriesForTier", new[] { typeof(int) });
Assert.That(provider, Is.Not.Null);
if (provider != null)
Assert.That(provider.ReturnType, Is.EqualTo(typeof(System.Collections.Generic.IReadOnlyList<Defense25DWaveEnemyEntry>)));
}
[TestCase(0f, 0)]
[TestCase(179.999f, 0)]
[TestCase(180f, 1)]
[TestCase(359.999f, 1)]
[TestCase(360f, 2)]
public void TierForNominalStart_UsesThe180And360SecondBoundaries(float nominalStart, int expectedTierId)
{
Type poolType = FindPoolType();
Assert.That(poolType, Is.Not.Null, "The runtime monster pool definition type is missing.");
if (poolType == null) return;
MethodInfo getTier = poolType.GetMethod("TryGetTierForNominalStart",
BindingFlags.Public | BindingFlags.Static, null,
new[] { typeof(float), typeof(int).MakeByRefType() }, null);
Assert.That(getTier, Is.Not.Null);
if (getTier == null) return;
object[] arguments = { nominalStart, 0 };
bool succeeded = (bool)getTier.Invoke(null, arguments);
Assert.That(succeeded, Is.True);
Assert.That(arguments[1], Is.EqualTo(expectedTierId));
}
[Test]
public void DirectorEntryProvider_RejectsTierIdsOutsideZeroThroughTwo()
{
Type poolType = FindPoolType();
Assert.That(poolType, Is.Not.Null, "The runtime monster pool definition type is missing.");
if (poolType == null) return;
ScriptableObject pool = ScriptableObject.CreateInstance(poolType);
try
{
MethodInfo provider = poolType.GetMethod("GetDirectorEntriesForTier", new[] { typeof(int) });
Assert.That(provider, Is.Not.Null);
if (provider == null) return;
TargetInvocationException exception = Assert.Throws<TargetInvocationException>(
() => provider.Invoke(pool, new object[] { 3 }));
Assert.That(exception.InnerException, Is.TypeOf<ArgumentOutOfRangeException>());
}
finally
{
UnityEngine.Object.DestroyImmediate(pool);
}
}
private static Type FindPoolType()
{
return AppDomain.CurrentDomain.GetAssemblies()
.Select(assembly => assembly.GetType(PoolTypeName, false))
.FirstOrDefault(type => type != null);
}
}
}