BatteryConditionTests.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // LoopFollow
  2. // BatteryConditionTests.swift
  3. @testable import LoopFollow
  4. import Testing
  5. struct BatteryConditionTests {
  6. let cond = BatteryCondition()
  7. @Test("#fires when battery ≤ threshold")
  8. func firesBelowOrEqual() {
  9. let alarm = Alarm.battery(threshold: 20)
  10. let data = AlarmData.withBattery(20)
  11. #expect(cond.evaluate(alarm: alarm, data: data, now: .init()))
  12. }
  13. @Test("#does NOT fire when battery > threshold")
  14. func ignoresAbove() {
  15. let alarm = Alarm.battery(threshold: 20)
  16. let data = AlarmData.withBattery(55)
  17. #expect(!cond.evaluate(alarm: alarm, data: data, now: .init()))
  18. }
  19. @Test("#does NOT fire if no battery reading")
  20. func ignoresMissingReading() {
  21. let alarm = Alarm.battery(threshold: 20)
  22. let data = AlarmData.withBattery(nil)
  23. #expect(!cond.evaluate(alarm: alarm, data: data, now: .init()))
  24. }
  25. @Test("#does NOT fire if threshold is nil / zero")
  26. func ignoresBadConfig() {
  27. let alarm = Alarm.battery(threshold: nil)
  28. let data = AlarmData.withBattery(5)
  29. #expect(!cond.evaluate(alarm: alarm, data: data, now: .init()))
  30. }
  31. }