InfoColoringTests.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // LoopFollow
  2. // InfoColoringTests.swift
  3. @testable import LoopFollow
  4. import SwiftUI
  5. import Testing
  6. struct InfoColoringTests {
  7. @Test("disabled coloring returns nil regardless of value")
  8. func disabledReturnsNil() {
  9. let coloring = InfoColoring(enabled: false, warning: 30, urgent: 15)
  10. #expect(coloring.color(for: 5, direction: .below) == nil)
  11. }
  12. @Test("below: battery warn 30 / urgent 15, in-range is green")
  13. func belowDirection() {
  14. let coloring = InfoColoring(enabled: true, warning: 30, urgent: 15)
  15. #expect(coloring.color(for: 40, direction: .below) == .green)
  16. #expect(coloring.color(for: 30, direction: .below) == .yellow)
  17. #expect(coloring.color(for: 25, direction: .below) == .yellow)
  18. #expect(coloring.color(for: 15, direction: .below) == .red)
  19. #expect(coloring.color(for: 10, direction: .below) == .red)
  20. }
  21. @Test("above: SAGE warn 8 / urgent 9.5, in-range is green")
  22. func aboveDirection() {
  23. let coloring = InfoColoring(enabled: true, warning: 8, urgent: 9.5)
  24. #expect(coloring.color(for: 6, direction: .above) == .green)
  25. #expect(coloring.color(for: 8, direction: .above) == .yellow)
  26. #expect(coloring.color(for: 8.5, direction: .above) == .yellow)
  27. #expect(coloring.color(for: 9.5, direction: .above) == .red)
  28. #expect(coloring.color(for: 12, direction: .above) == .red)
  29. }
  30. @Test("nil thresholds are green when enabled")
  31. func nilThresholds() {
  32. let coloring = InfoColoring(enabled: true, warning: nil, urgent: nil)
  33. #expect(coloring.color(for: 999, direction: .above) == .green)
  34. }
  35. @Test("only urgent set still colors red, otherwise green")
  36. func onlyUrgent() {
  37. let coloring = InfoColoring(enabled: true, warning: nil, urgent: 15)
  38. #expect(coloring.color(for: 20, direction: .below) == .green)
  39. #expect(coloring.color(for: 15, direction: .below) == .red)
  40. }
  41. @Test("pump reservoir colors on the way down, and a capped 50+ reads green")
  42. func pumpReservoir() throws {
  43. let config = try #require(InfoType.pump.colorConfig)
  44. let coloring = InfoColoring(enabled: true, warning: config.defaultWarning, urgent: config.defaultUrgent)
  45. #expect(coloring.color(for: 50, direction: config.direction) == .green)
  46. #expect(coloring.color(for: 20, direction: config.direction) == .yellow)
  47. #expect(coloring.color(for: 10, direction: config.direction) == .red)
  48. }
  49. @Test("thresholds that need decimals get a fractional step")
  50. func fractionalSteps() {
  51. #expect(InfoType.recBolus.colorConfig?.step == 0.1)
  52. #expect(InfoType.iob.colorConfig?.step == 0.5)
  53. #expect(InfoType.sage.colorConfig?.fractionDigits == 1)
  54. #expect(InfoType.cob.colorConfig?.fractionDigits == 0)
  55. }
  56. @Test("non-numeric rows are not colorable")
  57. func notColorable() {
  58. #expect(InfoType.basal.isColorable == false)
  59. #expect(InfoType.minMax.isColorable == false)
  60. #expect(InfoType.pump.isColorable)
  61. }
  62. }