TrioAlertCategoryTests.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Foundation
  2. import LoopKit
  3. import Testing
  4. @testable import Trio
  5. /// Pins the severity + immediacy mapping for every `TrioAlertCategory` case.
  6. /// A re-bucketing of any case (or an added/removed case) fails these tables.
  7. @Suite("Trio Alerts: TrioAlertCategory") struct TrioAlertCategoryTests {
  8. @Test("interruptionLevel maps each category to its severity tier", arguments: [
  9. // .critical
  10. (TrioAlertCategory.batteryEmpty, Alert.InterruptionLevel.critical),
  11. (.deliveryUncertain, .critical),
  12. (.glucoseUrgentLow, .critical),
  13. (.hardwareFault, .critical),
  14. (.notLooping, .critical),
  15. (.occlusion, .critical),
  16. (.reservoirEmpty, .critical),
  17. (.sensorFailure, .critical),
  18. // .timeSensitive
  19. (.batteryLow, .timeSensitive),
  20. (.bolusFailed, .timeSensitive),
  21. (.deviceExpired, .timeSensitive),
  22. (.glucoseDataStale, .timeSensitive),
  23. (.glucoseForecastedLow, .timeSensitive),
  24. (.glucoseHigh, .timeSensitive),
  25. (.glucoseLow, .timeSensitive),
  26. (.manualTempBasalActive, .timeSensitive),
  27. (.podShutdownImminent, .timeSensitive),
  28. (.reservoirLow, .timeSensitive),
  29. (.suspendTimeExpired, .timeSensitive),
  30. // .active
  31. (.algorithmError, .active),
  32. (.commsTransient, .active),
  33. (.deviceExpirationReminder, .active),
  34. (.other("x"), .active)
  35. ]) func interruptionLevelMapping(category: TrioAlertCategory, expected: Alert.InterruptionLevel) {
  36. #expect(category.interruptionLevel == expected)
  37. }
  38. @Test("shouldFireImmediately is true for every category except commsTransient", arguments: [
  39. (TrioAlertCategory.algorithmError, true),
  40. (.batteryEmpty, true),
  41. (.batteryLow, true),
  42. (.bolusFailed, true),
  43. (.deliveryUncertain, true),
  44. (.deviceExpirationReminder, true),
  45. (.deviceExpired, true),
  46. (.glucoseDataStale, true),
  47. (.glucoseForecastedLow, true),
  48. (.glucoseHigh, true),
  49. (.glucoseLow, true),
  50. (.glucoseUrgentLow, true),
  51. (.hardwareFault, true),
  52. (.manualTempBasalActive, true),
  53. (.notLooping, true),
  54. (.occlusion, true),
  55. (.other("x"), true),
  56. (.podShutdownImminent, true),
  57. (.reservoirEmpty, true),
  58. (.reservoirLow, true),
  59. (.sensorFailure, true),
  60. (.suspendTimeExpired, true),
  61. (.commsTransient, false)
  62. ]) func shouldFireImmediatelyMapping(category: TrioAlertCategory, expected: Bool) {
  63. #expect(category.shouldFireImmediately == expected)
  64. }
  65. @Test("commsTransient is dwell-suppressed") func commsTransientDoesNotFireImmediately() {
  66. #expect(TrioAlertCategory.commsTransient.shouldFireImmediately == false)
  67. }
  68. }