using NUnit.Framework; using SepCore.Battle; using SepCore.Definition; using SepCore.Event; using UnityEngine; namespace VampireLike.Tests.Gameplay.EditMode { [TestFixture] public class HarvestingEconomyTests { [Test] public void HarvestInterestRate_IsFivePercent() { Assert.AreEqual(0.05f, HarvestSettlementUtility.HarvestCompoundRate, 1e-5f); Assert.AreEqual("HarvestInterest", HarvestSettlementUtility.HarvestModifierSource); } [Test] public void WaveHarvestSettlementEventArgs_CreateAndClear_MaintainsValues() { var args = WaveHarvestSettlementEventArgs.Create(10, 1, 11); Assert.AreEqual(10, args.HarvestIncome); Assert.AreEqual(1, args.HarvestGrowth); Assert.AreEqual(11, args.CurrentHarvest); args.Clear(); Assert.AreEqual(0, args.HarvestIncome); Assert.AreEqual(0, args.HarvestGrowth); Assert.AreEqual(0, args.CurrentHarvest); } [Test] public void HarvestCompoundGrowth_SmallInitialValue_RoundsUpToOne() { // 当收获为 1 时,1 * 0.05 = 0.05,Mathf.CeilToInt 向上取整应为 1 int initialHarvest = 1; int growth = Mathf.CeilToInt(initialHarvest * HarvestCompoundRate); Assert.AreEqual(1, growth); // 当收获为 10 时,10 * 0.05 = 0.5,Mathf.CeilToInt 向上取整应为 1 int growth10 = Mathf.CeilToInt(10 * HarvestCompoundRate); Assert.AreEqual(1, growth10); // 当收获为 21 时,21 * 0.05 = 1.05,Mathf.CeilToInt 向上取整应为 2 int growth21 = Mathf.CeilToInt(21 * HarvestCompoundRate); Assert.AreEqual(2, growth21); // 当收获为 50 时,50 * 0.05 = 2.5,Mathf.CeilToInt 向上取整应为 3 int growth50 = Mathf.CeilToInt(50 * HarvestCompoundRate); Assert.AreEqual(3, growth50); } [Test] public void HarvestCompoundGrowth_SimulateMultiWaveProgression_InAttributePipeline() { var pipeline = new AttributePipeline(); pipeline.SetBaseValue(StatType.Harvesting, 10f); int totalIncome = 0; // 模拟连续 5 波的收获结算 for (int wave = 1; wave <= 5; wave++) { int currentHarvest = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting)); totalIncome += currentHarvest; int growth = Mathf.CeilToInt(currentHarvest * HarvestCompoundRate); pipeline.AddModifier( StatType.Harvesting, new StatModifier(growth, ModifierType.Flat, HarvestSettlementUtility.HarvestModifierSource)); } // Wave 1: Harvest=10, Income=10, Growth=1 -> Next Harvest=11 // Wave 2: Harvest=11, Income=11, Growth=1 -> Next Harvest=12 // Wave 3: Harvest=12, Income=12, Growth=1 -> Next Harvest=13 // Wave 4: Harvest=13, Income=13, Growth=1 -> Next Harvest=14 // Wave 5: Harvest=14, Income=14, Growth=1 -> Next Harvest=15 // Total Income = 10 + 11 + 12 + 13 + 14 = 60 Assert.AreEqual(60, totalIncome); Assert.AreEqual(15f, pipeline.GetValue(StatType.Harvesting), 1e-4f); } [Test] public void HarvestCompoundGrowth_HighInitial_AcceleratesExponentially() { var pipeline = new AttributePipeline(); pipeline.SetBaseValue(StatType.Harvesting, 40f); // Wave 1: 40 -> growth = ceil(40 * 0.05 = 2.0) = 2 -> 42 int harvestW1 = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting)); int g1 = Mathf.CeilToInt(harvestW1 * HarvestCompoundRate); Assert.AreEqual(2, g1); pipeline.AddModifier(StatType.Harvesting, new StatModifier(g1, ModifierType.Flat)); Assert.AreEqual(42f, pipeline.GetValue(StatType.Harvesting), 1e-4f); // Wave 2: 42 -> growth = ceil(42 * 0.05 = 2.1) = 3 -> 45 int harvestW2 = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting)); int g2 = Mathf.CeilToInt(harvestW2 * HarvestCompoundRate); Assert.AreEqual(3, g2); pipeline.AddModifier(StatType.Harvesting, new StatModifier(g2, ModifierType.Flat)); Assert.AreEqual(45f, pipeline.GetValue(StatType.Harvesting), 1e-4f); } private const float HarvestCompoundRate = HarvestSettlementUtility.HarvestCompoundRate; } }