using System; using NUnit.Framework; namespace DevilLink2.Gameplay.Tests { public sealed class SessionScoreTests { [TestCase(1,100)] [TestCase(2,200)] [TestCase(3,300)] [TestCase(4,400)] [TestCase(5,500)] [TestCase(6,500)] [TestCase(10,500)] public void ConsecutiveMatchesUseCappedMultiplier(int count, int expected) { var clock = new ManualClock(); var s = new SessionScore(clock); int points = 0; for (int i = 0; i < count; i++) { clock.Seconds += 1; points = s.RegisterMatch(); } Assert.That(points, Is.EqualTo(expected)); Assert.That(s.CurrentMultiplier, Is.EqualTo(Math.Min(count,5))); Assert.That(s.ComboCount, Is.EqualTo(count)); Assert.That(s.IsInCombo, Is.True); Assert.That(s.TotalScore, Is.EqualTo(count <= 5 ? count * (count + 1) * 50L : 1500L + (count - 5) * 500)); } [Test] public void ExactlyFourSecondsContinuesTheCombo() { var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 4; Assert.That(s.IsInCombo, Is.True); Assert.That(s.ComboRemainingTime, Is.Zero); Assert.That(s.RegisterMatch(), Is.EqualTo(200)); Assert.That(s.ComboRemainingTime, Is.EqualTo(4)); } [Test] public void MoreThanFourSecondsExpiresBeforeAnyNewMatch() { var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 4.000001; s.Update(); Assert.That(s.ComboCount, Is.Zero); Assert.That(s.CurrentMultiplier, Is.Zero); Assert.That(s.IsInCombo, Is.False); Assert.That(s.ComboRemainingTime, Is.Zero); Assert.That(s.RegisterMatch(), Is.EqualTo(100)); Assert.That(s.TotalScore, Is.EqualTo(200)); } [Test] public void EachMatchRestartsTheRealTimeWindow() { var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 3.5; s.RegisterMatch(); c.Seconds = 6; Assert.That(s.ComboRemainingTime, Is.EqualTo(1.5)); Assert.That(s.RegisterMatch(), Is.EqualTo(300)); } [Test] public void NewScoreStartsEmpty() { var c = new ManualClock(); var first = new SessionScore(c); first.RegisterMatch(); var second = new SessionScore(c); Assert.That(second.TotalScore, Is.Zero); Assert.That(second.ComboCount, Is.Zero); Assert.That(second.ComboRemainingTime, Is.Zero); } [TestCase(false,0,1000)] [TestCase(true,30,1300)] [TestCase(true,30.25,1310)] [TestCase(true,.01,1010)] [TestCase(true,0,1000)] public void ClearBonusUsesCeilingAndIsGrantedExactlyOnce(bool timed, double remaining, int expected) { var s = new SessionScore(new ManualClock()); int count = 0, notified = 0; s.ClearBonusAwarded += bonus => { count++; notified = bonus; }; s.RegisterMatch(); Assert.That(s.CompleteClear(timed, remaining), Is.EqualTo(expected)); Assert.That(s.CompleteClear(timed, remaining), Is.Zero); Assert.That(s.RegisterMatch(), Is.Zero); Assert.That(s.TotalScore, Is.EqualTo(100 + expected)); Assert.That(notified, Is.EqualTo(expected)); Assert.That(count, Is.EqualTo(1)); } [Test] public void FailureCannotGrantClearBonus() { var s = new SessionScore(new ManualClock()); s.RegisterMatch(); s.EndWithoutBonus(); Assert.That(s.CompleteClear(true,100), Is.Zero); Assert.That(s.TotalScore, Is.EqualTo(100)); Assert.That(s.ClearBonus, Is.Zero); } [Test] public void BackwardsClockIsRejected() { var c = new ManualClock { Seconds = 10 }; var s = new SessionScore(c); c.Seconds = 9; Assert.Throws(() => s.Update()); } } }