DynamicISFEnableTests.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import CoreData
  2. import Foundation
  3. import Swinject
  4. import Testing
  5. @testable import Trio
  6. @Suite("Dynamic ISF Enable Logic Tests", .serialized) struct DynamicISFEnableTests {
  7. var coreDataStack: CoreDataStack!
  8. var context: NSManagedObjectContext!
  9. init() async throws {
  10. // In-memory Core Data for tests
  11. coreDataStack = try await CoreDataStack.createForTests()
  12. context = coreDataStack.newTaskContext()
  13. }
  14. @Test("Confirm 80% of samples from last 7 days enables Dynamic ISF") func test80PercentSamplesEnablingLogic() async throws {
  15. let numberOfSamples = Int(288 * 7 * 0.8) // 80% of 7 days of samples
  16. let now = Date() // internal function uses Date()
  17. try await context.perform {
  18. for index in 0 ..< numberOfSamples {
  19. let timeDelta = Double(index * 5 * 60)
  20. let tdd = TDDStored(context: context)
  21. tdd.date = now - timeDelta
  22. tdd.total = 30
  23. tdd.bolus = 15
  24. tdd.tempBasal = 15
  25. tdd.scheduledBasal = 0
  26. }
  27. try context.save()
  28. }
  29. let enabled = try await BaseTDDStorage.hasSufficientTDD(context: context)
  30. #expect(enabled)
  31. }
  32. }