SessionScoreTests.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using NUnit.Framework;
  3. namespace DevilLink2.Gameplay.Tests
  4. {
  5. public sealed class SessionScoreTests
  6. {
  7. [TestCase(1,100)] [TestCase(2,200)] [TestCase(3,300)] [TestCase(4,400)] [TestCase(5,500)] [TestCase(6,500)] [TestCase(10,500)]
  8. public void ConsecutiveMatchesUseCappedMultiplier(int count, int expected)
  9. {
  10. var clock = new ManualClock(); var s = new SessionScore(clock); int points = 0;
  11. for (int i = 0; i < count; i++) { clock.Seconds += 1; points = s.RegisterMatch(); }
  12. Assert.That(points, Is.EqualTo(expected)); Assert.That(s.CurrentMultiplier, Is.EqualTo(Math.Min(count,5)));
  13. Assert.That(s.ComboCount, Is.EqualTo(count)); Assert.That(s.IsInCombo, Is.True);
  14. Assert.That(s.TotalScore, Is.EqualTo(count <= 5 ? count * (count + 1) * 50L : 1500L + (count - 5) * 500));
  15. }
  16. [Test] public void ExactlyFourSecondsContinuesTheCombo()
  17. {
  18. var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 4;
  19. Assert.That(s.IsInCombo, Is.True); Assert.That(s.ComboRemainingTime, Is.Zero);
  20. Assert.That(s.RegisterMatch(), Is.EqualTo(200)); Assert.That(s.ComboRemainingTime, Is.EqualTo(4));
  21. }
  22. [Test] public void MoreThanFourSecondsExpiresBeforeAnyNewMatch()
  23. {
  24. var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 4.000001; s.Update();
  25. Assert.That(s.ComboCount, Is.Zero); Assert.That(s.CurrentMultiplier, Is.Zero);
  26. Assert.That(s.IsInCombo, Is.False); Assert.That(s.ComboRemainingTime, Is.Zero);
  27. Assert.That(s.RegisterMatch(), Is.EqualTo(100)); Assert.That(s.TotalScore, Is.EqualTo(200));
  28. }
  29. [Test] public void EachMatchRestartsTheRealTimeWindow()
  30. {
  31. var c = new ManualClock(); var s = new SessionScore(c); s.RegisterMatch(); c.Seconds = 3.5; s.RegisterMatch();
  32. c.Seconds = 6; Assert.That(s.ComboRemainingTime, Is.EqualTo(1.5)); Assert.That(s.RegisterMatch(), Is.EqualTo(300));
  33. }
  34. [Test] public void NewScoreStartsEmpty()
  35. {
  36. var c = new ManualClock(); var first = new SessionScore(c); first.RegisterMatch();
  37. var second = new SessionScore(c); Assert.That(second.TotalScore, Is.Zero);
  38. Assert.That(second.ComboCount, Is.Zero); Assert.That(second.ComboRemainingTime, Is.Zero);
  39. }
  40. [TestCase(false,0,1000)] [TestCase(true,30,1300)] [TestCase(true,30.25,1310)]
  41. [TestCase(true,.01,1010)] [TestCase(true,0,1000)]
  42. public void ClearBonusUsesCeilingAndIsGrantedExactlyOnce(bool timed, double remaining, int expected)
  43. {
  44. var s = new SessionScore(new ManualClock()); int count = 0, notified = 0;
  45. s.ClearBonusAwarded += bonus => { count++; notified = bonus; };
  46. s.RegisterMatch(); Assert.That(s.CompleteClear(timed, remaining), Is.EqualTo(expected));
  47. Assert.That(s.CompleteClear(timed, remaining), Is.Zero); Assert.That(s.RegisterMatch(), Is.Zero);
  48. Assert.That(s.TotalScore, Is.EqualTo(100 + expected)); Assert.That(notified, Is.EqualTo(expected)); Assert.That(count, Is.EqualTo(1));
  49. }
  50. [Test] public void FailureCannotGrantClearBonus()
  51. {
  52. var s = new SessionScore(new ManualClock()); s.RegisterMatch(); s.EndWithoutBonus();
  53. Assert.That(s.CompleteClear(true,100), Is.Zero); Assert.That(s.TotalScore, Is.EqualTo(100)); Assert.That(s.ClearBonus, Is.Zero);
  54. }
  55. [Test] public void BackwardsClockIsRejected()
  56. {
  57. var c = new ManualClock { Seconds = 10 }; var s = new SessionScore(c); c.Seconds = 9;
  58. Assert.Throws<InvalidOperationException>(() => s.Update());
  59. }
  60. }
  61. }