using System; using KernelPanic.Combat; using NUnit.Framework; public class NixGovernorStateTests { [TestCase(int.MinValue, 0)] [TestCase(-1, 0)] [TestCase(0, 0)] [TestCase(1, 1)] [TestCase(3, 3)] [TestCase(5, 5)] [TestCase(6, 5)] [TestCase(int.MaxValue, 5)] public void BeginWaveClampsVersion(int input, int expected) { var state = new NixGovernorState(); state.BeginWave(input); Assert.That(state.Version, Is.EqualTo(expected)); Assert.That(state.Active, Is.EqualTo(expected > 0)); } [Test] public void InactiveStateHasNeutralModifiersForEveryGovernor() { var state = new NixGovernorState(); Assert.That(state.DamagePercent, Is.EqualTo(100)); Assert.That(state.ShieldPercent, Is.EqualTo(100)); foreach (NixGovernor governor in Enum.GetValues(typeof(NixGovernor))) { Assert.That(state.DamageFor(governor), Is.EqualTo(100)); Assert.That(state.ShieldFor(governor), Is.EqualTo(100)); } } [TestCase(0)] [TestCase(1)] [TestCase(5)] public void ModifierLookupsRejectInvalidGovernorsEvenWhenInactive(int version) { var state = new NixGovernorState(); state.BeginWave(version); foreach (var governor in new[] { (NixGovernor)(-1), (NixGovernor)99 }) { Assert.Throws(() => state.DamageFor(governor)); Assert.Throws(() => state.ShieldFor(governor)); } } [TestCase(1, 120, 75, 130, 105)] [TestCase(2, 120, 75, 130, 110)] [TestCase(3, 120, 75, 130, 110)] [TestCase(4, 130, 75, 140, 110)] [TestCase(5, 130, 75, 140, 110)] public void ModifierLookupsPreserveVersionBalance(int version, int damage, int shield, int powersave, int schedutil) { var state = new NixGovernorState(); state.BeginWave(version); Assert.That(state.DamageFor(NixGovernor.Performance), Is.EqualTo(damage)); Assert.That(state.ShieldFor(NixGovernor.Performance), Is.EqualTo(shield)); Assert.That(state.DamageFor(NixGovernor.Powersave), Is.EqualTo(80)); Assert.That(state.ShieldFor(NixGovernor.Powersave), Is.EqualTo(powersave)); Assert.That(state.DamageFor(NixGovernor.Schedutil), Is.EqualTo(schedutil)); Assert.That(state.ShieldFor(NixGovernor.Schedutil), Is.EqualTo(schedutil)); } [TestCase(0, false, NixGovernor.Performance, 1, 10, NixGovernorSwitchBlockReason.Inactive)] [TestCase(3, false, (NixGovernor)99, 1, 0, NixGovernorSwitchBlockReason.InvalidGovernor)] [TestCase(3, false, NixGovernor.Schedutil, 1, 0, NixGovernorSwitchBlockReason.AlreadySelected)] [TestCase(1, false, NixGovernor.Performance, 1, 0, NixGovernorSwitchBlockReason.InsufficientCycles)] [TestCase(3, true, (NixGovernor)99, 2, 10, NixGovernorSwitchBlockReason.InvalidGovernor)] [TestCase(3, true, NixGovernor.Performance, 2, 10, NixGovernorSwitchBlockReason.AlreadySelected)] [TestCase(3, true, NixGovernor.Powersave, 1, 0, NixGovernorSwitchBlockReason.AlreadySwitchedThisRound)] [TestCase(3, true, NixGovernor.Powersave, 2, 0, NixGovernorSwitchBlockReason.InsufficientCycles)] public void RejectedSwitchesReturnReasonAndPreserveAllState(int version, bool switched, NixGovernor target, int round, int cycles, NixGovernorSwitchBlockReason reason) { var state = new NixGovernorState(); state.BeginWave(version); if (switched) Assert.That(state.TrySwitch(NixGovernor.Performance, 1, 10, out _), Is.True); var before = (state.Version, state.Governor, state.FreeSwitchUsed, state.LastSwitchRound, state.SwitchCost, state.DamagePercent, state.ShieldPercent); Assert.That(state.GetSwitchBlockReason(target, round, cycles), Is.EqualTo(reason)); Assert.That(state.CanSwitch(target, round, cycles), Is.False); Assert.That(state.TrySwitch(target, round, cycles, out int cost), Is.False); Assert.That(cost, Is.Zero); Assert.That((state.Version, state.Governor, state.FreeSwitchUsed, state.LastSwitchRound, state.SwitchCost, state.DamagePercent, state.ShieldPercent), Is.EqualTo(before)); } [TestCase(1, 1)] [TestCase(2, 1)] [TestCase(3, 0)] [TestCase(4, 0)] [TestCase(5, 0)] public void SuccessfulSwitchReportsCostAndNextRoundCostsOne(int version, int initialCost) { var state = new NixGovernorState(); state.BeginWave(version); Assert.That(state.GetSwitchBlockReason(NixGovernor.Performance, 1, initialCost), Is.EqualTo(NixGovernorSwitchBlockReason.None)); Assert.That(state.CanSwitch(NixGovernor.Performance, 1, initialCost), Is.True); Assert.That(state.TrySwitch(NixGovernor.Performance, 1, initialCost, out int cost), Is.True); Assert.That(cost, Is.EqualTo(initialCost)); Assert.That(state.Governor, Is.EqualTo(NixGovernor.Performance)); Assert.That(state.LastSwitchRound, Is.EqualTo(1)); Assert.That(state.FreeSwitchUsed, Is.True); Assert.That(state.SwitchCost, Is.EqualTo(1)); Assert.That(state.TrySwitch(NixGovernor.Powersave, 2, 1, out cost), Is.True); Assert.That(cost, Is.EqualTo(1)); } [TestCase(0, 1)] [TestCase(1, 1)] [TestCase(3, 0)] [TestCase(5, 0)] public void BeginWaveResetsPreviouslyUsedState(int version, int switchCost) { var state = new NixGovernorState(); state.BeginWave(5); Assert.That(state.TrySwitch(NixGovernor.Performance, 7, 0, out _), Is.True); state.BeginWave(version); Assert.That(state.Governor, Is.EqualTo(NixGovernor.Schedutil)); Assert.That(state.LastSwitchRound, Is.EqualTo(-1)); Assert.That(state.FreeSwitchUsed, Is.False); Assert.That(state.SwitchCost, Is.EqualTo(switchCost)); Assert.That(state.DamagePercent, Is.EqualTo(version == 0 ? 100 : version == 1 ? 105 : 110)); Assert.That(state.ShieldPercent, Is.EqualTo(state.DamagePercent)); } [Test] public void EveryBlockedReasonHasPlayerFeedback() { Assert.That(NixGovernorSwitchBlockReason.None.GetMessage(), Is.Null); foreach (NixGovernorSwitchBlockReason reason in Enum.GetValues(typeof(NixGovernorSwitchBlockReason))) if (reason != NixGovernorSwitchBlockReason.None) Assert.That(reason.GetMessage(), Is.Not.Null.And.Not.Empty, reason.ToString()); } }